-
Notifications
You must be signed in to change notification settings - Fork 1
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 #27 from Code-Hammers/db-container
Db container testing moved to a containered test DB. testing workflow added to Github for automated testing on PR's to the dev branch.
- Loading branch information
Showing
8 changed files
with
3,070 additions
and
173 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
node_modules | ||
node_modules/ | ||
npm-debug.log |
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
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 |
---|---|---|
|
@@ -21,49 +21,61 @@ afterAll(async () => { | |
}); | ||
|
||
describe("User Routes", () => { | ||
describe("POST /api/users/login", () => { | ||
it("should login a user", async () => { | ||
const mockUserData = { | ||
email: "[email protected]", | ||
password: "123456", | ||
describe("POST /api/users/register", () => { | ||
it("should register a user", async () => { | ||
const mockNewUserData = { | ||
name: "John Doe", | ||
email: "[email protected]", | ||
password: "testpassword", | ||
}; | ||
|
||
const res = await request(app) | ||
.post("/api/users/login") | ||
.send(mockUserData); | ||
.post("/api/users/register") | ||
.send(mockNewUserData); | ||
|
||
expect(res.statusCode).toEqual(200); | ||
expect(res.statusCode).toEqual(201); | ||
expect(res.body).toHaveProperty("email"); | ||
}); | ||
}); | ||
|
||
describe("POST /api/users/register", () => { | ||
it("should register a user", async () => { | ||
const mockNewUserData = { | ||
name: "John Doe", | ||
describe("POST /api/users/login", () => { | ||
it("should login a user", async () => { | ||
const mockUserData = { | ||
email: "[email protected]", | ||
password: "testpassword", | ||
}; | ||
|
||
const res = await request(app) | ||
.post("/api/users/register") | ||
.send(mockNewUserData); | ||
.post("/api/users/login") | ||
.send(mockUserData); | ||
|
||
expect(res.statusCode).toEqual(201); | ||
expect(res.statusCode).toEqual(200); | ||
expect(res.body).toHaveProperty("email"); | ||
}); | ||
}); | ||
|
||
describe("GET /api/users/:id", () => { | ||
it("should get a specific user", async () => { | ||
const userId = "64e0c6963707b139178a6c46"; | ||
const expectedEmail = "[email protected]"; | ||
// Create a user first | ||
const newUser = { | ||
name: "Test User", | ||
email: "[email protected]", | ||
password: "password123", | ||
}; | ||
let createUserResponse = await request(app) | ||
.post("/api/users/register") | ||
.send(newUser); | ||
|
||
const userId = createUserResponse.body._id; | ||
|
||
// Now get the created user by ID | ||
const res = await request(app).get(`/api/users/${userId}`); | ||
|
||
expect(res.statusCode).toEqual(200); | ||
expect(res.body).toHaveProperty("email"); | ||
expect(res.body.email).toEqual(expectedEmail); | ||
expect(res.body.email).toEqual(newUser.email); | ||
|
||
await request(app).delete(`/api/users/${newUser.email}`); | ||
}); | ||
}); | ||
|
||
|
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
Oops, something went wrong.