Skip to content

Commit 58e77c8

Browse files
committed
chore: update dependencies
1 parent 58861f8 commit 58e77c8

14 files changed

Lines changed: 1166 additions & 214 deletions

File tree

packages/amplify-category-notifications/package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,20 @@
3030
"@aws-amplify/amplify-environment-parameters": "1.9.20",
3131
"@aws-amplify/amplify-prompts": "2.8.7",
3232
"@aws-amplify/amplify-provider-awscloudformation": "8.11.10",
33-
"aws-sdk": "^2.1464.0",
33+
"@aws-sdk/client-iam": "^3.901.0",
34+
"@aws-sdk/client-pinpoint": "^3.901.0",
35+
"@smithy/node-http-handler": "^4.3.0",
3436
"chalk": "^4.1.1",
3537
"fs-extra": "^8.1.0",
3638
"lodash": "^4.17.21",
3739
"ora": "^4.0.3",
3840
"promise-sequential": "^1.1.1",
3941
"proxy-agent": "^6.3.0"
4042
},
43+
"devDependencies": {
44+
"aws-sdk-client-mock": "^4.1.0",
45+
"aws-sdk-client-mock-jest": "^4.1.0"
46+
},
4147
"jest": {
4248
"testEnvironmentOptions": {
4349
"url": "http://localhost"
Lines changed: 44 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { $TSAny, $TSContext, AmplifyCategories, AmplifyFault, AmplifySupportedService, IContextPrint } from '@aws-amplify/amplify-cli-core';
22
import { prompter } from '@aws-amplify/amplify-prompts';
3+
import { mockClient } from 'aws-sdk-client-mock';
4+
import 'aws-sdk-client-mock-jest';
5+
import { PinpointClient, UpdateApnsChannelCommand, UpdateApnsSandboxChannelCommand } from '@aws-sdk/client-pinpoint';
36
import * as configureKey from '../apns-key-config';
47
import * as configureCertificate from '../apns-cert-config';
58

@@ -14,6 +17,8 @@ jest.mock('../apns-cert-config');
1417
jest.mock('@aws-amplify/amplify-prompts');
1518
const prompterMock = prompter as jest.Mocked<typeof prompter>;
1619

20+
const mockPinpointClient = mockClient(PinpointClient as any);
21+
1722
class NoErrorThrownError extends Error {}
1823
// wrapper to avoid conditional error checks
1924
const getError = async <TError>(call: () => unknown): Promise<TError> => {
@@ -44,7 +49,7 @@ describe('channel-APNS', () => {
4449

4550
const mockPinpointResponseErr = new Error('channel-APNS.test.js error');
4651
const mockPinpointResponseData = {
47-
APNSChannelResponse: {},
52+
APNSChannelResponse: { Enabled: true, ApplicationId: 'test-app-id' },
4853
};
4954

5055
const mockAPNSChannelResponseData = (status: boolean, action: ChannelAction, output: $TSAny): IChannelAPIResponse => ({
@@ -64,49 +69,22 @@ describe('channel-APNS', () => {
6469
const mockKeyConfig = {};
6570
const mockCertificateConfig = {};
6671

67-
const mockPinpointClient = {
68-
updateApnsChannel: jest.fn().mockReturnValue({
69-
promise: jest.fn().mockResolvedValue(mockPinpointResponseData),
70-
}),
71-
updateApnsSandboxChannel: jest.fn().mockReturnValue({
72-
promise: jest.fn().mockResolvedValue(mockPinpointResponseData),
73-
}),
74-
};
75-
76-
const mockPinpointClientReject = {
77-
updateApnsChannel: jest.fn().mockReturnValue({
78-
promise: jest.fn().mockRejectedValue(mockPinpointResponseErr),
79-
}),
80-
updateApnsSandboxChannel: jest.fn().mockReturnValue({
81-
promise: jest.fn().mockRejectedValue(mockPinpointResponseErr),
82-
}),
83-
};
84-
8572
const mockContext: $TSContext = {
8673
exeInfo: {
8774
serviceMeta: {
8875
output: mockServiceOutput,
8976
},
90-
pinpointClient: mockPinpointClient,
77+
pinpointClient: mockPinpointClient as any,
9178
},
9279
print: {
9380
info: jest.fn(),
9481
error: jest.fn(),
9582
} as unknown as IContextPrint,
9683
} as unknown as $TSContext;
9784

98-
const mockContextReject = {
99-
exeInfo: {
100-
serviceMeta: {
101-
output: mockServiceOutput,
102-
},
103-
pinpointClient: mockPinpointClientReject,
104-
},
105-
print: {
106-
info: jest.fn(),
107-
error: jest.fn(),
108-
},
109-
};
85+
beforeEach(() => {
86+
mockPinpointClient.reset();
87+
});
11088

11189
beforeAll(() => {
11290
global.console = { ...global.console, log: jest.fn() };
@@ -118,69 +96,73 @@ describe('channel-APNS', () => {
11896
});
11997

12098
test('configure', async () => {
99+
mockPinpointClient.on(UpdateApnsChannelCommand as any).resolves(mockPinpointResponseData as any);
100+
mockPinpointClient.on(UpdateApnsSandboxChannelCommand as any).resolves(mockPinpointResponseData as any);
101+
121102
mockChannelOutput.Enabled = true;
122103
prompterMock.yesOrNo.mockResolvedValueOnce(true);
123-
await channelAPNS.configure(mockContext).then(() => {
124-
expect(mockPinpointClient.updateApnsChannel).toBeCalled();
125-
});
104+
await channelAPNS.configure(mockContext);
105+
expect(mockPinpointClient).toHaveReceivedCommand(UpdateApnsChannelCommand as any);
126106

127107
mockChannelOutput.Enabled = true;
128108
prompterMock.yesOrNo.mockResolvedValueOnce(false);
129-
await channelAPNS.configure(mockContext).then(() => {
130-
expect(mockPinpointClient.updateApnsChannel).toBeCalled();
131-
});
109+
prompterMock.pick.mockResolvedValueOnce('Certificate');
110+
await channelAPNS.configure(mockContext);
111+
expect(mockPinpointClient).toHaveReceivedCommand(UpdateApnsChannelCommand as any);
132112

133113
mockChannelOutput.Enabled = false;
134114
prompterMock.yesOrNo.mockResolvedValueOnce(true);
135115
prompterMock.pick.mockResolvedValueOnce('Certificate');
136-
await channelAPNS.configure(mockContext).then(() => {
137-
expect(mockPinpointClient.updateApnsChannel).toBeCalled();
138-
});
116+
await channelAPNS.configure(mockContext);
117+
expect(mockPinpointClient).toHaveReceivedCommand(UpdateApnsChannelCommand as any);
139118
});
140119

141120
test('enable', async () => {
142-
prompterMock.pick.mockResolvedValueOnce('Certificate');
121+
mockPinpointClient.on(UpdateApnsChannelCommand as any).resolves(mockPinpointResponseData as any);
122+
mockPinpointClient.on(UpdateApnsSandboxChannelCommand as any).resolves(mockPinpointResponseData as any);
143123

124+
prompterMock.pick.mockResolvedValueOnce('Certificate');
144125
const disableData = await channelAPNS.enable(mockContext, 'successMessage');
145-
expect(mockPinpointClient.updateApnsChannel).toBeCalled();
146-
expect(mockPinpointClient.updateApnsSandboxChannel).toBeCalled();
126+
expect(mockPinpointClient).toHaveReceivedCommand(UpdateApnsChannelCommand as any);
127+
expect(mockPinpointClient).toHaveReceivedCommand(UpdateApnsSandboxChannelCommand as any);
147128
expect(disableData).toEqual(mockAPNSChannelResponseData(true, ChannelAction.ENABLE, mockPinpointResponseData.APNSChannelResponse));
148129

149130
prompterMock.pick.mockResolvedValueOnce('Key');
150131
const enableData = await channelAPNS.enable(mockContext, 'successMessage');
151-
expect(mockPinpointClient.updateApnsChannel).toBeCalled();
152-
expect(mockPinpointClient.updateApnsSandboxChannel).toBeCalled();
132+
expect(mockPinpointClient).toHaveReceivedCommand(UpdateApnsChannelCommand as any);
133+
expect(mockPinpointClient).toHaveReceivedCommand(UpdateApnsSandboxChannelCommand as any);
153134
expect(enableData).toEqual(mockAPNSChannelResponseData(true, ChannelAction.ENABLE, mockPinpointResponseData.APNSChannelResponse));
154135
});
155136

156137
test('enable unsuccessful', async () => {
157-
prompterMock.pick.mockResolvedValueOnce('Certificate');
138+
mockPinpointClient.on(UpdateApnsChannelCommand as any).rejects(mockPinpointResponseErr);
158139

159-
const errCert: AmplifyFault = await getError(async () =>
160-
channelAPNS.enable(mockContextReject as unknown as $TSContext, 'successMessage'),
161-
);
162-
expect(mockContextReject.exeInfo.pinpointClient.updateApnsChannel).toBeCalled();
140+
prompterMock.pick.mockResolvedValueOnce('Certificate');
141+
const errCert: AmplifyFault = await getError(async () => channelAPNS.enable(mockContext, 'successMessage'));
142+
expect(mockPinpointClient).toHaveReceivedCommand(UpdateApnsChannelCommand as any);
163143
expect(errCert?.downstreamException?.message).toContain(mockPinpointResponseErr.message);
164144

165145
prompterMock.pick.mockResolvedValueOnce('Key');
166-
const errKey: AmplifyFault = await getError(async () =>
167-
channelAPNS.enable(mockContextReject as unknown as $TSContext, 'successMessage'),
168-
);
169-
expect(mockPinpointClient.updateApnsChannel).toBeCalled();
146+
const errKey: AmplifyFault = await getError(async () => channelAPNS.enable(mockContext, 'successMessage'));
147+
expect(mockPinpointClient).toHaveReceivedCommand(UpdateApnsChannelCommand as any);
170148
expect(errKey?.downstreamException?.message).toContain(mockPinpointResponseErr.message);
171149
});
172150

173151
test('disable', async () => {
174-
await channelAPNS.disable(mockContext).then((data) => {
175-
expect(mockPinpointClient.updateApnsChannel).toBeCalled();
176-
expect(mockPinpointClient.updateApnsSandboxChannel).toBeCalled();
177-
expect(data).toEqual(mockAPNSChannelResponseData(true, ChannelAction.DISABLE, mockPinpointResponseData.APNSChannelResponse));
178-
});
152+
mockPinpointClient.on(UpdateApnsChannelCommand as any).resolves(mockPinpointResponseData as any);
153+
mockPinpointClient.on(UpdateApnsSandboxChannelCommand as any).resolves(mockPinpointResponseData as any);
154+
155+
const data = await channelAPNS.disable(mockContext);
156+
expect(mockPinpointClient).toHaveReceivedCommand(UpdateApnsChannelCommand as any);
157+
expect(mockPinpointClient).toHaveReceivedCommand(UpdateApnsSandboxChannelCommand as any);
158+
expect(data).toEqual(mockAPNSChannelResponseData(true, ChannelAction.DISABLE, mockPinpointResponseData.APNSChannelResponse));
179159
});
180160

181161
test('disable unsuccessful', async () => {
182-
const errKey: AmplifyFault = await getError(async () => channelAPNS.disable(mockContextReject as unknown as $TSContext));
183-
expect(mockPinpointClient.updateApnsChannel).toBeCalled();
162+
mockPinpointClient.on(UpdateApnsChannelCommand as any).rejects(mockPinpointResponseErr);
163+
164+
const errKey: AmplifyFault = await getError(async () => channelAPNS.disable(mockContext));
165+
expect(mockPinpointClient).toHaveReceivedCommand(UpdateApnsChannelCommand as any);
184166
expect(errKey?.downstreamException?.message).toContain(mockPinpointResponseErr.message);
185167
});
186168
});

packages/amplify-category-notifications/src/__tests__/channel-email.test.ts

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import { prompter } from '@aws-amplify/amplify-prompts';
2+
import { mockClient } from 'aws-sdk-client-mock';
3+
import 'aws-sdk-client-mock-jest';
4+
import { PinpointClient, UpdateEmailChannelCommand } from '@aws-sdk/client-pinpoint';
25
import * as channelEmail from '../channel-email';
36
import { ChannelAction, ChannelConfigDeploymentType, IChannelAPIResponse } from '../channel-types';
47
import { $TSAny, $TSContext, AmplifyCategories, AmplifySupportedService } from '@aws-amplify/amplify-cli-core';
@@ -19,11 +22,13 @@ jest.mock('@aws-amplify/amplify-cli-core', () => {
1922
jest.mock('@aws-amplify/amplify-prompts');
2023
const prompterMock = prompter as jest.Mocked<typeof prompter>;
2124

22-
const mockPinpointResponseData = (status: boolean, action: ChannelAction): IChannelAPIResponse => ({
25+
const mockPinpointClient = mockClient(PinpointClient as any);
26+
27+
const mockPinpointResponseData = (status: boolean, action: ChannelAction, output: any): IChannelAPIResponse => ({
2328
action,
2429
channel: ChannelType.Email,
2530
deploymentType: ChannelConfigDeploymentType.INLINE,
26-
output: undefined,
31+
output,
2732
response: {
2833
capability: AmplifyCategories.NOTIFICATIONS,
2934
pluginName: AmplifyCategories.NOTIFICATIONS,
@@ -33,36 +38,45 @@ const mockPinpointResponseData = (status: boolean, action: ChannelAction): IChan
3338
},
3439
});
3540

36-
const mockPinpointClient = {
37-
updateEmailChannel: jest.fn().mockImplementation(() => ({
38-
promise: jest.fn(() => mockPinpointResponseData(true, ChannelAction.ENABLE)),
39-
})),
40-
};
41-
42-
const mockContext = (output: $TSAny, client: $TSAny): $TSContext =>
41+
const mockContext = (output: $TSAny): $TSContext =>
4342
({
4443
exeInfo: {
4544
serviceMeta: {
4645
output,
4746
},
48-
pinpointClient: client,
47+
pinpointClient: mockPinpointClient as any,
4948
},
5049
print: {
5150
info: jest.fn(),
5251
error: jest.fn(),
5352
},
5453
} as unknown as $TSContext);
5554

56-
describe('channel-FCM', () => {
55+
describe('channel-Email', () => {
56+
const mockEmailChannelResponse = { Enabled: true, ApplicationId: 'test-app-id' };
57+
58+
beforeEach(() => {
59+
mockPinpointClient.reset();
60+
});
61+
5762
test('enable should store role arn', async () => {
63+
mockPinpointClient.on(UpdateEmailChannelCommand as any).resolves({ EmailChannelResponse: mockEmailChannelResponse } as any);
5864
prompterMock.input.mockResolvedValueOnce('fake@email.com');
5965
prompterMock.input.mockResolvedValueOnce('fake:arn:identity');
6066
prompterMock.input.mockResolvedValueOnce('fake:arn:role');
6167

62-
const mockContextObj = mockContext({ Enabled: true }, mockPinpointClient);
68+
const mockContextObj = mockContext({ Enabled: true });
6369
const data = await channelEmail.enable(mockContextObj, 'successMessage');
64-
expect(mockPinpointClient.updateEmailChannel).toBeCalled();
65-
expect(data).toEqual(mockPinpointResponseData(true, ChannelAction.ENABLE));
70+
expect(mockPinpointClient).toHaveReceivedCommandWith(UpdateEmailChannelCommand as any, {
71+
ApplicationId: undefined,
72+
EmailChannelRequest: {
73+
FromAddress: 'fake@email.com',
74+
Identity: 'fake:arn:identity',
75+
RoleArn: 'fake:arn:role',
76+
Enabled: true,
77+
},
78+
});
79+
expect(data).toEqual(mockPinpointResponseData(true, ChannelAction.ENABLE, mockEmailChannelResponse));
6680
expect(mockContextObj.exeInfo.serviceMeta.output['Email'].RoleArn).toEqual('fake:arn:role');
6781
});
6882
});

0 commit comments

Comments
 (0)