From e8ff7498c6eba4443dcff39b473f52453d26f427 Mon Sep 17 00:00:00 2001 From: xnacly Date: Wed, 1 Sep 2021 22:10:14 +0200 Subject: [PATCH 1/4] removed logging of database queries --- util/src/util/Database.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/src/util/Database.ts b/util/src/util/Database.ts index c22d8abd..d3844cd9 100644 --- a/util/src/util/Database.ts +++ b/util/src/util/Database.ts @@ -21,7 +21,7 @@ export function initDatabase() { // entities: Object.values(Models).filter((x) => x.constructor.name !== "Object"), synchronize: true, - logging: true, + logging: false, cache: { duration: 1000 * 3, // cache all find queries for 3 seconds }, From 26be2f9a1dcbcb1ecc5abb100b1920bb28597938 Mon Sep 17 00:00:00 2001 From: xnacly Date: Wed, 1 Sep 2021 22:10:44 +0200 Subject: [PATCH 2/4] fixed globalSetup for jest --- api/scripts/{setup_test.js => globalSetup.js} | 7 ++++--- cdn/package-lock.json | Bin 350229 -> 350423 bytes 2 files changed, 4 insertions(+), 3 deletions(-) rename api/scripts/{setup_test.js => globalSetup.js} (69%) diff --git a/api/scripts/setup_test.js b/api/scripts/globalSetup.js similarity index 69% rename from api/scripts/setup_test.js rename to api/scripts/globalSetup.js index 95bf2e40..76cd8e0d 100644 --- a/api/scripts/setup_test.js +++ b/api/scripts/globalSetup.js @@ -1,12 +1,13 @@ const fs = require("fs"); const { FosscordServer } = require("../dist/Server"); const Server = new FosscordServer({ port: 3001 }); -(async () => { +global.server = Server; +module.exports = async () => { try { - fs.unlinkSync(`${__dirname}/database.db`); + fs.unlinkSync(`${__dirname}/../database.db`); } catch {} return await Server.start(); -})(); +}; // afterAll(async () => { // return await Server.stop(); diff --git a/cdn/package-lock.json b/cdn/package-lock.json index 673395a5068117f8758227512aeb76992bd5e83f..a94f14097c53aa0e257cce38b27abc9785d2da6d 100644 GIT binary patch delta 578 zcmbQbLG=1Y(G9y;na%W!ChuicluFJ?EH2h9OU%hkNi4}PQnFG|iZjqNG}beme2q1F zvL}-`lcB-nL?&HE!|4iU%qsN-i6zMyx&?{J*@@|?VC80dCVJ*dI$WGUpj40!7PHVZ z*E58P6{V)-q$Zc>=BAb;0&PizSpu{MrlhzqC$l8g7%XF|XP{>UlPIYyNX;+Gg=#U< zV=^|Me4b5G#{^YLadJ^+L5Xfwaekg|adJj#F3b{Bpl2ovF#AlmGhx=6yn&r%vOkO3 z?VsdiA@$} WlN%nP*B)WU48$zkBg|O$Dgpp(ivCcuW^1}dVWfhl9hr|oUxvno~4ow z7bg%X<$@&gi&Mcerh10Pdgd^x$^Vy&a)ZSU^bC#kjHerzF{?~=XBT8P)H9we!0a>m z0=w2^ZI;T(`#U(MFJNS0nQXwJIlUx}QF;;==k!&1EZoiWIojuQFaj~t_W2ylS~}>; e4W{dxGIP<~#gh-23bkvRGXpWpc1?5Eb&3G_=TLtD From 5618e748b48acdaea07415e11252b77b35e9a999 Mon Sep 17 00:00:00 2001 From: xnacly Date: Wed, 1 Sep 2021 22:13:27 +0200 Subject: [PATCH 3/4] see parent --- api/package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/package.json b/api/package.json index 37db6ff3..66d94764 100644 --- a/api/package.json +++ b/api/package.json @@ -5,7 +5,7 @@ "main": "dist/Server.js", "types": "dist/Server.d.ts", "scripts": { - "test": "npm run build && jest --coverage --verbose ./tests", + "test": "npm run build && jest --coverage --verbose --forceExit ./tests", "test:watch": "jest --watch", "start": "npm run build && node dist/start", "build": "npx tsc -b .", @@ -86,9 +86,9 @@ }, "jest": { "setupFiles": [ - "/jest/setup.js", - "/scripts/setup_test.js" + "/jest/setup.js" ], + "globalSetup": "/scripts/globalSetup.js", "verbose": true } } From a1a859b1c163022d944ed97314480903fbca595a Mon Sep 17 00:00:00 2001 From: xnacly Date: Wed, 1 Sep 2021 22:14:06 +0200 Subject: [PATCH 4/4] added /login unittest --- api/tests/routes/auth/login.test.js | 33 ++++++++++++++++++++ api/tests/routes/auth/login.test.js.disabled | 2 -- api/tests/routes/auth/register.test.js | 4 ++- 3 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 api/tests/routes/auth/login.test.js delete mode 100644 api/tests/routes/auth/login.test.js.disabled diff --git a/api/tests/routes/auth/login.test.js b/api/tests/routes/auth/login.test.js new file mode 100644 index 00000000..d4b52444 --- /dev/null +++ b/api/tests/routes/auth/login.test.js @@ -0,0 +1,33 @@ +const supertest = require("supertest"); +const request = supertest("http://localhost:3001"); + +describe("/api/auth/login", () => { + describe("POST", () => { + test("without body", async () => { + const response = await request.post("/api/auth/login").send({}); + expect(response.statusCode).toBe(400); + }); + test("with body", async () => { + const user = { + login: "fortnitefortnite@gmail.com", + password: "verysecurepassword" + }; + + await request.post("/api/auth/register").send({ + fingerprint: "805826570869932034.wR8vi8lGlFBJerErO9LG5NViJFw", + email: user.login, + username: user.login.split("@")[0], + password: user.password, + invite: null, + consent: true, + date_of_birth: "2000-04-04", + gift_code_sku_id: null, + captcha_key: null + }); + + const response = await request.post("/api/auth/login").send(user); + + expect(response.statusCode).toBe(200); + }); + }); +}); diff --git a/api/tests/routes/auth/login.test.js.disabled b/api/tests/routes/auth/login.test.js.disabled deleted file mode 100644 index f677cebd..00000000 --- a/api/tests/routes/auth/login.test.js.disabled +++ /dev/null @@ -1,2 +0,0 @@ -const supertest = require("supertest"); -const request = supertest("http://localhost:1870"); diff --git a/api/tests/routes/auth/register.test.js b/api/tests/routes/auth/register.test.js index f42f004a..5d7b4eaa 100644 --- a/api/tests/routes/auth/register.test.js +++ b/api/tests/routes/auth/register.test.js @@ -1,10 +1,11 @@ const supertest = require("supertest"); const request = supertest("http://localhost:3001"); -describe("/api/register", () => { +describe("/api/auth/register", () => { describe("POST", () => { test("without body", async () => { const response = await request.post("/api/auth/register").send({}); + expect(response.statusCode).toBe(400); }); test("with body", async () => { @@ -19,6 +20,7 @@ describe("/api/register", () => { gift_code_sku_id: null, captcha_key: null }); + expect(response.statusCode).toBe(200); }); });