fix: revert tests
This commit is contained in:
1 parent
dea8c4fdd8
commit
08933743f1
12 files changed
+617
-645
No files matched your search
@@ -43,7 +43,7 @@ const createQueryChain = (finalResult, comparePasswordResult = false) => ({
|
||||
save: sinon.stub().resolves(),
|
||||
});
|
||||
|
||||
describe("recoveryModule", function () {
|
||||
describe("recoveryModule", function() {
|
||||
let deleteManyStub,
|
||||
saveStub,
|
||||
findOneStub,
|
||||
@@ -52,10 +52,9 @@ describe("recoveryModule", function () {
|
||||
userFindOneStub;
|
||||
let req, res;
|
||||
|
||||
beforeEach(function () {
|
||||
beforeEach(function() {
|
||||
req = {
|
||||
body: { email: "test@test.com" },
|
||||
language: 'en',
|
||||
};
|
||||
deleteManyStub = sinon.stub(RecoveryToken, "deleteMany");
|
||||
saveStub = sinon.stub(RecoveryToken.prototype, "save");
|
||||
@@ -65,19 +64,19 @@ describe("recoveryModule", function () {
|
||||
userFindOneStub = sinon.stub().resolves();
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
afterEach(function() {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
describe("requestRecoveryToken", function () {
|
||||
it("should return a recovery token", async function () {
|
||||
describe("requestRecoveryToken", function() {
|
||||
it("should return a recovery token", async function() {
|
||||
deleteManyStub.resolves();
|
||||
saveStub.resolves(mockRecoveryToken);
|
||||
const result = await requestRecoveryToken(req, res);
|
||||
expect(result.email).to.equal(mockRecoveryToken.email);
|
||||
});
|
||||
|
||||
it("should handle an error", async function () {
|
||||
it("should handle an error", async function() {
|
||||
const err = new Error("Test error");
|
||||
deleteManyStub.rejects(err);
|
||||
try {
|
||||
@@ -89,24 +88,24 @@ describe("recoveryModule", function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe("validateRecoveryToken", function () {
|
||||
it("should return a recovery token if found", async function () {
|
||||
describe("validateRecoveryToken", function() {
|
||||
it("should return a recovery token if found", async function() {
|
||||
findOneStub.resolves(mockRecoveryToken);
|
||||
const result = await validateRecoveryToken(req, res);
|
||||
expect(result).to.deep.equal(mockRecoveryToken);
|
||||
});
|
||||
|
||||
it("should thrown an error if a token is not found", async function () {
|
||||
it("should thrown an error if a token is not found", async function() {
|
||||
findOneStub.resolves(null);
|
||||
try {
|
||||
await validateRecoveryToken(req, res);
|
||||
} catch (error) {
|
||||
expect(error).to.exist;
|
||||
expect(error.message).to.equal(errorMessages.DB_TOKEN_NOT_FOUND(req.language));
|
||||
expect(error.message).to.equal(errorMessages.DB_TOKEN_NOT_FOUND);
|
||||
}
|
||||
});
|
||||
|
||||
it("should handle DB errors", async function () {
|
||||
it("should handle DB errors", async function() {
|
||||
const err = new Error("Test error");
|
||||
findOneStub.rejects(err);
|
||||
try {
|
||||
@@ -118,41 +117,40 @@ describe("recoveryModule", function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe("resetPassword", function () {
|
||||
beforeEach(function () {
|
||||
describe("resetPassword", function() {
|
||||
beforeEach(function() {
|
||||
req.body = {
|
||||
password: "test",
|
||||
newPassword: "test1",
|
||||
};
|
||||
req.language = 'en';
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
afterEach(function() {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
it("should thrown an error if a recovery token is not found", async function () {
|
||||
it("should thrown an error if a recovery token is not found", async function() {
|
||||
findOneStub.resolves(null);
|
||||
try {
|
||||
await resetPassword(req, res);
|
||||
} catch (error) {
|
||||
expect(error).to.exist;
|
||||
expect(error.message).to.equal(errorMessages.DB_TOKEN_NOT_FOUND(req.language));
|
||||
expect(error.message).to.equal(errorMessages.DB_TOKEN_NOT_FOUND);
|
||||
}
|
||||
});
|
||||
|
||||
it("should throw an error if a user is not found", async function () {
|
||||
it("should throw an error if a user is not found", async function() {
|
||||
findOneStub.resolves(mockRecoveryToken);
|
||||
userFindOneStub = sinon.stub(User, "findOne").resolves(null);
|
||||
try {
|
||||
await resetPassword(req, res);
|
||||
} catch (error) {
|
||||
expect(error).to.exist;
|
||||
expect(error.message).to.equal(errorMessages.DB_USER_NOT_FOUND(req.language));
|
||||
expect(error.message).to.equal(errorMessages.DB_USER_NOT_FOUND);
|
||||
}
|
||||
});
|
||||
|
||||
it("should throw an error if the passwords match", async function () {
|
||||
it("should throw an error if the passwords match", async function() {
|
||||
findOneStub.resolves(mockRecoveryToken);
|
||||
saveStub.resolves();
|
||||
userFindOneStub = sinon
|
||||
@@ -162,11 +160,11 @@ describe("recoveryModule", function () {
|
||||
await resetPassword(req, res);
|
||||
} catch (error) {
|
||||
expect(error).to.exist;
|
||||
expect(error.message).to.equal(errorMessages.DB_RESET_PASSWORD_BAD_MATCH(req.language));
|
||||
expect(error.message).to.equal(errorMessages.DB_RESET_PASSWORD_BAD_MATCH);
|
||||
}
|
||||
});
|
||||
|
||||
it("should return a user without password if successful", async function () {
|
||||
it("should return a user without password if successful", async function() {
|
||||
findOneStub.resolves(mockRecoveryToken);
|
||||
saveStub.resolves();
|
||||
userFindOneStub = sinon
|
||||
|
||||
Reference in new issue
Block a user