Add checkSuperadminExists test

This commit is contained in:
Alex Holliday
2024-10-10 18:56:32 +08:00
parent 5d9b1dd6ef
commit b24208f73e

View File

@@ -2,6 +2,7 @@ const {
registerUser,
loginUser,
editUser,
checkSuperadminExists,
} = require("../../controllers/authController");
const jwt = require("jsonwebtoken");
@@ -215,3 +216,44 @@ describe("Auth Controller - editUser", async () => {
expect(next.firstCall.args[0].status).to.equal(422);
});
});
describe("Auth Controller - checkSuperadminExists", async () => {
beforeEach(() => {
req = {
db: {
checkSuperadmin: sinon.stub(),
},
};
res = {
status: sinon.stub().returnsThis(),
json: sinon.stub(),
};
next = sinon.stub();
});
it("should return true if a superadmin exists", async () => {
req.db.checkSuperadmin.resolves(true);
await checkSuperadminExists(req, res, next);
expect(res.status.calledWith(200)).to.be.true;
expect(
res.json.calledWith({
success: true,
msg: successMessages.AUTH_SUPERADMIN_EXISTS,
data: true,
})
).to.be.true;
});
it("should return false if a superadmin does not exist", async () => {
req.db.checkSuperadmin.resolves(false);
await checkSuperadminExists(req, res, next);
expect(res.status.calledWith(200)).to.be.true;
expect(
res.json.calledWith({
success: true,
msg: successMessages.AUTH_SUPERADMIN_EXISTS,
data: false,
})
).to.be.true;
});
});