From 8095dd6bfceb1a4ae4f51fd2446a7da18db876c2 Mon Sep 17 00:00:00 2001
From: Bruce Berrios <58147810+Bruception@users.noreply.github.com>
Date: Thu, 5 May 2022 17:06:40 -0400
Subject: [PATCH] Add test step in pr-check action (#2942) Bruception

* Add test step in pr-check action

* Add jest action

* Specify wd

* Remove action

* Remove test

* Add anti-cheat check
---
 .github/workflows/pr-check.yml | 14 ++++++++++----
 backend/jest.config.ts         |  8 ++++++++
 backend/package.json           |  4 ++--
 package.json                   |  3 ++-
 4 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml
index c1031f340..6bd5d91cb 100644
--- a/.github/workflows/pr-check.yml
+++ b/.github/workflows/pr-check.yml
@@ -6,10 +6,12 @@ on:
 
 jobs:
   build:
+    permissions:
+      checks: write
+      pull-requests: write
     runs-on: ubuntu-latest
     steps:
       - uses: actions/checkout@v2
-
       - uses: dorny/paths-filter@v2
         id: filter
         with:
@@ -42,9 +44,9 @@ jobs:
         working-directory: ./frontend/src/ts/constants
         run: mv ./firebase-config-example.ts ./firebase-config-live.ts
 
-      # - name: Check Anti-cheat
-      #   if: steps.filter.outputs.anti-cheat == 'true'
-      #   run: exit 1
+      - name: Check Anti-cheat
+        if: steps.filter.outputs.anti-cheat == 'true'
+        run: exit 1
 
       - name: Cache node modules
         if: steps.filter.outputs.changes != '[]'
@@ -93,6 +95,10 @@ jobs:
         if: steps.filter.outputs.ts-be == 'true'
         run: npm run pr-check-build-be
 
+      - name: Test backend
+        if: steps.filter.outputs.ts-be == 'true'
+        run: npm run test-backend
+
       - name: Run webpack
         if: steps.filter.outputs.ts-scss-fe == 'true'
         run: npm run pr-check-ts
diff --git a/backend/jest.config.ts b/backend/jest.config.ts
index acd581fed..d3108588c 100644
--- a/backend/jest.config.ts
+++ b/backend/jest.config.ts
@@ -4,4 +4,12 @@ export default {
   preset: "@shelf/jest-mongodb",
   transform: tsjPreset.transform,
   setupFilesAfterEnv: ["<rootDir>/setup-tests.ts"],
+  coverageThreshold: {
+    global: {
+      branches: 0,
+      functions: 0,
+      lines: 0,
+      statements: 0,
+    },
+  },
 };
diff --git a/backend/package.json b/backend/package.json
index c37d671aa..cf86b34aa 100644
--- a/backend/package.json
+++ b/backend/package.json
@@ -8,8 +8,8 @@
     "watch": "tsc --build --watch",
     "clean": "tsc --build --clean",
     "start": "npm run build && node ./build/server.js",
-    "test": "jest",
-    "dev": "ts-node-dev ./src/server.ts -- --inspect --transpileOnly"
+    "test": "jest --verbose --collect-coverage",
+    "dev": "ts-node-dev server.ts -- --inspect --transpileOnly"
   },
   "engines": {
     "node": "16.13.2",
diff --git a/package.json b/package.json
index a55813fba..c91bb7c5b 100644
--- a/package.json
+++ b/package.json
@@ -21,7 +21,8 @@
     "pr-check-other-json": "cd frontend && npx gulp pr-check-other-json",
     "pr-check-ts": "cd frontend && npx gulp pr-check-ts",
     "pr-check-build-be": "cd backend && npm run build",
-    "docker": "cd backend && docker-compose up"
+    "docker": "cd backend && docker-compose up",
+    "test-backend": "cd backend && npm run test"
   },
   "engines": {
     "npm": "8.1.2"