Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automate alert push notification tests #1735

Merged
merged 12 commits into from
Jan 3, 2020
84 changes: 48 additions & 36 deletions test/e2e/alerts.js
Expand Up @@ -330,16 +330,7 @@ const decodeEmail = (mailhog, attrs) =>
}
: attrs

const runScenario = async (client, scenarioId, options) => {
console.log('Running scenario', scenarioId)
const scenario = scenarios[scenarioId]
await importData(client, scenario.data)

if (options.mailhog) {
await options.mailhog.deleteAll()
}

console.log('Running service...')
const runService = async options => {
const env = {
...process.env,
IS_TESTING: 'test'
Expand All @@ -362,38 +353,59 @@ const runScenario = async (client, scenarioId, options) => {
if (!options.showOutput) {
console.error(`Re-run with -v to see its output.`)
}
return false
throw new Error('Error while running onOperationOrBillCreate')
ptbrowne marked this conversation as resolved.
Show resolved Hide resolved
}
}

console.log('Description: ', scenario.description)

if (options.mailhog) {
const mailhog = options.mailhog
const latestMessages = (await mailhog.messages(0, 1)).items
const email = decodeEmail(
options.mailhog,
latestMessages.length > 0 ? pick(latestMessages[0], ['subject']) : null
)
if (scenario.expectedEmail === null) {
if (!email) {
return true
} else {
console.error('Error: should not have received a mail')
return false
}
}
const isMatching = isMatch(email, scenario.expectedEmail)
if (isMatching) {
const checkEmailForScenario = async (mailhog, scenario) => {
const latestMessages = (await mailhog.messages(0, 1)).items
const email = decodeEmail(
mailhog,
latestMessages.length > 0 ? pick(latestMessages[0], ['subject']) : null
)
if (scenario.expectedEmail === null) {
if (!email) {
return true
} else {
console.error(
'Error:',
email,
'does not match expected',
scenario.expectedEmail
)
console.error('Error: should not have received a mail')
return false
}
}
const isMatching = isMatch(email, scenario.expectedEmail)
if (isMatching) {
return true
} else {
console.error(
'Error:',
email,
'does not match expected',
scenario.expectedEmail
)
return false
}
}

const runScenario = async (client, scenarioId, options) => {
console.log('Running scenario', scenarioId)
const scenario = scenarios[scenarioId]
await importData(client, scenario.data)

if (options.mailhog) {
await options.mailhog.deleteAll()
}

console.log('Running service...')
try {
await runService(options)
} catch (e) {
return false
}

console.log('Description: ', scenario.description)

if (options.mailhog) {
const emailMatch = await checkEmailForScenario(options.mailhog, scenario)
return emailMatch
} else {
const answer = await question('Is scenario OK (y|n) ? ')
return answer === 'y'
Expand Down