-
Notifications
You must be signed in to change notification settings - Fork 0
/
agent.test.ts
106 lines (79 loc) · 3.64 KB
/
agent.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import SCIMMY from 'scimmy';
describe('Agent tests', () => {
// Declaring a schema definition under a different name
function ingress(_resource: any, data: any) {
const clonedData = { ...data, id: '2000' };
console.log('data' + JSON.stringify(clonedData));
return clonedData;
}
beforeAll(() => {
// https://scimmyjs.github.io/SCIMMY.Types.SchemaDefinition.html
const definition = new SCIMMY.Types.SchemaDefinition('Agent', 'urn:ietf:params:scim:schemas:domain:Agent', 'Agent', [
//https://scimmyjs.github.io/SCIMMY.Types.Attribute.html
new SCIMMY.Types.Attribute('string', 'admin', { required: true, description: 'admin field' }),
new SCIMMY.Types.Attribute('complex', 'agencies', { required: true, description: 'agencies array field', multiValued: true, direction: 'both' }, [
new SCIMMY.Types.Attribute('string', 'name', { required: true, description: 'admin field' }),
]),
]);
class AgentSchema extends SCIMMY.Types.Schema {
static get definition() {
return definition;
}
}
SCIMMY.Resources.declare(SCIMMY.Resources.User.extend(AgentSchema, true))
.ingress(ingress);
const u = SCIMMY.Resources.declared();
console.log('us' + JSON.stringify(u));
});
// test('testing the attribute', () => {
// const sch = SCIMMY.Schemas.declared('Agent');
// console.log(JSON.stringify(sch));
// const attr = sch.attribute('agencies');
// console.log(JSON.stringify(attr));
// const value = attr.coerce(['value_test']);
// console.log('v' + value)
// })
test('should validate true when Agent has extended attributes', async () => {
await (new SCIMMY.Resources.User())
.write({
'userName': 'someGuy',
'externalId': '5667',
'emails': [
{
value: 'dschrute@example.com',
type: 'work',
primary: true,
},
],
'schemas': ['urn:ietf:params:scim:schemas:domain:Agent', 'urn:ietf:params:scim:schemas:core:2.0:User'],
'urn:ietf:params:scim:schemas:domain:Agent': {
admin: 'test-admin',
agencies: []
},
},
);
});
test('should validate false when Agent has different extended attributes', async () => {
await expect(async () => {
await (new SCIMMY.Resources.User()).write({
'userName': 'someGuy',
'externalId': '5667',
'schemas': ['urn:ietf:params:scim:schemas:domain:Agent', 'urn:ietf:params:scim:schemas:core:2.0:User'],
'urn:ietf:params:scim:schemas:domain:Agent': {
fakeAttribute: 'testagency',
},
},
);
}).rejects.toThrow('Required attribute \'admin\' is missing in schema extension \'urn:ietf:params:scim:schemas:domain:Agent\'');
});
test('should validate false when Agent has no extended attributes', async () => {
await expect(async () => {
await (new SCIMMY.Resources.User()).write({
userName: 'someGuy',
externalId: '5667',
schemas: ['urn:ietf:params:scim:schemas:domain:Agent', 'urn:ietf:params:scim:schemas:core:2.0:User'],
},
);
}).rejects.toThrow('Missing values for required schema extension \'urn:ietf:params:scim:schemas:domain:Agent\'');
});
});