Skip to content

Commit

Permalink
feat(logout): implement logout functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
GarrixA committed Apr 25, 2024
1 parent d170901 commit 5a162d6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
14 changes: 6 additions & 8 deletions src/__test__/users.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,30 +101,28 @@ describe("USER API TEST", () => {
* -----------------------------------------LOG OUT--------------------------------------
*/
it("Should log out a user and return 404", async () => {
const { body } = await Jest_request.post("/api/v1/users/logout")
.send()
const { body } = await Jest_request.post("/api/v1/users/logout").send();
expect(404);
expect(body.status).toStrictEqual("NOT FOUND");
expect(body.message).toStrictEqual("Token Not Found");
});

it("Should log out a user and return 201", async () => {
const { body } = await Jest_request.post("/api/v1/users/logout")
.send()
.set("Authorization", `Bearer ${token}`);
.send()
.set("Authorization", `Bearer ${token}`);
expect(201);
expect(body.status).toStrictEqual("CREATED");
expect(body.message).toStrictEqual("Logged out successfully");
token = token;
});

it("Should alert an error and return 401", async () => {
const { body } = await Jest_request.post("/api/v1/users/logout")
.send()
.set("Authorization", `Bearer ${token}`);
.set("Authorization", `Bearer ${token}`);
expect(401);
expect(body.status).toStrictEqual("UNAUTHORIZED");
expect(body.message).toStrictEqual("Already logged out");
});

});
2 changes: 1 addition & 1 deletion src/controllers/logoutController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const logout = async (req: Request, res: Response) => {
}

const blacklistedToken = await Blacklist.findOne({ where: { token } });

if (!blacklistedToken) {
await Blacklist.create({ id: uuidv4(), token: token });
return res
Expand Down

0 comments on commit 5a162d6

Please sign in to comment.