-
Notifications
You must be signed in to change notification settings - Fork 818
/
auth-defaults-appliers.test.ts
72 lines (62 loc) · 2.58 KB
/
auth-defaults-appliers.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
import { ServiceQuestionsResult } from '../../../../provider-utils/awscloudformation/service-walkthrough-types';
import { structureOAuthMetadata } from '../../../../provider-utils/awscloudformation/service-walkthroughs/auth-questions';
import {
getAddAuthDefaultsApplier,
getUpdateAuthDefaultsApplier,
} from '../../../../provider-utils/awscloudformation/utils/auth-defaults-appliers';
jest.mock(`../../../../provider-utils/awscloudformation/assets/cognito-defaults.js`, () => ({
functionMap: {
userPoolOnly: () => ({ some: 'default value' }),
},
getAllDefaults: jest.fn(),
generalDefaults: jest.fn().mockReturnValue({ requiredAttributes: ['email'] }),
}));
jest.mock('../../../../provider-utils/awscloudformation/service-walkthroughs/auth-questions', () => ({
structureOAuthMetadata: jest.fn(result => (result.include = 'this value')),
}));
jest.mock('amplify-cli-core', () => {
return {
FeatureFlags: {
getBoolean: jest.fn().mockImplementation((name, defaultValue) => {
if (name === 'auth.enableCaseInsensitivity') {
return true;
}
}),
getNumber: jest.fn(),
getObject: jest.fn(),
getString: jest.fn(),
},
};
});
const structureOAuthMetadata_mock = structureOAuthMetadata as jest.MockedFunction<typeof structureOAuthMetadata>;
describe('update auth defaults applier', () => {
it('calls structureOAuthMetadata', async () => {
const stubResult = {
useDefault: 'manual',
authSelections: 'userPoolOnly',
} as ServiceQuestionsResult;
const result = await getUpdateAuthDefaultsApplier({}, 'cognito-defaults.js', {} as ServiceQuestionsResult)(stubResult);
expect(result).toMatchSnapshot();
expect(structureOAuthMetadata_mock.mock.calls.length).toBe(1);
});
it('overwrites default parameters', async () => {
const stubResult = {
useDefault: 'manual',
authSelections: 'userPoolOnly',
requiredAttributes: [] as string[],
} as ServiceQuestionsResult;
const result = await getUpdateAuthDefaultsApplier({}, 'cognito-defaults.js', {} as ServiceQuestionsResult)(stubResult);
expect(result.requiredAttributes).toEqual([]);
});
});
describe('add auth defaults applier', () => {
it('overwrites default parameters', async () => {
const stubResult: ServiceQuestionsResult = {
useDefault: 'manual',
authSelections: 'userPoolOnly',
requiredAttributes: [] as string[],
} as ServiceQuestionsResult;
const result = await getAddAuthDefaultsApplier({}, 'cognito-defaults.js', 'testProjectName')(stubResult);
expect(result.requiredAttributes).toEqual([]);
});
});