Skip to content

Commit

Permalink
fix: update notification channel name lookup (#12763)
Browse files Browse the repository at this point in the history
* fix: notification update
  • Loading branch information
lazpavel committed Jun 14, 2023
1 parent bad7c96 commit 92ca721
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ export const alias = 'update';
*/
export const run = async (context: $TSContext): Promise<$TSContext> => {
const availableChannelViewNames = getAvailableChannelViewNames();
const channelName = context.parameters.first;
let channelViewName = channelName ? getChannelViewName(channelName) : undefined;
let channelViewName = context.parameters.first ? getChannelViewName(context.parameters.first) : undefined;

if (!channelViewName || !availableChannelViewNames.includes(channelViewName)) {
channelViewName = await prompter.pick('Choose the notification channel to configure', availableChannelViewNames);
}
if (channelViewName && typeof channelName === 'string') {
const selectedChannel = getChannelNameFromView(channelViewName);

if (channelViewName) {
const channelName = getChannelNameFromView(channelViewName);
let pinpointAppStatus = await pinpointHelper.ensurePinpointApp(context, undefined);
// In-line deployment now requires an amplify-push to create the Pinpoint resource
if (pinpointHelper.isPinpointDeploymentRequired(channelName, pinpointAppStatus)) {
Expand All @@ -55,8 +55,8 @@ export const run = async (context: $TSContext): Promise<$TSContext> => {
);
}
}
if (isPinpointAppDeployed(pinpointAppStatus.status) || isChannelDeploymentDeferred(selectedChannel)) {
const channelAPIResponse: IChannelAPIResponse | undefined = await notificationManager.configureChannel(context, selectedChannel);
if (isPinpointAppDeployed(pinpointAppStatus.status) || isChannelDeploymentDeferred(channelName)) {
const channelAPIResponse: IChannelAPIResponse | undefined = await notificationManager.configureChannel(context, channelName);
await writeData(context, channelAPIResponse);
}
} else {
Expand Down
24 changes: 24 additions & 0 deletions packages/amplify-e2e-core/src/categories/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,27 @@ export const addNotificationChannel = async (

return chain.wait(`The ${channel} channel has been successfully enabled`).sendEof().runAsync();
};

/**
* Update notification resource for a given channel
*
* @param cwd the current working directory to run CLI in
* @param settings settings required to add a notification channel
* @param settings.resourceName the name to give to the created pinpoint resource
* @param channel the channel to add
*/
export const updateNotificationChannel = async (
cwd: string,
channel: string,
enable = true,
testingWithLatestCodebase = true,
): Promise<void> => {
const chain = spawn(getCLIPath(testingWithLatestCodebase), ['update', 'notification'], { cwd, stripColors: true });
chain.wait('Choose the notification channel to configure').sendLine(channel);
chain.wait(`Do you want to ${enable ? 'enable' : 'disable'} the ${channel} channel`).sendYes();

return chain
.wait(`The ${channel} channel has been ${enable ? 'enabled' : 'disabled'}`)
.sendEof()
.runAsync();
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {
addNotificationChannel,
createNewProjectDir,
deleteProject,
deleteProjectDir,
initJSProjectWithProfile,
updateNotificationChannel,
} from '@aws-amplify/amplify-e2e-core';
import { getShortId } from '../import-helpers';

describe('notification category update test', () => {
const testChannel = 'SMS';
const testChannelSelection = 'SMS';
const projectPrefix = `notification${testChannel}`.substring(0, 19);
const projectSettings = {
name: projectPrefix,
disableAmplifyAppCreation: false,
};

let projectRoot: string;

beforeEach(async () => {
projectRoot = await createNewProjectDir(projectPrefix);
});

afterEach(async () => {
await deleteProject(projectRoot);
deleteProjectDir(projectRoot);
});

it(`should add and update the ${testChannel} channel`, async () => {
await initJSProjectWithProfile(projectRoot, projectSettings);

const settings = { resourceName: `${projectPrefix}${getShortId()}` };
await addNotificationChannel(projectRoot, settings, testChannelSelection);
await updateNotificationChannel(projectRoot, testChannelSelection, false);
});
});

0 comments on commit 92ca721

Please sign in to comment.