Skip to content

Commit 3d688a8

Browse files
authored
make testing optional features (sorting and pagination) configurable (#4)
For backward compatibility the tests will be performed if the config option is omitted for the respective feature
1 parent 966d7ef commit 3d688a8

File tree

3 files changed

+50
-40
lines changed

3 files changed

+50
-40
lines changed

site/.vitepress/theme/components/config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
detectSchema: true
22
detectResourceTypes: true
3+
verifyPagination: true
4+
verifySorting: true
35

46
users:
57
enabled: true

src/groups.js

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -104,27 +104,31 @@ function runTests(groupSchema, groupSchemaExtensions = [], configuration) {
104104
assert.strictEqual(response.data.schemas[0], 'urn:ietf:params:scim:api:messages:2.0:Error', 'Error response should contain the correct error schema');
105105
});
106106

107-
test('Paginates groups using startIndex', async (t) => {
108-
const testAxios = getAxiosInstance(configuration, t);
109-
const startIndex = 20;
110-
const count = 5;
111-
const response = await testAxios.get(`/Groups?startIndex=${startIndex}&count=${count}`);
112-
assert.strictEqual(response.status, 200, 'Pagination request should return 200 OK');
113-
assert.strictEqual(response.data.schemas[0], 'urn:ietf:params:scim:api:messages:2.0:ListResponse', 'Response should use the correct SCIM list response schema');
114-
assert.ok(response.data.Resources.length <= count, 'Number of resources should be less than or equal to count');
115-
assert.strictEqual(response.data.startIndex, startIndex, 'startIndex should match the requested startIndex');
116-
});
107+
if (configuration?.verifyPagination !== false) {
108+
test('Paginates groups using startIndex', async (t) => {
109+
const testAxios = getAxiosInstance(configuration, t);
110+
const startIndex = 20;
111+
const count = 5;
112+
const response = await testAxios.get(`/Groups?startIndex=${startIndex}&count=${count}`);
113+
assert.strictEqual(response.status, 200, 'Pagination request should return 200 OK');
114+
assert.strictEqual(response.data.schemas[0], 'urn:ietf:params:scim:api:messages:2.0:ListResponse', 'Response should use the correct SCIM list response schema');
115+
assert.ok(response.data.Resources.length <= count, 'Number of resources should be less than or equal to count');
116+
assert.strictEqual(response.data.startIndex, startIndex, 'startIndex should match the requested startIndex');
117+
});
118+
}
117119

118-
test('Sorts groups by displayName', async (t) => {
119-
const testAxios = getAxiosInstance(configuration, t);
120-
const response = await testAxios.get('/Groups?sortBy=displayName');
121-
assert.strictEqual(response.status, 200, 'Sort request should return 200 OK');
122-
assert.strictEqual(response.data.schemas[0], 'urn:ietf:params:scim:api:messages:2.0:ListResponse', 'Response should use the correct SCIM list response schema');
123-
const groups = response.data.Resources;
124-
for (let i = 1; i < groups.length; i++) {
125-
assert.ok(groups[i - 1].displayName <= groups[i].displayName, 'Groups should be sorted by displayName');
126-
}
127-
});
120+
if (configuration?.verifySorting !== false) {
121+
test('Sorts groups by displayName', async (t) => {
122+
const testAxios = getAxiosInstance(configuration, t);
123+
const response = await testAxios.get('/Groups?sortBy=displayName');
124+
assert.strictEqual(response.status, 200, 'Sort request should return 200 OK');
125+
assert.strictEqual(response.data.schemas[0], 'urn:ietf:params:scim:api:messages:2.0:ListResponse', 'Response should use the correct SCIM list response schema');
126+
const groups = response.data.Resources;
127+
for (let i = 1; i < groups.length; i++) {
128+
assert.ok(groups[i - 1].displayName <= groups[i].displayName, 'Groups should be sorted by displayName');
129+
}
130+
});
131+
}
128132

129133
if (configuration?.groups?.operations?.includes('POST')) {
130134
for (const [index, creation] of (configuration.groups.post_tests || []).entries()) {

src/users.js

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -99,27 +99,31 @@ function runTests(userSchema, userSchemaExtensions = [], configuration) {
9999

100100
});
101101

102-
test('Paginates users using startIndex', async (t) => {
103-
const testAxios = getAxiosInstance(configuration, t);
104-
const startIndex = 20;
105-
const count = 5;
106-
const response = await testAxios.get(`/Users?startIndex=${startIndex}&count=${count}`);
107-
assert.strictEqual(response.status, 200, 'Pagination request should return 200 OK');
108-
assert.strictEqual(response.data.schemas[0], 'urn:ietf:params:scim:api:messages:2.0:ListResponse', 'Response should use the correct SCIM list response schema');
109-
assert.ok(response.data.Resources.length <= count, 'Number of resources should be less than or equal to count');
110-
assert.strictEqual(response.data.startIndex, startIndex, 'startIndex should match the requested startIndex');
111-
});
102+
if (configuration?.verifyPagination !== false) {
103+
test('Paginates users using startIndex', async (t) => {
104+
const testAxios = getAxiosInstance(configuration, t);
105+
const startIndex = 20;
106+
const count = 5;
107+
const response = await testAxios.get(`/Users?startIndex=${startIndex}&count=${count}`);
108+
assert.strictEqual(response.status, 200, 'Pagination request should return 200 OK');
109+
assert.strictEqual(response.data.schemas[0], 'urn:ietf:params:scim:api:messages:2.0:ListResponse', 'Response should use the correct SCIM list response schema');
110+
assert.ok(response.data.Resources.length <= count, 'Number of resources should be less than or equal to count');
111+
assert.strictEqual(response.data.startIndex, startIndex, 'startIndex should match the requested startIndex');
112+
});
113+
}
112114

113-
test('Sorts users by userName', async (t) => {
114-
const testAxios = getAxiosInstance(configuration, t);
115-
const response = await testAxios.get('/Users?sortBy=userName');
116-
assert.strictEqual(response.status, 200, 'Sort request should return 200 OK');
117-
assert.strictEqual(response.data.schemas[0], 'urn:ietf:params:scim:api:messages:2.0:ListResponse', 'Response should use the correct SCIM list response schema');
118-
const users = response.data.Resources;
119-
for (let i = 1; i < users.length; i++) {
120-
assert.ok(users[i - 1].userName <= users[i].userName, 'Users should be sorted by userName');
121-
}
122-
});
115+
if (configuration?.verifySorting !== false) {
116+
test('Sorts users by userName', async (t) => {
117+
const testAxios = getAxiosInstance(configuration, t);
118+
const response = await testAxios.get('/Users?sortBy=userName');
119+
assert.strictEqual(response.status, 200, 'Sort request should return 200 OK');
120+
assert.strictEqual(response.data.schemas[0], 'urn:ietf:params:scim:api:messages:2.0:ListResponse', 'Response should use the correct SCIM list response schema');
121+
const users = response.data.Resources;
122+
for (let i = 1; i < users.length; i++) {
123+
assert.ok(users[i - 1].userName <= users[i].userName, 'Users should be sorted by userName');
124+
}
125+
});
126+
}
123127

124128
test('Retrieves only userName attributes', async (t) => {
125129
const testAxios = getAxiosInstance(configuration, t);

0 commit comments

Comments
 (0)