-
Notifications
You must be signed in to change notification settings - Fork 1
/
GetAccountByUserId.unit.ts
48 lines (38 loc) · 1.42 KB
/
GetAccountByUserId.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
import { GetAccountByUserId } from './GetAccountByUserId';
import { Request, Response } from './GetAccountByUserIdDTOs';
import { AccountRepoFake, UserId } from '../../repos/AccountRepoFake';
import { getAppSyncEvent as getEvent } from '../../../../shared/utils/test';
import { Envelope } from '../../../../shared/core/Envelope';
import { BaseError } from '../../../../shared/core/AppError';
let accountRepo, getAccountByUserId: GetAccountByUserId;
beforeAll(() => {
accountRepo = new AccountRepoFake();
getAccountByUserId = new GetAccountByUserId(accountRepo);
});
it('gets an account', async () => {
const validData: Request = {
userId: UserId.GOOD,
};
const response = (await getAccountByUserId.execute(
getEvent(validData)
)) as Envelope<Response>;
expect(response.result?.balance).toBe(100); // faked balance is 100
});
it(`fails when userId isn't an uuid`, async () => {
const badData = {
userId: 'not a uuid',
};
const result = (await getAccountByUserId.execute(
getEvent(badData)
)) as Envelope<BaseError>;
expect(result.errorType).toBe('GetAccountByUserIdErrors.UserIdNotUuid');
});
it(`fails when account isn't found`, async () => {
const validData: Request = {
userId: UserId.NO_TRANSACTIONS,
};
const response = (await getAccountByUserId.execute(
getEvent(validData)
)) as Envelope<BaseError>;
expect(response.errorType).toBe('GetAccountByUserIdErrors.AccountNotFound');
});