Skip to content

Commit

Permalink
mend
Browse files Browse the repository at this point in the history
  • Loading branch information
ndahimana154 committed May 29, 2024
1 parent 9a8614c commit 77dafc3
Showing 1 changed file with 85 additions and 75 deletions.
160 changes: 85 additions & 75 deletions src/modules/user/test/user.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe("Update User Status test case ", () => {
router()
.post("/api/auth/register")
.send({
email: "niyofo8179@acuxi.com",
email: "nda1234@gmail.com",
password: "userPassword@123"
})
.end((error, response) => {
Expand Down Expand Up @@ -132,79 +132,89 @@ describe("User Repository Functions", () => {



describe("Admin update User roles", () => {

let userIdd: number = null;


it("should register a new user", (done) => {
router()
.post("/api/auth/register")
.send({
email: "[email protected]",
password: "userPassword@123"
})
.end((error, response) => {
expect(response.status).to.equal(httpStatus.CREATED);
expect(response.body).to.be.an("object");
expect(response.body).to.have.property("data");
userIdd = response.body.data.user.id;
expect(response.body).to.have.property("message", "Account created successfully. Please check email to verify account.");
done(error);
});
});

it("Should notify if no role is specified", async () => {

const response = await router()
.put(`/api/users/admin-update-role/${userIdd}`);

expect(response.status).to.equal(httpStatus.BAD_REQUEST);
expect(response.body).to.have.property("message");
});

it("Should notify if the role is other than ['Admin', 'Buyer', 'Seller']", async () => {

const response = await router()
.put(`/api/users/admin-update-role/${userIdd}`)
.send({ role: "Hello" });

expect(response.status).to.equal(httpStatus.BAD_REQUEST);
expect(response.body).to.have.property("message", "The 'role' parameter must be one of ['Admin', 'Buyer', 'Seller'].");
});

it("Should return error when invalid Id is passed", async () => {
const response = await router()
.put("/api/users/admin-update-role/invalid-id")
.send({ role: "Admin" });

expect(response.status).to.equal(httpStatus.INTERNAL_SERVER_ERROR);
expect(response).to.have.property("status", httpStatus.INTERNAL_SERVER_ERROR);
});


it("Should update User and return updated user", (done) => {
router()
.put(`/api/users/admin-update-role/${userIdd}`)
.send({ role: "Admin" })
.end((err, res) => {
expect(res).to.have.status(httpStatus.OK);
expect(res.body).to.be.an("object");
expect(res.body).to.have.property("message", "User role updated successfully");
done(err);
});
});



it("Should return 404 if user is not found", (done) => {
router().put("/api/users/admin-update-role/10001").send({ role: "Admin" }).end((err, res) => {
expect(res).to.have.status(httpStatus.NOT_FOUND);
expect(res.body).to.be.an("object");
expect(res.body).to.have.property("message", "User doesn't exist.")
done(err)
describe("Admin update User roles", () => {

before(async () => {
await Users.destroy({
where: {}
})
})
after(async () => {
await Users.destroy({
where: {}
})
})
let userIdd: number = null;


it("should register a new user", (done) => {
router()
.post("/api/auth/register")
.send({
email: "[email protected]",
password: "userPassword@123"
})
.end((error, response) => {
expect(response.status).to.equal(httpStatus.CREATED);
expect(response.body).to.be.an("object");
expect(response.body).to.have.property("data");
userIdd = response.body.data.user.id;
expect(response.body).to.have.property("message", "Account created successfully. Please check email to verify account.");
done(error);
});
});

it("Should notify if no role is specified", async () => {

const response = await router()
.put(`/api/users/admin-update-role/${userIdd}`);

expect(response.status).to.equal(httpStatus.BAD_REQUEST);
expect(response.body).to.have.property("message");
});

it("Should notify if the role is other than ['Admin', 'Buyer', 'Seller']", async () => {

const response = await router()
.put(`/api/users/admin-update-role/${userIdd}`)
.send({ role: "Hello" });

expect(response.status).to.equal(httpStatus.BAD_REQUEST);
expect(response.body).to.have.property("message", "The 'role' parameter must be one of ['Admin', 'Buyer', 'Seller'].");
});

it("Should return error when invalid Id is passed", async () => {
const response = await router()
.put("/api/users/admin-update-role/invalid-id")
.send({ role: "Admin" });

expect(response.status).to.equal(httpStatus.INTERNAL_SERVER_ERROR);
expect(response).to.have.property("status", httpStatus.INTERNAL_SERVER_ERROR);
});


it("Should update User and return updated user", (done) => {
router()
.put(`/api/users/admin-update-role/${userIdd}`)
.send({ role: "Admin" })
.end((err, res) => {
expect(res).to.have.status(httpStatus.OK);
expect(res.body).to.be.an("object");
expect(res.body).to.have.property("message", "User role updated successfully");
done(err);
});
});



it("Should return 404 if user is not found", (done) => {
router().put("/api/users/admin-update-role/10001").send({ role: "Admin" }).end((err, res) => {
expect(res).to.have.status(httpStatus.NOT_FOUND);
expect(res.body).to.be.an("object");
expect(res.body).to.have.property("message", "User doesn't exist.")
done(err)
})


});
})


});

0 comments on commit 77dafc3

Please sign in to comment.