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

Add backend tests to CI #71

Merged
merged 9 commits into from
Jul 27, 2023
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
39 changes: 39 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: Node.js CI

on:
push:
branches:
- main
- dev
pull_request:
branches:
- main
- dev

jobs:
build-test-backend:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

defaults:
run:
working-directory: ./backend
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache-dependency-path: './backend/package-lock.json'
- run: npm ci
- run: npm run build --if-present
- run: npm test
21 changes: 9 additions & 12 deletions backend/test/unit/email.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,7 @@ test("GIVEN email is ready to be sent WHEN email is sent THEN session list is up
};
const response = sendEmail(address, subject, body, session);
// check the response
expect(response).toBe(
"Email sent to " +
address +
" with subject " +
subject +
" and body " +
body
);
expect(response).toBe(JSON.stringify({ isEmailSent: true }));
// check the sent email has been added to the session
expect(session.sentEmails.length).toBe(1);
expect(session.sentEmails[0].address).toBe(address);
Expand All @@ -30,16 +23,20 @@ test("GIVEN email is ready to be sent WHEN email is sent THEN session list is up

test("GIVEN EMAIL_WHITELIST envionrment variable is set WHEN getting whitelist AND whitelist defense on THEN list is returned", () => {
process.env.EMAIL_WHITELIST = "bob@example.com,kate@example.com";
const isDefenceActive = true;
const isDefenceActive = true;
const whitelist = getEmailWhitelist(isDefenceActive);
expect(whitelist).toBe("The whitelisted emails and domains are: "+ process.env.EMAIL_WHITELIST);
expect(whitelist).toBe(
"The whitelisted emails and domains are: " + process.env.EMAIL_WHITELIST
);
});

test("GIVEN EMAIL_WHITELIST envionrment variable is set WHEN getting whitelist AND whitelist defense off THEN text is returned", () => {
process.env.EMAIL_WHITELIST = "bob@example.com,kate@example.com";
const isDefenceActive = false;
const isDefenceActive = false;
const whitelist = getEmailWhitelist(isDefenceActive);
expect(whitelist).toBe("As the email whitelist defence is not active, any email address can be emailed.");
expect(whitelist).toBe(
"As the email whitelist defence is not active, any email address can be emailed."
);
});

test("GIVEN email is not in whitelist WHEN checking whitelist THEN false is returned", () => {
Expand Down