Skip to content
Open
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
11 changes: 11 additions & 0 deletions .env_test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
HOST=0.0.0.0
PORT=1337
APP_KEYS=ZLOWy3eQveTXpEgwqQ7WTA==,mpIfppgPTCRQbtP4alpRpw==,erpwTcq03kk/6FsVSKyZaw==,I4VvkD+ucVS8diXHTL0+eg==
API_TOKEN_SALT=XFkrawFybUK3Qh5MNYcAAA==
ADMIN_JWT_SECRET=1M+6TpwrWYyPYtdHiLLYXg==
TRANSFER_TOKEN_SALT=3Oc+vfbVkEcFWFiqAJW2bQ==
# Database
DATABASE_CLIENT=sqlite
JWT_SECRET=6iZBa/zctckbHoRmA/xfqQ==
# ENV
NODE_ENV=test
16 changes: 16 additions & 0 deletions .github/workflows/test-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Run integration test using docker-compose
on:
push:
branches:
- main
pull_request:
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 2
steps:
- uses: actions/checkout@v2
- name: Build and run tests
run: make test
- name: TearDown
run: make down
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
SHELL := /usr/bin/env bash

.PHONY:
up:
docker-compose up -d --remove-orphans

.PHONY:
test:
docker-compose -f docker-compose.yml run backend-test frontend-test

.PHONY:
down:
docker-compose down --remove-orphans
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ application including web shop + planning software for goods and delivery.

## Local Development Setup

* `docker-compose up`
* `make up`
* Open `http://localhost:8055/` locally and login with `admin@example.com` + `admin`

## Components Overview
Expand Down Expand Up @@ -61,3 +61,7 @@ Overnight bakers night need to prepare the ordered goods which are then shipped
## Value proposition

For details please refer to: https://docs.google.com/document/d/1pH0qjtOCmJ9wbqzUIkqdiRtdwsFonX-IpqglRnEzz4I/edit?usp=sharing

# Local Developer Setup

* `make`
9 changes: 9 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ services:
backend-db:
condition: service_healthy

backend-test:
build:
context: ./backend
dockerfile: Dockerfile
command: ["npm", "test"]
depends_on:
backend:
condition: service_healthy

backend-db:
container_name: backend-db
platform: linux/amd64 # for platform error on Apple M1 chips
Expand Down
2 changes: 1 addition & 1 deletion frontend/Dockerfile.test
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ ENV NG_CLI_ANALYTICS="false"
WORKDIR /app
COPY . .
RUN npm install
CMD ["npm", "run", "test-ci"]
CMD ["npm", "run", "test-ci"]
10 changes: 10 additions & 0 deletions frontend/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
"testPathIgnorePatterns": [
"/node_modules/",
".tmp",
".cache"
],
preset: 'ts-jest',
testEnvironment: 'node',
};
17 changes: 17 additions & 0 deletions frontend/tests/app.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const fs = require('fs');
const { setupStrapi, cleanupStrapi } = require("./helpers/strapi");
jest.useFakeTimers()

jest.setTimeout(20000)

beforeAll(async () => {
await setupStrapi();
});

afterAll(async () => {
await cleanupStrapi();
});

it("strapi is defined", () => {
expect(strapi).toBeDefined();
});
34 changes: 34 additions & 0 deletions frontend/tests/helpers/strapi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import fs from "fs";
import strapi, { Strapi } from "@strapi/strapi";
import {Knex} from "knex";
import Config = Knex.Config;

let instance: Strapi;

export const setupStrapi = async (): Promise<Strapi> => {
if (!instance) {
instance = await strapi({distDir: "./dist"}).load();

instance.server.mount();
}
return instance;
}

export const cleanupStrapi = async (): Promise<void> => {
const dbSettings = instance.config.get<Config>("database.connection");
console.log(dbSettings);

//close server to release the db-file
instance.server.httpServer.close();

// close the connection to the database before deletion
await instance.db.connection.destroy();

//delete test database after all tests have completed
if (dbSettings && dbSettings.connection && (dbSettings.connection as Knex.Sqlite3ConnectionConfig).filename) {
const tmpDbFile = (dbSettings.connection as Knex.Sqlite3ConnectionConfig).filename;
if (fs.existsSync(tmpDbFile)) {
fs.unlinkSync(tmpDbFile);
}
}
}