Skip to content

Commit 7c7af4a

Browse files
CCM-10429: Initial unit tests
1 parent 80f8982 commit 7c7af4a

17 files changed

+807
-548
lines changed

data-migration/user-transfer/jest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const config: Config = {
3333

3434
collectCoverageFrom: ['src/**/*.ts*'],
3535

36-
coveragePathIgnorePatterns: ['handler.ts', 'constants.ts'],
36+
coveragePathIgnorePatterns: ['migrate-cli.ts', 'plan-cli.ts'],
3737

3838
// Set the absolute path for imports
3939
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {

data-migration/user-transfer/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
"scripts": {
2323
"lint": "eslint ./src",
2424
"lint:fix": "eslint ./src --fix",
25+
"migrate": "tsx src/migrate-cli.ts",
26+
"plan": "tsx src/plan-cli.ts",
2527
"test:unit": "jest",
26-
"transfer": "tsx src/handler.ts",
2728
"typecheck": "tsc --noEmit"
2829
}
2930
}

data-migration/user-transfer/src/__tests__/user-transfer.test.ts

Lines changed: 0 additions & 88 deletions
This file was deleted.

data-migration/user-transfer/src/__tests__/utils/backup-utils.test.ts

Lines changed: 0 additions & 95 deletions
This file was deleted.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { mockDeep } from 'jest-mock-extended';
2+
import { CognitoRepository } from '../../utils/cognito-repository';
3+
import { CognitoIdentityProviderClient } from '@aws-sdk/client-cognito-identity-provider';
4+
5+
test('getAllUsers', async () => {
6+
const mockCognitoClient = mockDeep<CognitoIdentityProviderClient>({
7+
send: jest
8+
.fn()
9+
.mockResolvedValueOnce({
10+
Users: [
11+
{
12+
Username: 'username-1',
13+
Attributes: [
14+
{
15+
Name: 'sub',
16+
Value: 'sub-1',
17+
},
18+
],
19+
},
20+
{
21+
Username: 'username-2',
22+
},
23+
],
24+
})
25+
.mockResolvedValueOnce({
26+
Groups: [
27+
{
28+
GroupName: 'client:client-1',
29+
},
30+
],
31+
})
32+
.mockResolvedValueOnce({
33+
Groups: [],
34+
}),
35+
});
36+
37+
const cognitoRepository = new CognitoRepository(
38+
'user-pool-id',
39+
mockCognitoClient
40+
);
41+
42+
const users = await cognitoRepository.getAllUsers();
43+
44+
expect(users).toEqual([
45+
{
46+
username: 'username-1',
47+
clientId: 'client-1',
48+
userId: 'sub-1',
49+
},
50+
]);
51+
});
52+
53+
test('getAllUser - throws error', async () => {
54+
const mockCognitoClient = mockDeep<CognitoIdentityProviderClient>({
55+
send: jest
56+
.fn()
57+
.mockResolvedValueOnce({
58+
Users: [
59+
{
60+
Username: 'username-1',
61+
Attributes: [
62+
{
63+
Name: 'sub',
64+
Value: 'sub-1',
65+
},
66+
],
67+
},
68+
],
69+
})
70+
.mockImplementation(() => {
71+
throw new Error('error');
72+
}),
73+
});
74+
75+
const cognitoRepository = new CognitoRepository(
76+
'user-pool-id',
77+
mockCognitoClient
78+
);
79+
80+
await expect(
81+
async () => await cognitoRepository.getAllUsers()
82+
).rejects.toThrow('error');
83+
});

0 commit comments

Comments
 (0)