Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADMINAPI-1039] Fixes to the Sorting #144

Merged
merged 36 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
e3cbe5e
Add the sorting in the queries before paging
jagudelo-gap Aug 16, 2024
4cc0160
Remove the unused SortableList class
jagudelo-gap Aug 16, 2024
b9d8d3b
Add a couple of integration tests to the GetAllApplicationsQuery
jagudelo-gap Aug 17, 2024
17e5868
Fix the property name in the orderby applications
jagudelo-gap Aug 20, 2024
74c4cb6
Fix the orderby in vendors to include contactname, contactemail and n…
jagudelo-gap Aug 20, 2024
4bf358a
Add new constants in order to use it in the sorting implementation
jagudelo-gap Aug 20, 2024
dbe9862
Fix the orderby namespaceprefixes in vendors
jagudelo-gap Aug 20, 2024
91a9d40
Merge remote-tracking branch 'origin/main' into ADMINAPI-1039
jagudelo-gap Aug 20, 2024
c1b3dee
Replace from odsInstanceId to id in odsintances e2e
jagudelo-gap Aug 21, 2024
bd4fd0b
Add again the e2e file
jagudelo-gap Aug 21, 2024
a77f353
Fix syntax in js for odsintance e2e
jagudelo-gap Aug 21, 2024
a8a6913
Add console.log to trace js errors
jagudelo-gap Aug 21, 2024
c9cc98b
Fix ODS Instance e2e
jagudelo-gap Aug 22, 2024
5c27fbd
Add the collate to the orderby in odsinstance
jagudelo-gap Aug 23, 2024
3163d91
Add a different mechanism to sort data in js
jagudelo-gap Aug 23, 2024
37c6f5d
Add the new mechanism to sort data in js but for a different column
jagudelo-gap Aug 23, 2024
94078ab
Fix typo
jagudelo-gap Aug 23, 2024
f50a275
Revert changes on odsintance e2e
jagudelo-gap Aug 23, 2024
aa7cfc4
Add the collate function to the EF core in order to match with the js…
jagudelo-gap Aug 23, 2024
431f38f
Add a different mechansim in the e2e to validate sorting odsinstances
jagudelo-gap Aug 24, 2024
ff26363
Add a different mechansim in the e2e to validate sorting odsinstances
jagudelo-gap Aug 24, 2024
87c1567
Add a different mechansim in the e2e to validate sorting odsinstances
jagudelo-gap Aug 24, 2024
cceae37
Add the command to force collate in SQL server engine
jagudelo-gap Aug 24, 2024
f5bd27d
Add the js sort function to the env. Modify the application's e2e to …
jagudelo-gap Aug 24, 2024
8e5ce73
Fix the vendor's e2e
jagudelo-gap Aug 26, 2024
8cf4ffa
Add jshelper as a variable. Modify profile's e2e
jagudelo-gap Aug 26, 2024
4918287
Fix the ifs statements in connectionstringhelper
jagudelo-gap Aug 26, 2024
c042cea
Fix the Claimsets e2e
jagudelo-gap Aug 26, 2024
7411e0a
Fix applications e2e
jagudelo-gap Aug 26, 2024
e27c250
Fix the profile's e2e
jagudelo-gap Aug 26, 2024
acb2652
Set a different collation to sql server order Latin1_General_100_BIN2…
jagudelo-gap Aug 26, 2024
48648b5
Fix the vendor's e2e sqlserver
jagudelo-gap Aug 26, 2024
0f967d4
Add the collation function to the column sorting
jagudelo-gap Aug 26, 2024
209c8b6
Fix to delete data after e2e passed
jagudelo-gap Aug 26, 2024
f26dcce
Fix a typo
jagudelo-gap Aug 26, 2024
b09543f
Revert to use loadash in the e2e
jagudelo-gap Aug 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// SPDX-License-Identifier: Apache-2.0
// Licensed to the Ed-Fi Alliance under one or more agreements.
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0.
// See the LICENSE and NOTICES files in the project root for more information.

using System;
using System.Threading.Tasks;
using EdFi.Admin.DataAccess.Models;
using EdFi.Ods.AdminApi.Helpers;
using EdFi.Ods.AdminApi.Infrastructure;
using EdFi.Ods.AdminApi.Infrastructure.Database.Queries;
using Microsoft.Extensions.Options;
using NUnit.Framework;
using Shouldly;
using VendorUser = EdFi.Admin.DataAccess.Models.User;


namespace EdFi.Ods.AdminApi.DBTests.Database.QueryTests;

[TestFixture]
public class GetAllApplicationsQueryTests : PlatformUsersContextTestBase
{
private IOptions<AppSettings> _options { get; set; }

[OneTimeSetUp]
public virtual async Task FixtureSetup()
{
_options = Testing.GetAppSettings();
_options.Value.PreventDuplicateApplications = false;
LoadApplications(3);
await Task.Yield();
}

[Test]
public void ShouldGetAllApplications()
{
Transaction(usersContext =>
{
var query = new GetAllApplicationsQuery(usersContext, _options);
var result = query.Execute(
new CommonQueryParams(null, null, null, null), null, null, null);

result.Count.ShouldBeGreaterThan(0);
});
}

[Test]
public void ShouldGetAllApplications_With_Offset_and_Limit()
{
var offset = 1;
var limit = 2;
Transaction(usersContext =>
{
var query = new GetAllApplicationsQuery(usersContext, _options);
var result = query.Execute(
new CommonQueryParams(offset, limit, null, null), null, null, null);

result.Count.ShouldBeGreaterThan(0);
result.Count.ShouldBe(2);
});
}

private void LoadApplications(int count = 1)
{
for (int i = 0; i < count; i++)
{
var vendor = new Vendor { VendorName = $"test vendor {Guid.NewGuid().ToString()}" };
var odsInstance = new OdsInstance
{
Name = $"Test Instance {Guid.NewGuid().ToString()}",
InstanceType = "Ods",
ConnectionString = "Data Source=(local);Initial Catalog=EdFi_Ods;Integrated Security=True;Encrypt=False"
};

var application = new Application
{
ApplicationName = $"test application {Guid.NewGuid().ToString()}",
ClaimSetName = "test claim set",
Vendor = vendor,
OperationalContextUri = OperationalContext.DefaultOperationalContextUri,
};
var user = new VendorUser
{
Email = "",
FullName = application.ApplicationName,
Vendor = vendor
};

var apiClient = new ApiClient
{
Application = application,
Key = "key",
Secret = "secret",
Name = application.ApplicationName,
IsApproved = true,
UseSandbox = false,
KeyStatus = "Active",
User = user,
};

var apiClientOdsIntance = new ApiClientOdsInstance
{
ApiClient = apiClient,
OdsInstance = odsInstance,
};

Save(odsInstance, vendor, application, apiClient, apiClientOdsIntance);
}
}
}
121 changes: 0 additions & 121 deletions Application/EdFi.Ods.AdminApi.UnitTests/Features/SortableListTests.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@
"value": "Tenant2",
"type": "default",
"enabled": true
},
{
"key": "sortByProperty",
"value": "function sortByProperty(objArray, prop, direction){ if (arguments.length<2) throw new Error(\"ARRAY, AND OBJECT PROPERTY MINIMUM ARGUMENTS, OPTIONAL DIRECTION\"); if (!Array.isArray(objArray)) throw new Error(\"FIRST ARGUMENT NOT AN ARRAY\"); const clone = objArray.slice(0); const direct = arguments.length>2 ? arguments[2] : 1; const propPath = (prop.constructor===Array) ? prop : prop.split(\".\"); clone.sort(function(a,b){ for (let p in propPath){ if (a[propPath[p]] && b[propPath[p]]){ a = a[propPath[p]]; b = b[propPath[p]]; } } a = a.match(/^\\d+$/) ? +a : a; b = b.match(/^\\d+$/) ? +b : b; return ( (a < b) ? -1*direct : ((a > b) ? 1*direct : 0) ); }); return clone; }",
"type": "default",
"enabled": true
},
{
"key": "jsHelper",
"value": "(function () { const rndChar = function (str) { return str.charAt(Math.floor(Math.random() * str.length)); }; const shfChar = function (str) { const array = str.split(''); for (let i = array.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); [array[i], array[j]] = [array[j], array[i]]; } return array.join(''); }; return { generateClientSecret: function(){ const minLength = 32; const maxLength = 128; let result = ''; const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; const specialCharacters = '!@#$%^&*()_+{}:\"<>?|[];\\',./`~'; const length = Math.floor(Math.random() * (maxLength - minLength + 1)) + minLength; result += rndChar('abcdefghijklmnopqrstuvwxyz'); result += rndChar('ABCDEFGHIJKLMNOPQRSTUVWXYZ'); result += rndChar('0123456789'); result += rndChar(specialCharacters); for (let i = result.length; i < length; i++) { const charactersPlusSpecial = characters + specialCharacters; result += charactersPlusSpecial.charAt(Math.floor(Math.random() * charactersPlusSpecial.length)); } return shfChar(result); }, randomChar : rndChar, shuffleString: shfChar } })",
"type": "default",
"enabled": true
}
],
"_postman_variable_scope": "environment",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@
"value": "Tenant2",
"type": "default",
"enabled": true
},
{
"key": "sortByProperty",
"value": "function sortByProperty(objArray, prop, direction){ if (arguments.length<2) throw new Error(\"ARRAY, AND OBJECT PROPERTY MINIMUM ARGUMENTS, OPTIONAL DIRECTION\"); if (!Array.isArray(objArray)) throw new Error(\"FIRST ARGUMENT NOT AN ARRAY\"); const clone = objArray.slice(0); const direct = arguments.length>2 ? arguments[2] : 1; const propPath = (prop.constructor===Array) ? prop : prop.split(\".\"); clone.sort(function(a,b){ for (let p in propPath){ if (a[propPath[p]] && b[propPath[p]]){ a = a[propPath[p]]; b = b[propPath[p]]; } } a = a.match(/^\\d+$/) ? +a : a; b = b.match(/^\\d+$/) ? +b : b; return ( (a < b) ? -1*direct : ((a > b) ? 1*direct : 0) ); }); return clone; }",
"type": "default",
"enabled": true
},
{
"key": "jsHelper",
"value": "(function () { const rndChar = function (str) { return str.charAt(Math.floor(Math.random() * str.length)); }; const shfChar = function (str) { const array = str.split(''); for (let i = array.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); [array[i], array[j]] = [array[j], array[i]]; } return array.join(''); }; return { generateClientSecret: function(){ const minLength = 32; const maxLength = 128; let result = ''; const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; const specialCharacters = '!@#$%^&*()_+{}:\"<>?|[];\\',./`~'; const length = Math.floor(Math.random() * (maxLength - minLength + 1)) + minLength; result += rndChar('abcdefghijklmnopqrstuvwxyz'); result += rndChar('ABCDEFGHIJKLMNOPQRSTUVWXYZ'); result += rndChar('0123456789'); result += rndChar(specialCharacters); for (let i = result.length; i < length; i++) { const charactersPlusSpecial = characters + specialCharacters; result += charactersPlusSpecial.charAt(Math.floor(Math.random() * charactersPlusSpecial.length)); } return shfChar(result); }, randomChar : rndChar, shuffleString: shfChar } })",
"type": "default",
"enabled": true
}
],
"_postman_variable_scope": "environment",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@
"value": "false",
"type": "default",
"enabled": true
},
{
"key": "sortByProperty",
"value": "function sortByProperty(objArray, prop, direction){ if (arguments.length<2) throw new Error(\"ARRAY, AND OBJECT PROPERTY MINIMUM ARGUMENTS, OPTIONAL DIRECTION\"); if (!Array.isArray(objArray)) throw new Error(\"FIRST ARGUMENT NOT AN ARRAY\"); const clone = objArray.slice(0); const direct = arguments.length>2 ? arguments[2] : 1; const propPath = (prop.constructor===Array) ? prop : prop.split(\".\"); clone.sort(function(a,b){ for (let p in propPath){ if (a[propPath[p]] && b[propPath[p]]){ a = a[propPath[p]]; b = b[propPath[p]]; } } a = a.match(/^\\d+$/) ? +a : a; b = b.match(/^\\d+$/) ? +b : b; return ( (a < b) ? -1*direct : ((a > b) ? 1*direct : 0) ); }); return clone; }",
"type": "default",
"enabled": true
},
{
"key": "jsHelper",
"value": "(function () { const rndChar = function (str) { return str.charAt(Math.floor(Math.random() * str.length)); }; const shfChar = function (str) { const array = str.split(''); for (let i = array.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); [array[i], array[j]] = [array[j], array[i]]; } return array.join(''); }; return { generateClientSecret: function(){ const minLength = 32; const maxLength = 128; let result = ''; const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; const specialCharacters = '!@#$%^&*()_+{}:\"<>?|[];\\',./`~'; const length = Math.floor(Math.random() * (maxLength - minLength + 1)) + minLength; result += rndChar('abcdefghijklmnopqrstuvwxyz'); result += rndChar('ABCDEFGHIJKLMNOPQRSTUVWXYZ'); result += rndChar('0123456789'); result += rndChar(specialCharacters); for (let i = result.length; i < length; i++) { const charactersPlusSpecial = characters + specialCharacters; result += charactersPlusSpecial.charAt(Math.floor(Math.random() * charactersPlusSpecial.length)); } return shfChar(result); }, randomChar : rndChar, shuffleString: shfChar } })",
"type": "default",
"enabled": true
}
],
"_postman_variable_scope": "environment",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@
"value": "false",
"type": "default",
"enabled": true
},
{
"key": "sortByProperty",
"value": "function sortByProperty(objArray, prop, direction){ if (arguments.length<2) throw new Error(\"ARRAY, AND OBJECT PROPERTY MINIMUM ARGUMENTS, OPTIONAL DIRECTION\"); if (!Array.isArray(objArray)) throw new Error(\"FIRST ARGUMENT NOT AN ARRAY\"); const clone = objArray.slice(0); const direct = arguments.length>2 ? arguments[2] : 1; const propPath = (prop.constructor===Array) ? prop : prop.split(\".\"); clone.sort(function(a,b){ for (let p in propPath){ if (a[propPath[p]] && b[propPath[p]]){ a = a[propPath[p]]; b = b[propPath[p]]; } } a = a.match(/^\\d+$/) ? +a : a; b = b.match(/^\\d+$/) ? +b : b; return ( (a < b) ? -1*direct : ((a > b) ? 1*direct : 0) ); }); return clone; }",
"type": "default",
"enabled": true
},
{
"key": "jsHelper",
"value": "(function () { const rndChar = function (str) { return str.charAt(Math.floor(Math.random() * str.length)); }; const shfChar = function (str) { const array = str.split(''); for (let i = array.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); [array[i], array[j]] = [array[j], array[i]]; } return array.join(''); }; return { generateClientSecret: function(){ const minLength = 32; const maxLength = 128; let result = ''; const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; const specialCharacters = '!@#$%^&*()_+{}:\"<>?|[];\\',./`~'; const length = Math.floor(Math.random() * (maxLength - minLength + 1)) + minLength; result += rndChar('abcdefghijklmnopqrstuvwxyz'); result += rndChar('ABCDEFGHIJKLMNOPQRSTUVWXYZ'); result += rndChar('0123456789'); result += rndChar(specialCharacters); for (let i = result.length; i < length; i++) { const charactersPlusSpecial = characters + specialCharacters; result += charactersPlusSpecial.charAt(Math.floor(Math.random() * charactersPlusSpecial.length)); } return shfChar(result); }, randomChar : rndChar, shuffleString: shfChar } })",
"type": "default",
"enabled": true
}
],
"_postman_variable_scope": "environment",
Expand Down
Loading
Loading