1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-09-21 02:01:33 +02:00
This commit is contained in:
Flam3rboy 2021-09-02 00:14:34 +02:00
commit f056885fb0
7 changed files with 69 additions and 27 deletions

View File

@ -5,7 +5,7 @@
"main": "dist/Server.js", "main": "dist/Server.js",
"types": "dist/Server.d.ts", "types": "dist/Server.d.ts",
"scripts": { "scripts": {
"test": "npm run build && jest --coverage --verbose ./tests", "test": "npm run build && jest --coverage --verbose --forceExit ./tests",
"test:watch": "jest --watch", "test:watch": "jest --watch",
"start": "npm run build && node dist/start", "start": "npm run build && node dist/start",
"build": "npx tsc -b .", "build": "npx tsc -b .",
@ -90,9 +90,9 @@
}, },
"jest": { "jest": {
"setupFiles": [ "setupFiles": [
"<rootDir>/jest/setup.js", "<rootDir>/jest/setup.js"
"<rootDir>/scripts/setup_test.js"
], ],
"globalSetup": "<rootDir>/scripts/globalSetup.js",
"verbose": true "verbose": true
} }
} }

View File

@ -1,12 +1,13 @@
const fs = require("fs"); const fs = require("fs");
const { FosscordServer } = require("../dist/Server"); const { FosscordServer } = require("../dist/Server");
const Server = new FosscordServer({ port: 3001 }); const Server = new FosscordServer({ port: 3001 });
(async () => { global.server = Server;
module.exports = async () => {
try { try {
fs.unlinkSync(`${__dirname}/database.db`); fs.unlinkSync(`${__dirname}/../database.db`);
} catch {} } catch {}
return await Server.start(); return await Server.start();
})(); };
// afterAll(async () => { // afterAll(async () => {
// return await Server.stop(); // return await Server.stop();

View File

@ -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);
});
});
});

View File

@ -1,2 +0,0 @@
const supertest = require("supertest");
const request = supertest("http://localhost:1870");

View File

@ -1,10 +1,11 @@
const supertest = require("supertest"); const supertest = require("supertest");
const request = supertest("http://localhost:3001"); const request = supertest("http://localhost:3001");
describe("/api/register", () => { describe("/api/auth/register", () => {
describe("POST", () => { describe("POST", () => {
test("without body", async () => { test("without body", async () => {
const response = await request.post("/api/auth/register").send({}); const response = await request.post("/api/auth/register").send({});
expect(response.statusCode).toBe(400); expect(response.statusCode).toBe(400);
}); });
test("with body", async () => { test("with body", async () => {
@ -19,6 +20,7 @@ describe("/api/register", () => {
gift_code_sku_id: null, gift_code_sku_id: null,
captcha_key: null captcha_key: null
}); });
expect(response.statusCode).toBe(200); expect(response.statusCode).toBe(200);
}); });
}); });

42
cdn/package-lock.json generated
View File

@ -53,26 +53,30 @@
"hasInstallScript": true, "hasInstallScript": true,
"license": "GPLV3", "license": "GPLV3",
"dependencies": { "dependencies": {
"ajv": "^8.5.0", "ajv": "^8.6.2",
"amqplib": "^0.8.0", "amqplib": "^0.8.0",
"class-validator": "^0.13.1",
"dot-prop": "^6.0.1", "dot-prop": "^6.0.1",
"env-paths": "^2.2.1", "env-paths": "^2.2.1",
"jsonwebtoken": "^8.5.1", "jsonwebtoken": "^8.5.1",
"missing-native-js-functions": "^1.2.10", "lambert-server": "^1.2.10",
"mongodb": "^3.6.9", "missing-native-js-functions": "^1.2.11",
"mongoose": "^5.13.7",
"mongoose-autopopulate": "^0.12.3",
"node-fetch": "^2.6.1", "node-fetch": "^2.6.1",
"typescript": "^4.1.3" "patch-package": "^6.4.7",
"pg": "^8.7.1",
"reflect-metadata": "^0.1.13",
"sqlite3": "^5.0.2",
"typeorm": "^0.2.37",
"typescript": "^4.4.2",
"typescript-json-schema": "^0.50.1"
}, },
"devDependencies": { "devDependencies": {
"@types/amqplib": "^0.8.1", "@types/amqplib": "^0.8.1",
"@types/jsonwebtoken": "^8.5.0", "@types/jsonwebtoken": "^8.5.0",
"@types/mongodb": "^3.6.9",
"@types/mongoose-autopopulate": "^0.10.1", "@types/mongoose-autopopulate": "^0.10.1",
"@types/mongoose-lean-virtuals": "^0.5.1",
"@types/node": "^14.17.9", "@types/node": "^14.17.9",
"@types/node-fetch": "^2.5.12" "@types/node-fetch": "^2.5.12",
"jest": "^27.0.6"
} }
}, },
"node_modules/@babel/code-frame": { "node_modules/@babel/code-frame": {
@ -5965,22 +5969,26 @@
"requires": { "requires": {
"@types/amqplib": "^0.8.1", "@types/amqplib": "^0.8.1",
"@types/jsonwebtoken": "^8.5.0", "@types/jsonwebtoken": "^8.5.0",
"@types/mongodb": "^3.6.9",
"@types/mongoose-autopopulate": "^0.10.1", "@types/mongoose-autopopulate": "^0.10.1",
"@types/mongoose-lean-virtuals": "^0.5.1",
"@types/node": "^14.17.9", "@types/node": "^14.17.9",
"@types/node-fetch": "^2.5.12", "@types/node-fetch": "^2.5.12",
"ajv": "^8.5.0", "ajv": "^8.6.2",
"amqplib": "^0.8.0", "amqplib": "^0.8.0",
"class-validator": "^0.13.1",
"dot-prop": "^6.0.1", "dot-prop": "^6.0.1",
"env-paths": "^2.2.1", "env-paths": "^2.2.1",
"jest": "^27.0.6",
"jsonwebtoken": "^8.5.1", "jsonwebtoken": "^8.5.1",
"missing-native-js-functions": "^1.2.10", "lambert-server": "^1.2.10",
"mongodb": "^3.6.9", "missing-native-js-functions": "^1.2.11",
"mongoose": "^5.13.7",
"mongoose-autopopulate": "^0.12.3",
"node-fetch": "^2.6.1", "node-fetch": "^2.6.1",
"typescript": "^4.1.3" "patch-package": "^6.4.7",
"pg": "^8.7.1",
"reflect-metadata": "^0.1.13",
"sqlite3": "^5.0.2",
"typeorm": "^0.2.37",
"typescript": "^4.4.2",
"typescript-json-schema": "^0.50.1"
} }
}, },
"@istanbuljs/load-nyc-config": { "@istanbuljs/load-nyc-config": {

View File

@ -21,7 +21,7 @@ export function initDatabase() {
// //
entities: Object.values(Models).filter((x) => x.constructor.name !== "Object"), entities: Object.values(Models).filter((x) => x.constructor.name !== "Object"),
synchronize: true, synchronize: true,
logging: true, logging: false,
cache: { cache: {
duration: 1000 * 3, // cache all find queries for 3 seconds duration: 1000 * 3, // cache all find queries for 3 seconds
}, },