diff --git a/.env_test b/.env_test new file mode 100644 index 0000000..8c37dce --- /dev/null +++ b/.env_test @@ -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 \ No newline at end of file diff --git a/.github/workflows/test-integration.yml b/.github/workflows/test-integration.yml new file mode 100644 index 0000000..c27570e --- /dev/null +++ b/.github/workflows/test-integration.yml @@ -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 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..273178a --- /dev/null +++ b/Makefile @@ -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 diff --git a/README.md b/README.md index e82d64c..16ce91a 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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` diff --git a/docker-compose.yml b/docker-compose.yml index 8c66700..a235e76 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 diff --git a/frontend/Dockerfile.test b/frontend/Dockerfile.test index d12c4c7..af1dfda 100644 --- a/frontend/Dockerfile.test +++ b/frontend/Dockerfile.test @@ -6,4 +6,4 @@ ENV NG_CLI_ANALYTICS="false" WORKDIR /app COPY . . RUN npm install -CMD ["npm", "run", "test-ci"] \ No newline at end of file +CMD ["npm", "run", "test-ci"] diff --git a/frontend/jest.config.js b/frontend/jest.config.js new file mode 100644 index 0000000..b460c7c --- /dev/null +++ b/frontend/jest.config.js @@ -0,0 +1,10 @@ +/** @type {import('ts-jest').JestConfigWithTsJest} */ +module.exports = { + "testPathIgnorePatterns": [ + "/node_modules/", + ".tmp", + ".cache" + ], + preset: 'ts-jest', + testEnvironment: 'node', +}; diff --git a/frontend/tests/app.test.js b/frontend/tests/app.test.js new file mode 100644 index 0000000..13bdfd1 --- /dev/null +++ b/frontend/tests/app.test.js @@ -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(); +}); diff --git a/frontend/tests/helpers/strapi.ts b/frontend/tests/helpers/strapi.ts new file mode 100644 index 0000000..4127148 --- /dev/null +++ b/frontend/tests/helpers/strapi.ts @@ -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 => { + if (!instance) { + instance = await strapi({distDir: "./dist"}).load(); + + instance.server.mount(); + } + return instance; +} + +export const cleanupStrapi = async (): Promise => { + const dbSettings = instance.config.get("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); + } + } +}