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

feat: log all critical bounces #288

Merged
merged 30 commits into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
28e648b
refactor: move bounce model into module
mantariksh Sep 7, 2020
1c847ec
refactor: inline tests
mantariksh Sep 7, 2020
4627bb7
refactor: move helpers into util
mantariksh Sep 7, 2020
da9fa12
feat: log admin responses to main log group
mantariksh Sep 7, 2020
f116dcd
feat: log all critical bounces
mantariksh Sep 7, 2020
4727bfe
refactor: use absolute paths in tests
mantariksh Sep 7, 2020
e45ee1a
fix: fix constants import
mantariksh Sep 7, 2020
6a4d903
feat: log submission ID for critical bounces
mantariksh Sep 7, 2020
9534df6
test: allow varying email type
mantariksh Sep 7, 2020
98ef7ee
test: update tests for bounce service
mantariksh Sep 7, 2020
cdbb4f8
test: ignore __tests__ for coverage
mantariksh Sep 7, 2020
4164671
test: add test for short term logs
mantariksh Sep 7, 2020
30eeaf3
build: ignore tests for compilation
mantariksh Sep 7, 2020
0ed4006
refactor: rename bounce-helpers to bounce-test-helpers
mantariksh Sep 7, 2020
3d6df6c
refactor: avoid using lodash get
mantariksh Sep 7, 2020
442058a
refactor: convert EMAIL_TYPES to enum
mantariksh Sep 10, 2020
6e45508
refactor: change log action to calling method
mantariksh Sep 10, 2020
faf0916
refactor: change CRITICAL BOUNCE to sentence case
mantariksh Sep 10, 2020
cd0ca43
refactor: move isCriticalBounce into domain
mantariksh Sep 10, 2020
c25d367
refactor: move typeguards into util
mantariksh Sep 10, 2020
fc4a5b5
refactor: avoid typecast for IBounceNotification
mantariksh Sep 10, 2020
3d211ee
refactor: call logCriticalBounce only once
mantariksh Sep 10, 2020
e8a5fb2
refactor: remove setting of hasAlarmed
mantariksh Sep 10, 2020
6b920ec
refactor: extract function for logging raw notif
mantariksh Sep 10, 2020
f166429
docs: add TODO to convert bounceType to enum
mantariksh Sep 10, 2020
5c4813b
refactor: use typeguard to check recipients
mantariksh Sep 10, 2020
f0ebc69
fix: convert formId to string
mantariksh Sep 10, 2020
488b4ce
fix: set hasAlarmed
mantariksh Sep 10, 2020
069af84
refactor: collapse save calls
mantariksh Sep 10, 2020
4fe6ae8
refactor: add bounceInfo key explicitly
mantariksh Sep 10, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
mantariksh marked this conversation as resolved.
Show resolved Hide resolved
): 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',
mantariksh marked this conversation as resolved.
Show resolved Hide resolved
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