add sample test

This commit is contained in:
Maxime Cannoodt 2022-07-09 10:47:03 +02:00
parent 0efd3f4056
commit 2be7bfcaee
5 changed files with 72 additions and 2 deletions

View File

@ -23,6 +23,7 @@
"@types/express": "^4.17.13", "@types/express": "^4.17.13",
"@types/node": "^18.0.0", "@types/node": "^18.0.0",
"@types/sqlite3": "^3.1.8", "@types/sqlite3": "^3.1.8",
"@types/supertest": "^2.0.12",
"nodemon": "^2.0.18", "nodemon": "^2.0.18",
"pino-colada": "^2.2.2", "pino-colada": "^2.2.2",
"prisma": "^4.0.0", "prisma": "^4.0.0",
@ -251,6 +252,12 @@
"@types/node": "*" "@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": { "node_modules/@types/cors": {
"version": "2.8.12", "version": "2.8.12",
"resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.12.tgz", "resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.12.tgz",
@ -323,6 +330,25 @@
"@types/node": "*" "@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": { "node_modules/abbrev": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
@ -4538,6 +4564,12 @@
"@types/node": "*" "@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": { "@types/cors": {
"version": "2.8.12", "version": "2.8.12",
"resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.12.tgz", "resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.12.tgz",
@ -4610,6 +4642,25 @@
"@types/node": "*" "@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": { "abbrev": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",

View File

@ -27,6 +27,7 @@
"@types/express": "^4.17.13", "@types/express": "^4.17.13",
"@types/node": "^18.0.0", "@types/node": "^18.0.0",
"@types/sqlite3": "^3.1.8", "@types/sqlite3": "^3.1.8",
"@types/supertest": "^2.0.12",
"nodemon": "^2.0.18", "nodemon": "^2.0.18",
"pino-colada": "^2.2.2", "pino-colada": "^2.2.2",
"prisma": "^4.0.0", "prisma": "^4.0.0",

14
server/src/app.test.ts Normal file
View File

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

View File

@ -71,6 +71,11 @@ app.get("/api/note/:id", (req, res, next) => {
.catch(next); .catch(next);
}); });
// For testing purposes
app.get("/api/test", (req, res, next) => {
res.status(200).send("Hello world!");
});
// Clean up expired notes periodically // Clean up expired notes periodically
const interval = const interval =
Math.max(parseInt(<string>process.env.CLEANUP_INTERVAL_SECONDS) || 1, 1) * Math.max(parseInt(<string>process.env.CLEANUP_INTERVAL_SECONDS) || 1, 1) *

View File

@ -9,7 +9,6 @@
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */, "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
"strict": true /* Enable all strict type-checking options. */, "strict": true /* Enable all strict type-checking options. */,
"noImplicitAny": true /* Enable error reporting for expressions and declarations with an implied 'any' type. */, "noImplicitAny": true /* Enable error reporting for expressions and declarations with an implied 'any' type. */,
"skipLibCheck": true /* Skip type checking all .d.ts files. */, "skipLibCheck": true /* Skip type checking all .d.ts files. */
"types": ["vitest/globals"]
} }
} }