-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
➡️ merge pull request #22 from devsoc-unsw/feature/login
🧪wrote more tests for the login function and added test.env variables
- Loading branch information
Showing
3 changed files
with
72 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,27 +45,58 @@ describe("Tests", () => { | |
|
||
test("Unauthorized User", async () => { | ||
const { status, body } = await request(app).post("/auth/register").send({ | ||
username: "shinjisatoo", | ||
password: "testpassword", | ||
email: "[email protected]", | ||
userType: "ATTENDEE", | ||
}); | ||
const users = await prisma.user.findMany({}) | ||
console.log(users) | ||
const newUser = await prisma.user.findFirst({ | ||
where: { | ||
id: body.newUser.id, | ||
}, | ||
username: "shinjisatoo", | ||
password: "testpassword", | ||
email: "[email protected]", | ||
userType: "ATTENDEE", | ||
}); | ||
|
||
const newUser = await prisma.user.findFirst({ | ||
where: { | ||
id: body.newUser.id, | ||
}, | ||
}); | ||
if (newUser == null) return; | ||
expect(status).toBe(201); | ||
expect(newUser).not.toBeNull(); | ||
|
||
const response2 = await request(app) | ||
.get("/user") | ||
.send({ | ||
userId: newUser.id, | ||
}); | ||
if (newUser == null) return; | ||
expect(status).toBe(201); | ||
expect(newUser).not.toBeNull(); | ||
|
||
const response2 = await request(app) | ||
.get("/user") | ||
.send({ | ||
userId: newUser.id, | ||
}); | ||
expect(response2.status).toBe(401); | ||
expect(response2.status).toBe(401); | ||
}) | ||
|
||
test("Wrong password", async () => { | ||
const { status, body } = await request(app).post("/auth/register").send({ | ||
username: "shinjisatoo", | ||
password: "testpassword", | ||
email: "[email protected]", | ||
userType: "ATTENDEE", | ||
}); | ||
|
||
const response = await request(app).post("/auth/login").send({ | ||
username: body.newUser.username, | ||
password: "wrongpassword", | ||
}); | ||
|
||
expect(response.status).toBe(400); | ||
}) | ||
|
||
test("Nonexistent Username", async () => { | ||
const { status, body } = await request(app).post("/auth/register").send({ | ||
username: "shinjisatoo", | ||
password: "testpassword", | ||
email: "[email protected]", | ||
userType: "ATTENDEE", | ||
}); | ||
|
||
const response = await request(app).post("/auth/login").send({ | ||
username: "Idon'texistlol", | ||
password: "testpassword", | ||
}); | ||
|
||
expect(response.status).toBe(400); | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,4 +53,22 @@ describe("Tests", () => { | |
|
||
expect(status).toBe(400); | ||
}) | ||
|
||
test("Username already exists", async () => { | ||
await request(app).post("/auth/register").send({ | ||
username: "shinjisatoo", | ||
password: "testpassword", | ||
email: "[email protected]", | ||
userType: "ATTENDEE", | ||
}); | ||
|
||
const { status, body } = await request(app).post("/auth/register").send({ | ||
username: "shinjisatoo", | ||
password: "testpassword2", | ||
email: "[email protected]", | ||
userType: "ATTENDEE", | ||
}); | ||
|
||
expect(status).toBe(400); | ||
}) | ||
}); |