-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
961f6df
commit eca6d53
Showing
1 changed file
with
92 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { jest } from "@jest/globals"; | ||
import connector from "#models/databaseUtil"; | ||
import studentModel from "#models/student"; | ||
|
||
jest.mock("#util"); | ||
const { agent } = global; | ||
|
||
function cleanUp(callback) { | ||
studentModel | ||
.remove({ | ||
ERPID: "S1032220999", | ||
name: "Arya", | ||
joiningYear: 2020, | ||
branch: "64fc3c8bde9fa947ea1f412f", | ||
division: "A", | ||
rollNo: 12, | ||
coursesOpted: "64fc3c8bde9fa947ea1f412f", | ||
}) | ||
.then(() => { | ||
connector.disconnect((DBerr) => { | ||
if (DBerr) console.log("Database disconnect error : ", DBerr); | ||
callback(); | ||
}); | ||
}); | ||
} | ||
|
||
|
||
afterAll((done) => { | ||
cleanUp(done); | ||
}); | ||
|
||
describe("Student API", () => { | ||
it("should create student", async () => { | ||
const response = await agent.post("/student/add").send({ | ||
ERPID: "S1032220999", | ||
name: "Arya", | ||
joiningYear: 2020, | ||
branch: "64fc3c8bde9fa947ea1f412f", | ||
division: "A", | ||
rollNo: 12, | ||
coursesOpted: "64fc3c8bde9fa947ea1f412f", | ||
}); | ||
|
||
expect(response.status).toBe(200); | ||
expect(response.body.res).toMatch(/added student/); | ||
}); | ||
|
||
describe("after adding student", () => { | ||
let id; | ||
beforeEach(async () => { | ||
id = await agent.post("/student/add").send({ | ||
ERPID: "S1032220999", | ||
name: "Arya", | ||
joiningYear: 2020, | ||
branch: "64fc3c8bde9fa947ea1f412f", | ||
division: "A", | ||
rollNo: 12, | ||
coursesOpted: "64fc3c8bde9fa947ea1f412f", | ||
}); | ||
id = JSON.parse(id.res.text).id; | ||
}); | ||
|
||
afterEach(async () => { | ||
await studentModel.remove({ | ||
ERPID: "S1032220999", | ||
name: "Arya", | ||
joiningYear: 2020, | ||
branch: "64fc3c8bde9fa947ea1f412f", | ||
division: "A", | ||
rollNo: 12, | ||
coursesOpted: "64fc3c8bde9fa947ea1f412f", | ||
}); | ||
}); | ||
|
||
it("should read student", async () => { | ||
const response = await agent | ||
.get("/student/list") | ||
.send({ name: "Arya" }); | ||
expect(response.status).toBe(200); | ||
expect(response.body.res).toBeDefined(); | ||
}); | ||
|
||
it("should update student", async () => { | ||
const response = await agent | ||
.post(`/student/update/${id}`) | ||
.send({ joiningYear: 2020 }); | ||
|
||
expect(response.status).toBe(200); | ||
expect(response.body.res).toMatch(/updated student/); | ||
}); | ||
}); | ||
}); |