-
Notifications
You must be signed in to change notification settings - Fork 822
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* fix: pull issue with multi-env notifications #6475 * fix notification category multi-env handling * fix to ask for `API key` for FCM on `remove notification` command * add E2E for notification testing
- Loading branch information
Attila Hajdrik
authored
Mar 2, 2021
1 parent
7f89462
commit b0803d1
Showing
8 changed files
with
426 additions
and
233 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { nspawn as spawn, getCLIPath, singleSelect } from '..'; | ||
|
||
export type NotificationSettings = { | ||
resourceName: string; | ||
}; | ||
|
||
export const addSMSNotification = async (cwd: string, settings: NotificationSettings): Promise<void> => { | ||
return new Promise((resolve, reject) => { | ||
let chain = spawn(getCLIPath(), ['add', 'notification'], { cwd, stripColors: true }); | ||
|
||
singleSelect(chain.wait('Choose the push notification channel to enable'), 'SMS', ['APNS', 'FCM', 'Email', 'SMS']); | ||
|
||
chain | ||
.wait('Provide your pinpoint resource name') | ||
.sendLine(settings.resourceName) | ||
.wait('The SMS channel has been successfully enabled') | ||
.sendEof() | ||
.run((err: Error) => { | ||
if (!err) { | ||
resolve(undefined); | ||
} else { | ||
reject(err); | ||
} | ||
}); | ||
}); | ||
}; |
87 changes: 87 additions & 0 deletions
87
packages/amplify-e2e-tests/src/__tests__/notifications.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import _ from 'lodash'; | ||
import { | ||
addSMSNotification, | ||
amplifyPull, | ||
amplifyPushAuth, | ||
createNewProjectDir, | ||
deleteProject, | ||
deleteProjectDir, | ||
getAppId, | ||
getTeamProviderInfo, | ||
initJSProjectWithProfile, | ||
} from 'amplify-e2e-core'; | ||
import { checkoutEnvironment, removeEnvironment } from '../environment/env'; | ||
import { getShortId } from '../import-helpers'; | ||
|
||
const profileName = 'amplify-integ-test-user'; | ||
|
||
describe('notification category test', () => { | ||
const projectPrefix = 'notification'; | ||
|
||
const projectSettings = { | ||
name: projectPrefix, | ||
}; | ||
|
||
let projectRoot: string; | ||
let ignoreProjectDeleteErrors: boolean = false; | ||
|
||
beforeEach(async () => { | ||
projectRoot = await createNewProjectDir(projectPrefix); | ||
ignoreProjectDeleteErrors = false; | ||
}); | ||
|
||
afterEach(async () => { | ||
try { | ||
await deleteProject(projectRoot); | ||
} catch (error) { | ||
// In some tests where project initialization fails it can lead to errors on cleanup which we | ||
// can ignore if set by the test | ||
if (!ignoreProjectDeleteErrors) { | ||
throw error; | ||
} | ||
} | ||
deleteProjectDir(projectRoot); | ||
}); | ||
|
||
it('add notifications and pull to empty dir to compare values', async () => { | ||
await initJSProjectWithProfile(projectRoot, { | ||
...projectSettings, | ||
disableAmplifyAppCreation: false, | ||
}); | ||
|
||
const shortId = getShortId(); | ||
|
||
const settings = { | ||
resourceName: `${projectPrefix}${shortId}`, | ||
}; | ||
|
||
await addSMSNotification(projectRoot, settings); | ||
|
||
await amplifyPushAuth(projectRoot); | ||
|
||
const appId = getAppId(projectRoot); | ||
expect(appId).toBeDefined(); | ||
|
||
let projectRootPull; | ||
|
||
try { | ||
projectRootPull = await createNewProjectDir('notification-pull'); | ||
|
||
await amplifyPull(projectRootPull, { override: false, emptyDir: true, appId }); | ||
|
||
expectLocalAndPulledTeamNotificationMatching(projectRoot, projectRootPull); | ||
} finally { | ||
deleteProjectDir(projectRootPull); | ||
} | ||
}); | ||
|
||
const expectLocalAndPulledTeamNotificationMatching = (projectRoot: string, pulledProjectRoot: string) => { | ||
const team = getTeamProviderInfo(projectRoot); | ||
const pulledTeam = getTeamProviderInfo(pulledProjectRoot); | ||
|
||
const pinpointApp = _.get(team, ['integtest', 'categories', 'notifications']); | ||
const pulledPinpointApp = _.get(pulledTeam, ['integtest', 'categories', 'notifications']); | ||
|
||
expect(pinpointApp).toMatchObject(pulledPinpointApp); | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters