Compare commits

...

2 Commits

Author SHA1 Message Date
Suguivy 98086640e5 Merge pull request 'Added unit testing' (#1) from unit-testing into main
Reviewed-on: #1
2023-12-25 11:20:13 +00:00
Sugui d749743e56 Added unit testing 2023-12-25 12:15:19 +01:00
3 changed files with 33 additions and 4 deletions

View File

@ -3,13 +3,20 @@
"module": "index.ts",
"type": "module",
"devDependencies": {
"bun-types": "latest"
"@types/jest": "^29.5.11",
"@types/supertest": "^6.0.1",
"bun-types": "latest",
"jest": "^29.7.0",
"supertest": "^6.3.3",
"ts-jest": "^29.1.1"
},
"peerDependencies": {
"typescript": "^5.0.0"
},"scripts": {
},
"scripts": {
"start": "bun run src/index.ts",
"dev": "bun --hot run src/index.ts"
"dev": "bun --hot run src/index.ts",
"test": "bun test"
},
"dependencies": {
"@types/express": "^4.17.21",

View File

@ -2,7 +2,7 @@ import express from "express";
import mongoose from "mongoose";
import ImageModel from "./ImageModel";
const app = express();
export const app = express();
app.use(express.json());

22
tests/app.test.ts Normal file
View File

@ -0,0 +1,22 @@
import { describe, expect, it } from "bun:test";
import request from "supertest";
import { app } from "../src";
describe("GET /images works properly", () => {
it("should be an array", async () => {
const res = await request(app).get("/images");
expect(Array.isArray(res.body)).toBeTrue();
expect(res.statusCode).toBe(200);
});
});
describe("POST /images works properly", () => {
it("should return 201 or 409", async () => {
const res = await request(app).post("/images").send({
url: "https://test.url.com/123",
status: "available",
tags: ["2girls", "touhou"]
});
expect(res.status).toSatisfy(status => [201, 409].includes(status));
});
});