-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.test.ts
79 lines (62 loc) · 2.25 KB
/
user.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
import { SDK } from '../../../src';
import { ServerError } from '../../../src/errors';
import { UserCreateReq, UserStatus } from '../../../src/generated';
import Utils from '../../utils';
describe('User Validation Tests', () => {
let sdk: SDK;
beforeEach(() => {
sdk = Utils.SDK();
});
test('should handle null full name', async () => {
expect.assertions(2);
try {
const req = { name: Utils.testConstants.TEST_EMPTY_STRING, status: UserStatus.Active };
await sdk.users().create(req);
} catch (error) {
expect(error).toBeInstanceOf(ServerError);
expect((error as ServerError).httpStatusCode).toEqual(500);
}
});
test('should handle successful create', async () => {
expect.assertions(1);
const req: UserCreateReq = { fullName: Utils.createRandomTestName(), status: UserStatus.Active };
const sendResponse = await sdk.users().create(req);
expect(sendResponse.fullName).toEqual(req.fullName);
});
test('should handle not found delete', async () => {
expect.assertions(3);
try {
await sdk.users().delete(Utils.testConstants.TEST_USER_ID);
} catch (error) {
expect(error).toBeInstanceOf(ServerError);
expect((error as ServerError).httpStatusCode).toEqual(400);
expect((error as ServerError).getValidationMessages()).toEqual(['userID: does not exist']);
}
});
test('should handle successful delete', async () => {
expect.assertions(2);
const userId = (await Utils.createUser()).userID;
await sdk.users().delete(userId);
try {
await sdk.users().get(userId);
} catch (error) {
expect(error).toBeInstanceOf(ServerError);
expect((error as ServerError).httpStatusCode).toEqual(400);
}
});
test('should handle not found get', async () => {
expect.assertions(2);
try {
await sdk.users().get(Utils.testConstants.TEST_USER_ID);
} catch (error) {
expect(error).toBeInstanceOf(ServerError);
expect((error as ServerError).httpStatusCode).toEqual(400);
}
});
test('should handle successful get', async () => {
expect.assertions(1);
const userId = (await Utils.createUser()).userID;
const getResponse = await sdk.users().get(userId);
expect(getResponse.userID).toEqual(userId);
});
});