Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 0 additions & 32 deletions api/cloud_api/routes/Mailer.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,36 +129,4 @@ router.post('/sendUnsubscribeEmail', async (req, res) => {
return res.sendStatus(OK);
});


// Routing post /sendBlastEmail calls the sendEmail function
// and sends the blast email with the blast email template
router.post('/sendBlastEmail', async (req, res) => {
if (!ENABLED && process.env.NODE_ENV !== 'test') {
return res.sendStatus(OK);
}
const scopes = ['https://mail.google.com/'];
const pathToToken = __dirname + '/../../config/token.json';
const apiHandler = new SceGoogleApiHandler(scopes, pathToToken);

await blastEmail(
USER,
req.body.emailList,
req.body.subject,
req.body.content
)
.then((template) => {
apiHandler
.sendEmail(template)
.then((_) => {
res.sendStatus(OK);
MetricsHandler.emailSent.inc({ type: 'blast' });
}).catch((_) => {
res.sendStatus(BAD_REQUEST);
});
})
.catch((_) => {
res.sendStatus(BAD_REQUEST);
});
});

module.exports = router;
6 changes: 1 addition & 5 deletions src/APIFunctions/2DPrinting.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ export async function healthCheck() {
const url = new URL('/api/Printer/healthCheck', BASE_API_URL);
try {
const res = await fetch(url.href);
if (res.ok) {
status.responseData = await res.json();
} else {
status.error = true;
}
status.error = !!res.ok;
} catch (err) {
status.responseData = err;
status.error = true;
Expand Down
21 changes: 0 additions & 21 deletions test/api/Mailer.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,4 @@ describe('Mailer', () => {
expect(result).to.have.status(BAD_REQUEST);
});
});

describe('/POST sendBlastEmail', () => {
it('Should return 200 when an email is successfully sent', async () => {
sendEmailStub.resolves({});
verificationStub.resolves({});
const result = await test.sendPostRequest(
'/api/Mailer/sendBlastEmail',
VALID_EMAIL_REQUEST
);
expect(result).to.have.status(OK);
});

it('Should return 400 when sending an email fails', async () => {
sendEmailStub.rejects({});
const result = await test.sendPostRequest(
'/api/Mailer/sendBlastEmail',
VALID_EMAIL_REQUEST
);
expect(result).to.have.status(BAD_REQUEST);
});
});
});