-
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 branch 'admin-update-role-187584923' of https://github.com/atlp…
…-rwanda/e-commerce-ninjas-bn into admin-update-role-187584923
- Loading branch information
Showing
1 changed file
with
74 additions
and
79 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 |
---|---|---|
|
@@ -132,84 +132,79 @@ describe("User Repository Functions", () => { | |
|
||
|
||
|
||
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); | ||
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 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) | ||
expect(res.body).to.have.property("message", "User doesn't exist.") | ||
done(err) | ||
}) | ||
}) | ||
}) | ||
|
||
|
||
}); | ||
|
||
|
||
}); |