-
Notifications
You must be signed in to change notification settings - Fork 1
/
CreateUser.unit.ts
77 lines (64 loc) · 1.91 KB
/
CreateUser.unit.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
process.env.distributeDomainEvents = 'dummy';
import { CreateUser } from './CreateUser';
import { UserRepoFake } from '../../repos/UserRepoFake';
import { LambdaInvokerFake } from '../../../../shared/infra/invocation/LambdaInvokerFake';
import {
dateFormat,
getAppSyncEvent as getEvent,
} from '../../../../shared/utils/test';
let userRepo, createUser: CreateUser;
beforeAll(() => {
userRepo = new UserRepoFake();
createUser = new CreateUser(userRepo, new LambdaInvokerFake());
});
test('User creation with alias', async () => {
const validData = {
username: 'test_username',
email: 'test@email.com',
password: 'passwordd',
alias: 'test_alias',
};
const result = await createUser.execute(getEvent(validData));
expect(result).toMatchObject({
time: expect.stringMatching(dateFormat),
});
expect(result).not.toMatchObject({
error: expect.anything(),
});
});
test('User creation without alias', async () => {
const validData = {
username: 'test_username',
email: 'test@email.com',
password: 'passwordd',
};
const result = await createUser.execute(getEvent(validData));
expect(result).toMatchObject({
time: expect.stringMatching(dateFormat),
});
expect(result).not.toMatchObject({
error: expect.anything(),
});
});
test('User creation fails for taken email', async () => {
const data = {
username: 'test_username',
email: 'already@taken.com',
password: 'passwordd',
};
const result = await createUser.execute(getEvent(data));
expect(result).toMatchObject({
errorType: 'CreateUserErrors.EmailAlreadyTaken',
});
});
test('User creation fails for taken username', async () => {
const data = {
username: 'taken_username',
email: 'test@email.com',
password: 'passwordd',
};
const result = await createUser.execute(getEvent(data));
expect(result).toMatchObject({
errorType: 'CreateUserErrors.UsernameAlreadyTaken',
});
});