From 2be7bfcaee24afc757bbb37a71c30c55cfcf5c87 Mon Sep 17 00:00:00 2001 From: Maxime Cannoodt Date: Sat, 9 Jul 2022 10:47:03 +0200 Subject: [PATCH] add sample test --- server/package-lock.json | 51 ++++++++++++++++++++++++++++++++++++++++ server/package.json | 1 + server/src/app.test.ts | 14 +++++++++++ server/src/app.ts | 5 ++++ server/tsconfig.json | 3 +-- 5 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 server/src/app.test.ts diff --git a/server/package-lock.json b/server/package-lock.json index 415ad48..6e7bcfa 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -23,6 +23,7 @@ "@types/express": "^4.17.13", "@types/node": "^18.0.0", "@types/sqlite3": "^3.1.8", + "@types/supertest": "^2.0.12", "nodemon": "^2.0.18", "pino-colada": "^2.2.2", "prisma": "^4.0.0", @@ -251,6 +252,12 @@ "@types/node": "*" } }, + "node_modules/@types/cookiejar": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/@types/cookiejar/-/cookiejar-2.1.2.tgz", + "integrity": "sha512-t73xJJrvdTjXrn4jLS9VSGRbz0nUY3cl2DMGDU48lKl+HR9dbbjW2A9r3g40VA++mQpy6uuHg33gy7du2BKpog==", + "dev": true + }, "node_modules/@types/cors": { "version": "2.8.12", "resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.12.tgz", @@ -323,6 +330,25 @@ "@types/node": "*" } }, + "node_modules/@types/superagent": { + "version": "4.1.15", + "resolved": "https://registry.npmjs.org/@types/superagent/-/superagent-4.1.15.tgz", + "integrity": "sha512-mu/N4uvfDN2zVQQ5AYJI/g4qxn2bHB6521t1UuH09ShNWjebTqN0ZFuYK9uYjcgmI0dTQEs+Owi1EO6U0OkOZQ==", + "dev": true, + "dependencies": { + "@types/cookiejar": "*", + "@types/node": "*" + } + }, + "node_modules/@types/supertest": { + "version": "2.0.12", + "resolved": "https://registry.npmjs.org/@types/supertest/-/supertest-2.0.12.tgz", + "integrity": "sha512-X3HPWTwXRerBZS7Mo1k6vMVR1Z6zmJcDVn5O/31whe0tnjE4te6ZJSJGq1RiqHPjzPdMTfjCFogDJmwng9xHaQ==", + "dev": true, + "dependencies": { + "@types/superagent": "*" + } + }, "node_modules/abbrev": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", @@ -4538,6 +4564,12 @@ "@types/node": "*" } }, + "@types/cookiejar": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/@types/cookiejar/-/cookiejar-2.1.2.tgz", + "integrity": "sha512-t73xJJrvdTjXrn4jLS9VSGRbz0nUY3cl2DMGDU48lKl+HR9dbbjW2A9r3g40VA++mQpy6uuHg33gy7du2BKpog==", + "dev": true + }, "@types/cors": { "version": "2.8.12", "resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.12.tgz", @@ -4610,6 +4642,25 @@ "@types/node": "*" } }, + "@types/superagent": { + "version": "4.1.15", + "resolved": "https://registry.npmjs.org/@types/superagent/-/superagent-4.1.15.tgz", + "integrity": "sha512-mu/N4uvfDN2zVQQ5AYJI/g4qxn2bHB6521t1UuH09ShNWjebTqN0ZFuYK9uYjcgmI0dTQEs+Owi1EO6U0OkOZQ==", + "dev": true, + "requires": { + "@types/cookiejar": "*", + "@types/node": "*" + } + }, + "@types/supertest": { + "version": "2.0.12", + "resolved": "https://registry.npmjs.org/@types/supertest/-/supertest-2.0.12.tgz", + "integrity": "sha512-X3HPWTwXRerBZS7Mo1k6vMVR1Z6zmJcDVn5O/31whe0tnjE4te6ZJSJGq1RiqHPjzPdMTfjCFogDJmwng9xHaQ==", + "dev": true, + "requires": { + "@types/superagent": "*" + } + }, "abbrev": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", diff --git a/server/package.json b/server/package.json index cdc4827..20fa030 100644 --- a/server/package.json +++ b/server/package.json @@ -27,6 +27,7 @@ "@types/express": "^4.17.13", "@types/node": "^18.0.0", "@types/sqlite3": "^3.1.8", + "@types/supertest": "^2.0.12", "nodemon": "^2.0.18", "pino-colada": "^2.2.2", "prisma": "^4.0.0", diff --git a/server/src/app.test.ts b/server/src/app.test.ts new file mode 100644 index 0000000..50e1e46 --- /dev/null +++ b/server/src/app.test.ts @@ -0,0 +1,14 @@ +import app from "./app"; +import request from "supertest"; +import { describe, it, expect } from "vitest"; + +describe("GET /api/test", () => { + it('should respond "Hello world!"', () => { + return request(app) + .get("/api/test") + .then((res) => { + expect(res.statusCode).toBe(200); + expect(res.text).toBe("Hello world!"); + }); + }); +}); diff --git a/server/src/app.ts b/server/src/app.ts index 50f84ae..8b12497 100644 --- a/server/src/app.ts +++ b/server/src/app.ts @@ -71,6 +71,11 @@ app.get("/api/note/:id", (req, res, next) => { .catch(next); }); +// For testing purposes +app.get("/api/test", (req, res, next) => { + res.status(200).send("Hello world!"); +}); + // Clean up expired notes periodically const interval = Math.max(parseInt(process.env.CLEANUP_INTERVAL_SECONDS) || 1, 1) * diff --git a/server/tsconfig.json b/server/tsconfig.json index 989a664..1dc9eb6 100644 --- a/server/tsconfig.json +++ b/server/tsconfig.json @@ -9,7 +9,6 @@ "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */, "strict": true /* Enable all strict type-checking options. */, "noImplicitAny": true /* Enable error reporting for expressions and declarations with an implied 'any' type. */, - "skipLibCheck": true /* Skip type checking all .d.ts files. */, - "types": ["vitest/globals"] + "skipLibCheck": true /* Skip type checking all .d.ts files. */ } }