diff --git a/backend/src/__tests__/item.test.ts b/backend/src/__tests__/item.test.ts index 3d992f9..2f3de50 100644 --- a/backend/src/__tests__/item.test.ts +++ b/backend/src/__tests__/item.test.ts @@ -27,6 +27,10 @@ export const userPayload = { contactNumber: "0712345678", }; + +/** + * Main test suite + */ describe("site", () => { beforeAll(async () => { const mongoServer = await MongoMemoryServer.create(); @@ -37,8 +41,13 @@ describe("site", () => { await mongoose.disconnect(); await mongoose.connection.close(); }); + + /** + * Sub test suite 1 - POST operation + */ describe("create item route", () => { describe("given the user is not logged in", () => { + /* failure scenario */ it("should return a 403", async () => { const { statusCode } = await supertest(app).post("/api/items"); @@ -46,6 +55,7 @@ describe("site", () => { }); }); describe("given the user is logged in", () => { + /* success scenario */ it("should return a 200 and create the item", async () => { const jwt = signJwt(userPayload); @@ -60,14 +70,20 @@ describe("site", () => { }); }); }); + + /** + * Sub test suite 2 - GET operation (all) + */ describe("get item list route", () => { describe("given the user is not logged in", () => { + /* failure scenario */ it("should return a 403", async () => { const { statusCode } = await supertest(app).get("/api/items"); expect(statusCode).toBe(403); }); }); describe("given the user is logged in", () => { + /* success scenario */ it("should return a 200 and get the item list", async () => { const jwt = signJwt(userPayload); @@ -81,8 +97,13 @@ describe("site", () => { }); }); }); + + /** + * Sub test suite 3 - update site + */ describe("update item route", () => { describe("given the user is not logged in", () => { + /* failure scenario */ it("should return a 403", async () => { const oldItem = await createItem(itemPayload); const { statusCode } = await supertest(app).put( @@ -93,6 +114,7 @@ describe("site", () => { }); }); describe("given the user is logged in", () => { + /* success scenario */ it("should return a 200 and update the item", async () => { const jwt = signJwt(userPayload); diff --git a/backend/src/__tests__/site.test.ts b/backend/src/__tests__/site.test.ts index 7c3e153..4607609 100644 --- a/backend/src/__tests__/site.test.ts +++ b/backend/src/__tests__/site.test.ts @@ -27,6 +27,10 @@ export const userPayload = { contactNumber: "0712345678", }; + +/** + * Main test suite + */ describe("site", () => { beforeAll(async () => { const mongoServer = await MongoMemoryServer.create(); @@ -37,8 +41,14 @@ describe("site", () => { await mongoose.disconnect(); await mongoose.connection.close(); }); + + + /** + * Sub test suite 1 - POST operation + */ describe("create site route", () => { describe("given the user is not logged in", () => { + /* failure scenario */ it("should return a 403", async () => { const { statusCode } = await supertest(app).post("/api/sites"); @@ -47,6 +57,7 @@ describe("site", () => { }); describe("given the user is logged in", () => { + /* success scenario */ it("should return a 200 and create the site", async () => { const jwt = signJwt(userPayload); @@ -62,8 +73,12 @@ describe("site", () => { }); }); + /** + * Sub test suite 2 - GET operation (all) + */ describe("get sites list route", () => { describe("given the user is not logged in", () => { + /* failure scenario */ it("should return a 403", async () => { const { statusCode } = await supertest(app).get("/api/sites"); @@ -72,6 +87,7 @@ describe("site", () => { }); describe("given the user is logged in", () => { + /* success scenario */ it("should return a 200 and the sites", async () => { const jwt = signJwt(userPayload); @@ -92,8 +108,12 @@ describe("site", () => { }); }); + /** + * Sub test suite 3 - GET operation (particular site) + */ describe("get site by id route", () => { describe("given the site does not exist", () => { + /* failure scenario */ it("should return a 404", async () => { const siteId = "site-123"; const jwt = signJwt(userPayload); @@ -106,6 +126,7 @@ describe("site", () => { }); describe("given the site does exist", () => { + /* success scenario */ it("should return a 200 status and the site", async () => { const site = await createSite(sitePayload); const jwt = signJwt(userPayload); @@ -121,8 +142,12 @@ describe("site", () => { }); }); + /** + * Sub test suite 4 - update site + */ describe("update site route", () => { describe("given the user is not logged in", () => { + /* failure scenario */ it("should return a 403", async () => { const site = await createSite(sitePayload); const { statusCode } = await supertest(app).put( @@ -133,6 +158,7 @@ describe("site", () => { }); describe("given the user is logged in", () => { + /* success scenario */ it("should return a 200 and update the site", async () => { const site = await createSite(sitePayload); const jwt = signJwt(userPayload); diff --git a/backend/src/__tests__/user-management.test.ts b/backend/src/__tests__/user-management.test.ts index 1837900..afa4b4d 100644 --- a/backend/src/__tests__/user-management.test.ts +++ b/backend/src/__tests__/user-management.test.ts @@ -28,6 +28,9 @@ const userInput: CreateUserInput["body"] = { contactNumber: "0712345678", }; +/** + * Main test suite + */ describe("user-management", () => { beforeAll(async () => { const mongoServer = await MongoMemoryServer.create(); @@ -38,8 +41,12 @@ describe("user-management", () => { await mongoose.connection.close(); }); + /** + * Sub test suite 1 - POST operation + */ describe("create user route", () => { describe("given the user is not logged in", () => { + /* failure scenario */ it("should return a 403", async () => { const { statusCode } = await supertest(app).post( "/api/user-management" @@ -50,6 +57,7 @@ describe("user-management", () => { }); describe("given the user is logged in", () => { + /* success scenario */ it("should return a 201 and create the user", async () => { const jwt = signJwt(userPayload); @@ -65,8 +73,12 @@ describe("user-management", () => { }); }); + /** + * Sub test suite 2 - GET operation (all) + */ describe("get user list route", () => { describe("given the user is not logged in", () => { + /* failure scenario */ it("should return a 403", async () => { const { statusCode } = await supertest(app).get("/api/user-management"); @@ -75,6 +87,7 @@ describe("user-management", () => { }); describe("given the user is logged in", () => { + /* success scenario */ it("should return a 200 and the users", async () => { const jwt = signJwt(userPayload); @@ -89,8 +102,12 @@ describe("user-management", () => { }); }); + /** + * Sub test suite 4 - update user + */ describe("update user route", () => { describe("given the user is not logged in", () => { + /* failure scenario */ it("should return a 403", async () => { const { statusCode } = await supertest(app).put( `/api/user-management/${userPayload.userId}` @@ -101,6 +118,7 @@ describe("user-management", () => { }); describe("given the user is logged in", () => { + /* success scenario */ it("should return a 200 and update the user", async () => { const jwt = signJwt(userPayload);