fix: revert tests

This commit is contained in:
cihatata authored and cihat committed 2025-02-11 07:43:39 +03:00
1 parent dea8c4fdd8
commit 08933743f1
12 files changed
+617 -645

No files matched your search

+36 -38
View File
@@ -27,9 +27,7 @@ const imageFile = {
image: 1,
};
const mockLanguage = 'en';
describe("userModule", function () {
describe("userModule", function() {
let teamSaveStub,
teamFindByIdAndDeleteStub,
userSaveStub,
@@ -42,7 +40,7 @@ describe("userModule", function () {
generateAvatarImageStub,
parseBooleanStub;
beforeEach(function () {
beforeEach(function() {
teamSaveStub = sinon.stub(TeamModel.prototype, "save");
teamFindByIdAndDeleteStub = sinon.stub(TeamModel, "findByIdAndDelete");
userSaveStub = sinon.stub(UserModel.prototype, "save");
@@ -56,12 +54,12 @@ describe("userModule", function () {
parseBooleanStub = sinon.stub().returns(true);
});
afterEach(function () {
afterEach(function() {
sinon.restore();
});
describe("insertUser", function () {
it("should insert a regular user", async function () {
describe("insertUser", function() {
it("should insert a regular user", async function() {
userSaveStub.resolves(mockUser);
userFindOneStub.returns({
select: sinon.stub().returns({
@@ -72,7 +70,7 @@ describe("userModule", function () {
expect(result).to.deep.equal(mockUser);
});
it("should insert a superadmin user", async function () {
it("should insert a superadmin user", async function() {
userSaveStub.resolves(mockSuperUser);
userFindOneStub.returns({
select: sinon.stub().returns({
@@ -83,7 +81,7 @@ describe("userModule", function () {
expect(result).to.deep.equal(mockSuperUser);
});
it("should handle an error", async function () {
it("should handle an error", async function() {
const err = new Error("test error");
userSaveStub.rejects(err);
try {
@@ -94,7 +92,7 @@ describe("userModule", function () {
}
});
it("should handle a duplicate key error", async function () {
it("should handle a duplicate key error", async function() {
const err = new Error("test error");
err.code = 11000;
userSaveStub.rejects(err);
@@ -107,8 +105,8 @@ describe("userModule", function () {
});
});
describe("getUserByEmail", function () {
it("should return a user", async function () {
describe("getUserByEmail", function() {
it("should return a user", async function() {
userFindOneStub.returns({
select: sinon.stub().resolves(mockUser),
});
@@ -117,23 +115,23 @@ describe("userModule", function () {
});
});
describe("getUserByEmail", function () {
it("throw an error if a user is not found", async function () {
describe("getUserByEmail", function() {
it("throw an error if a user is not found", async function() {
userFindOneStub.returns({
select: sinon.stub().resolves(null),
});
try {
await getUserByEmail(mockUser.email);
} catch (error) {
expect(error.message).to.equal(errorMessages.DB_USER_NOT_FOUND(mockLanguage));
expect(error.message).to.equal(errorMessages.DB_USER_NOT_FOUND);
}
});
});
describe("updateUser", function () {
describe("updateUser", function() {
let req, res;
beforeEach(function () {
beforeEach(function() {
req = {
params: {
userId: "testId",
@@ -150,9 +148,9 @@ describe("userModule", function () {
res = {};
});
afterEach(function () { });
afterEach(function() {});
it("should update a user", async function () {
it("should update a user", async function() {
parseBooleanStub.returns(false);
userFindByIdAndUpdateStub.returns({
select: sinon.stub().returns({
@@ -168,7 +166,7 @@ describe("userModule", function () {
expect(result).to.deep.equal(mockUser);
});
it("should delete a user profile image", async function () {
it("should delete a user profile image", async function() {
req.body.deleteProfileImage = "true";
userFindByIdAndUpdateStub.returns({
select: sinon.stub().returns({
@@ -184,7 +182,7 @@ describe("userModule", function () {
expect(result).to.deep.equal(mockUser);
});
it("should handle an error", async function () {
it("should handle an error", async function() {
const err = new Error("test error");
userFindByIdAndUpdateStub.throws(err);
try {
@@ -196,23 +194,23 @@ describe("userModule", function () {
});
});
describe("deleteUser", function () {
it("should return a deleted user", async function () {
describe("deleteUser", function() {
it("should return a deleted user", async function() {
userFindByIdAndDeleteStub.resolves(mockUser);
const result = await deleteUser("testId");
expect(result).to.deep.equal(mockUser);
});
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() {
try {
await deleteUser("testId");
} catch (error) {
expect(error).to.exist;
expect(error.message).to.equal(errorMessages.DB_USER_NOT_FOUND(mockLanguage));
expect(error.message).to.equal(errorMessages.DB_USER_NOT_FOUND);
}
});
it("should handle an error", async function () {
it("should handle an error", async function() {
const err = new Error("test error");
userFindByIdAndDeleteStub.throws(err);
try {
@@ -224,14 +222,14 @@ describe("userModule", function () {
});
});
describe("deleteTeam", function () {
it("should return true if team deleted", async function () {
describe("deleteTeam", function() {
it("should return true if team deleted", async function() {
teamFindByIdAndDeleteStub.resolves();
const result = await deleteTeam("testId");
expect(result).to.equal(true);
});
it("should handle an error", async function () {
it("should handle an error", async function() {
const err = new Error("test error");
teamFindByIdAndDeleteStub.throws(err);
try {
@@ -243,14 +241,14 @@ describe("userModule", function () {
});
});
describe("deleteAllOtherUsers", function () {
it("should return true if all other users deleted", async function () {
describe("deleteAllOtherUsers", function() {
it("should return true if all other users deleted", async function() {
userDeleteManyStub.resolves(true);
const result = await deleteAllOtherUsers();
expect(result).to.equal(true);
});
it("should handle an error", async function () {
it("should handle an error", async function() {
const err = new Error("test error");
userDeleteManyStub.throws(err);
try {
@@ -262,8 +260,8 @@ describe("userModule", function () {
});
});
describe("getAllUsers", function () {
it("should return all users", async function () {
describe("getAllUsers", function() {
it("should return all users", async function() {
userFindStub.returns({
select: sinon.stub().returns({
select: sinon.stub().resolves([mockUser]),
@@ -273,7 +271,7 @@ describe("userModule", function () {
expect(result).to.deep.equal([mockUser]);
});
it("should handle an error", async function () {
it("should handle an error", async function() {
const err = new Error("test error");
userFindStub.throws(err);
try {
@@ -285,14 +283,14 @@ describe("userModule", function () {
});
});
describe("logoutUser", function () {
it("should return true if user logged out", async function () {
describe("logoutUser", function() {
it("should return true if user logged out", async function() {
userUpdateOneStub.resolves(true);
const result = await logoutUser("testId");
expect(result).to.equal(true);
});
it("should handle an error", async function () {
it("should handle an error", async function() {
const err = new Error("test error");
userUpdateOneStub.throws(err);
try {