Skip to content

Commit

Permalink
test: fix same user duplicate key error
Browse files Browse the repository at this point in the history
  • Loading branch information
belphegor-s committed Oct 23, 2023
1 parent 0188c81 commit be88136
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import request from "supertest";
import app from "../src/index";

const randomGen = () => Math.random().toString(36).substring(2, 10);

describe("Auth API Tests", () => {
let authToken = "";
let testUserId = "";
const user = {
username: randomGen(),
password: randomGen(),
};

// Test user registration
it("registers a user", (done: jest.DoneCallback) => {
request(app)
.post("/api/v1/register")
.send({ username: "testuser", password: "testpassword" })
.send({ usernam: user.username, password: user.password })
.expect(200)
.expect((res) => {
expect(res.body.msg).toBe("Successfully registered User");
Expand All @@ -22,7 +28,7 @@ describe("Auth API Tests", () => {
it("logs in a user and generates a JWT", (done) => {
request(app)
.post("/api/v1/login")
.send({ username: "testuser", password: "testpassword" })
.send({ username: user.username, password: user.password })
.expect(200)
.expect((res) => {
expect(res.body.data.token).toBeDefined();
Expand Down

0 comments on commit be88136

Please sign in to comment.