Skip to content

Commit

Permalink
comments added to item user site
Browse files Browse the repository at this point in the history
  • Loading branch information
IT20611088 committed Oct 29, 2023
1 parent abebd7a commit 008ad0c
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
22 changes: 22 additions & 0 deletions backend/src/__tests__/item.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export const userPayload = {
contactNumber: "0712345678",
};


/**
* Main test suite
*/
describe("site", () => {
beforeAll(async () => {
const mongoServer = await MongoMemoryServer.create();
Expand All @@ -37,15 +41,21 @@ 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");

expect(statusCode).toBe(403);
});
});
describe("given the user is logged in", () => {
/* success scenario */
it("should return a 200 and create the item", async () => {
const jwt = signJwt(userPayload);

Expand All @@ -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);

Expand All @@ -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(
Expand All @@ -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);

Expand Down
26 changes: 26 additions & 0 deletions backend/src/__tests__/site.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export const userPayload = {
contactNumber: "0712345678",
};


/**
* Main test suite
*/
describe("site", () => {
beforeAll(async () => {
const mongoServer = await MongoMemoryServer.create();
Expand All @@ -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");

Expand All @@ -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);

Expand All @@ -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");

Expand All @@ -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);

Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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(
Expand All @@ -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);
Expand Down
18 changes: 18 additions & 0 deletions backend/src/__tests__/user-management.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ const userInput: CreateUserInput["body"] = {
contactNumber: "0712345678",
};

/**
* Main test suite
*/
describe("user-management", () => {
beforeAll(async () => {
const mongoServer = await MongoMemoryServer.create();
Expand All @@ -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"
Expand All @@ -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);

Expand All @@ -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");

Expand All @@ -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);

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

Expand Down

0 comments on commit 008ad0c

Please sign in to comment.