Add checkSuperadminExists test
This commit is contained in:
1 parent
5d9b1dd6ef
commit
b24208f73e
1 file changed
+42
@@ -2,6 +2,7 @@ const {
|
|||||||
registerUser,
|
registerUser,
|
||||||
loginUser,
|
loginUser,
|
||||||
editUser,
|
editUser,
|
||||||
|
checkSuperadminExists,
|
||||||
} = require("../../controllers/authController");
|
} = require("../../controllers/authController");
|
||||||
const jwt = require("jsonwebtoken");
|
const jwt = require("jsonwebtoken");
|
||||||
|
|
||||||
@@ -215,3 +216,44 @@ describe("Auth Controller - editUser", async () => {
|
|||||||
expect(next.firstCall.args[0].status).to.equal(422);
|
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;
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in new issue
Block a user