-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathuser-get.ts
More file actions
72 lines (61 loc) · 2.06 KB
/
Copy pathuser-get.ts
File metadata and controls
72 lines (61 loc) · 2.06 KB
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
import { expect } from 'chai';
import utils = require('../utils');
import { Client, DefaultRequestExecutor } from '@okta/okta-sdk-nodejs';
let orgUrl = process.env.OKTA_CLIENT_ORGURL;
if (process.env.OKTA_USE_MOCK) {
orgUrl = `${orgUrl}/user-get`;
}
const client = new Client({
scopes: ['okta.users.manage'],
orgUrl: orgUrl,
token: process.env.OKTA_CLIENT_TOKEN,
clientId: process.env.OKTA_CLIENT_ID,
clientSecret: process.env.OKTA_CLIENT_SECRET,
requestExecutor: new DefaultRequestExecutor()
});
describe('User API Tests', () => {
it('should get user by ID & Login', async () => {
// Okta user should have custom attribute `age` (type `number`) added in admin dashboard
// https://help.okta.com/en-us/Content/Topics/users-groups-profiles/usgp-add-custom-user-attributes.htm
// 1. Create a user
const newUser = {
profile: {
...utils.getMockProfile('user-get'),
age: 33
},
credentials: {
password: { value: 'Abcd1234#@' }
}
};
// Cleanup the user if user exists
await utils.cleanup(client, newUser);
const queryParameters = { activate : false };
const createdUser = await client.userApi.createUser({body: newUser, ...queryParameters});
utils.validateUser(createdUser, newUser);
// 2. Get the user by user ID
const userByID = await client.userApi.getUser({
userId: createdUser.id
});
utils.validateUser(userByID, createdUser);
// 3. Get the user by user login
const userByLogin = await client.userApi.getUser({
userId: createdUser.profile.login
});
utils.validateUser(userByLogin, createdUser);
expect(userByLogin.profile.age).to.equal(newUser.profile.age);
// 4. Delete the user
await utils.deleteUser(createdUser, client);
// 5. Verify user was deleted
let err;
try {
await client.userApi.getUser({
userId: createdUser.profile.login
});
} catch (e) {
err = e;
} finally {
expect(err, 'User was not deleted').to.exist;
expect(err.message).to.contain('Okta HTTP 404');
}
});
});