Skip to content

Commit

Permalink
feat: log all critical bounces (#288)
Browse files Browse the repository at this point in the history
* refactor: move bounce model into module

* refactor: inline tests

* refactor: move helpers into util

* feat: log admin responses to main log group

* feat: log all critical bounces

* refactor: use absolute paths in tests

* fix: fix constants import

* feat: log submission ID for critical bounces

* test: allow varying email type

* test: update tests for bounce service

* test: ignore __tests__ for coverage

* test: add test for short term logs

* build: ignore tests for compilation

* refactor: rename bounce-helpers to bounce-test-helpers

* refactor: avoid using lodash get

* refactor: convert EMAIL_TYPES to enum

* refactor: change log action to calling method

* refactor: change CRITICAL BOUNCE to sentence case

* refactor: move isCriticalBounce into domain

* refactor: move typeguards into util

* refactor: avoid typecast for IBounceNotification

* refactor: call logCriticalBounce only once

* refactor: remove setting of hasAlarmed

* refactor: extract function for logging raw notif

* docs: add TODO to convert bounceType to enum

* refactor: use typeguard to check recipients

* fix: convert formId to string

* fix: set hasAlarmed

* refactor: collapse save calls

* refactor: add bounceInfo key explicitly
  • Loading branch information
mantariksh authored Sep 10, 2020
1 parent d5bfd5a commit 22b8ab1
Show file tree
Hide file tree
Showing 13 changed files with 316 additions and 150 deletions.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = {
// Needed to use @shelf/jest-mongodb preset.
...tsJestPreset.transform,
},
collectCoverageFrom: ['./src/**/*.{ts,js}'],
collectCoverageFrom: ['./src/**/*.{ts,js}', '!**/__tests__/**'],
coveragePathIgnorePatterns: ['./node_modules/', './tests'],
coverageThreshold: {
global: {
Expand Down
12 changes: 6 additions & 6 deletions src/app/constants/mail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ export const EMAIL_HEADERS = {
}

// Types of emails we send
export const EMAIL_TYPES = {
adminResponse: 'Admin (response)',
loginOtp: 'Login OTP',
verificationOtp: 'Verification OTP',
emailConfirmation: 'Email confirmation',
adminBounce: 'Admin (bounce notification)',
export enum EmailType {
AdminResponse = 'Admin (response)',
LoginOtp = 'Login OTP',
VerificationOtp = 'Verification OTP',
EmailConfirmation = 'Email confirmation',
AdminBounce = 'Admin (bounce notification)',
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const makeEmailNotification = (
formId: ObjectId,
submissionId: ObjectId,
recipientList: string[],
emailType: 'Admin (response)' | 'Email confirmation',
): IEmailNotification => {
return {
notificationType,
Expand All @@ -43,7 +44,7 @@ const makeEmailNotification = (
},
{
name: 'X-Formsg-Email-Type',
value: 'Admin (response)',
value: emailType,
},
],
commonHeaders: {
Expand All @@ -61,9 +62,16 @@ export const makeBounceNotification = (
recipientList: string[] = [],
bouncedList: string[] = [],
bounceType: 'Transient' | 'Permanent' = 'Permanent',
emailType: 'Admin (response)' | 'Email confirmation' = 'Admin (response)',
): ISnsNotification => {
const Message = merge(
makeEmailNotification('Bounce', formId, submissionId, recipientList),
makeEmailNotification(
'Bounce',
formId,
submissionId,
recipientList,
emailType,
),
{
bounce: {
bounceType,
Expand All @@ -83,9 +91,16 @@ export const makeDeliveryNotification = (
submissionId: ObjectId = new ObjectId(),
recipientList: string[] = [],
deliveredList: string[] = [],
emailType: 'Admin (response)' | 'Email confirmation' = 'Admin (response)',
): ISnsNotification => {
const Message = merge(
makeEmailNotification('Delivery', formId, submissionId, recipientList),
makeEmailNotification(
'Delivery',
formId,
submissionId,
recipientList,
emailType,
),
{
delivery: {
recipients: deliveredList,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { ObjectId } from 'bson'
import { omit, pick } from 'lodash'
import mongoose from 'mongoose'
import dbHandler from 'tests/unit/backend/helpers/jest-db'

import getBounceModel from 'src/app/models/bounce.server.model'
import getBounceModel from 'src/app/modules/bounce/bounce.model'

import {
extractBounceObject,
makeBounceNotification,
makeDeliveryNotification,
} from '../helpers/bounce'
import dbHandler from '../helpers/jest-db'
} from './bounce-test-helpers'

const Bounce = getBounceModel(mongoose)

Expand Down
Loading

0 comments on commit 22b8ab1

Please sign in to comment.