From dc3afb073f222d01bafb965ea1448fe7aef2cb64 Mon Sep 17 00:00:00 2001 From: am-ons <171134774+am-ons@users.noreply.github.com> Date: Thu, 20 Jun 2024 16:11:20 +0100 Subject: [PATCH] feat: Add all tests to cover the code in /api/users GET endpoint --- server/tests/index.test.ts | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/server/tests/index.test.ts b/server/tests/index.test.ts index 6e774cb..18a7348 100644 --- a/server/tests/index.test.ts +++ b/server/tests/index.test.ts @@ -146,12 +146,25 @@ describe("Test /api/users DELETE endpoint", () => { }); }); -/* -beforeEach(() => { - blaiseApiMock.reset(); -}); +describe("Test /api/users GET endpoint", () => { + it("should call Blaise API getUsers endpoint AND return http status OK_200", async () => { + const newUser1 : NewUser = { + name: "name1", + password: "password1", + role: "role1", + serverParks: ["sp1", "sp2"], + defaultServerPark: "sp1" + }; + const newUser2 = newUser1; + newUser2.name = "name2"; + const newUser3 = newUser2; + newUser3.name = "name3"; + const userArray : NewUser [] = [newUser1, newUser2, newUser3]; + blaiseApiMock.setup((api) => api.getUsers()).returns(_ => Promise.resolve(userArray)); -afterAll(() => { - blaiseApiMock.reset(); + const response = await sut.get("/api/users"); + + expect(response.statusCode).toEqual(200); + blaiseApiMock.verify(a => a.getUsers(), Times.once()); + }); }); -*/