fix(test): Use 'npm run lint-fix' to fix 'mocha/no-mocha-arrows' like lint warnings
- ref: https://mochajs.org/#arrow-functions
This commit is contained in:
1 parent
319e6d6017
commit
fcda60fe5b
31 files changed
+1268
-907
No files matched your search
@@ -27,7 +27,7 @@ const imageFile = {
|
||||
image: 1,
|
||||
};
|
||||
|
||||
describe("userModule", () => {
|
||||
describe("userModule", function() {
|
||||
let teamSaveStub,
|
||||
teamFindByIdAndDeleteStub,
|
||||
userSaveStub,
|
||||
@@ -39,7 +39,8 @@ describe("userModule", () => {
|
||||
userUpdateOneStub,
|
||||
generateAvatarImageStub,
|
||||
parseBooleanStub;
|
||||
beforeEach(() => {
|
||||
|
||||
beforeEach(function() {
|
||||
teamSaveStub = sinon.stub(TeamModel.prototype, "save");
|
||||
teamFindByIdAndDeleteStub = sinon.stub(TeamModel, "findByIdAndDelete");
|
||||
userSaveStub = sinon.stub(UserModel.prototype, "save");
|
||||
@@ -53,12 +54,12 @@ describe("userModule", () => {
|
||||
parseBooleanStub = sinon.stub().returns(true);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
afterEach(function() {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
describe("insertUser", () => {
|
||||
it("should insert a regular user", async () => {
|
||||
describe("insertUser", function() {
|
||||
it("should insert a regular user", async function() {
|
||||
userSaveStub.resolves(mockUser);
|
||||
userFindOneStub.returns({
|
||||
select: sinon.stub().returns({
|
||||
@@ -68,7 +69,8 @@ describe("userModule", () => {
|
||||
const result = await insertUser(mockUser, imageFile, generateAvatarImageStub);
|
||||
expect(result).to.deep.equal(mockUser);
|
||||
});
|
||||
it("should insert a superadmin user", async () => {
|
||||
|
||||
it("should insert a superadmin user", async function() {
|
||||
userSaveStub.resolves(mockSuperUser);
|
||||
userFindOneStub.returns({
|
||||
select: sinon.stub().returns({
|
||||
@@ -78,7 +80,8 @@ describe("userModule", () => {
|
||||
const result = await insertUser(mockSuperUser, imageFile, generateAvatarImageStub);
|
||||
expect(result).to.deep.equal(mockSuperUser);
|
||||
});
|
||||
it("should handle an error", async () => {
|
||||
|
||||
it("should handle an error", async function() {
|
||||
const err = new Error("test error");
|
||||
userSaveStub.rejects(err);
|
||||
try {
|
||||
@@ -88,7 +91,8 @@ describe("userModule", () => {
|
||||
expect(error).to.deep.equal(err);
|
||||
}
|
||||
});
|
||||
it("should handle a duplicate key error", async () => {
|
||||
|
||||
it("should handle a duplicate key error", async function() {
|
||||
const err = new Error("test error");
|
||||
err.code = 11000;
|
||||
userSaveStub.rejects(err);
|
||||
@@ -100,8 +104,9 @@ describe("userModule", () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
describe("getUserByEmail", () => {
|
||||
it("should return a user", async () => {
|
||||
|
||||
describe("getUserByEmail", function() {
|
||||
it("should return a user", async function() {
|
||||
userFindOneStub.returns({
|
||||
select: sinon.stub().resolves(mockUser),
|
||||
});
|
||||
@@ -109,8 +114,9 @@ describe("userModule", () => {
|
||||
expect(result).to.deep.equal(mockUser);
|
||||
});
|
||||
});
|
||||
describe("getUserByEmail", () => {
|
||||
it("throw an error if a user is not found", async () => {
|
||||
|
||||
describe("getUserByEmail", function() {
|
||||
it("throw an error if a user is not found", async function() {
|
||||
userFindOneStub.returns({
|
||||
select: sinon.stub().resolves(null),
|
||||
});
|
||||
@@ -121,9 +127,11 @@ describe("userModule", () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
describe("updateUser", () => {
|
||||
|
||||
describe("updateUser", function() {
|
||||
let req, res;
|
||||
beforeEach(() => {
|
||||
|
||||
beforeEach(function() {
|
||||
req = {
|
||||
params: {
|
||||
userId: "testId",
|
||||
@@ -140,8 +148,9 @@ describe("userModule", () => {
|
||||
res = {};
|
||||
});
|
||||
|
||||
afterEach(() => {});
|
||||
it("should update a user", async () => {
|
||||
afterEach(function() {});
|
||||
|
||||
it("should update a user", async function() {
|
||||
parseBooleanStub.returns(false);
|
||||
userFindByIdAndUpdateStub.returns({
|
||||
select: sinon.stub().returns({
|
||||
@@ -156,7 +165,8 @@ describe("userModule", () => {
|
||||
);
|
||||
expect(result).to.deep.equal(mockUser);
|
||||
});
|
||||
it("should delete a user profile image", async () => {
|
||||
|
||||
it("should delete a user profile image", async function() {
|
||||
req.body.deleteProfileImage = "true";
|
||||
userFindByIdAndUpdateStub.returns({
|
||||
select: sinon.stub().returns({
|
||||
@@ -171,7 +181,8 @@ describe("userModule", () => {
|
||||
);
|
||||
expect(result).to.deep.equal(mockUser);
|
||||
});
|
||||
it("should handle an error", async () => {
|
||||
|
||||
it("should handle an error", async function() {
|
||||
const err = new Error("test error");
|
||||
userFindByIdAndUpdateStub.throws(err);
|
||||
try {
|
||||
@@ -182,13 +193,15 @@ describe("userModule", () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
describe("deleteUser", async () => {
|
||||
it("should return a deleted user", async () => {
|
||||
|
||||
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 () => {
|
||||
|
||||
it("should throw an error if a user is not found", async function() {
|
||||
try {
|
||||
await deleteUser("testId");
|
||||
} catch (error) {
|
||||
@@ -196,7 +209,8 @@ describe("userModule", () => {
|
||||
expect(error.message).to.equal(errorMessages.DB_USER_NOT_FOUND);
|
||||
}
|
||||
});
|
||||
it("should handle an error", async () => {
|
||||
|
||||
it("should handle an error", async function() {
|
||||
const err = new Error("test error");
|
||||
userFindByIdAndDeleteStub.throws(err);
|
||||
try {
|
||||
@@ -208,13 +222,14 @@ describe("userModule", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("deleteTeam", () => {
|
||||
it("should return true if team deleted", async () => {
|
||||
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 () => {
|
||||
|
||||
it("should handle an error", async function() {
|
||||
const err = new Error("test error");
|
||||
teamFindByIdAndDeleteStub.throws(err);
|
||||
try {
|
||||
@@ -226,13 +241,14 @@ describe("userModule", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("deleteAllOtherUsers", () => {
|
||||
it("should return true if all other users deleted", async () => {
|
||||
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 () => {
|
||||
|
||||
it("should handle an error", async function() {
|
||||
const err = new Error("test error");
|
||||
userDeleteManyStub.throws(err);
|
||||
try {
|
||||
@@ -244,8 +260,8 @@ describe("userModule", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("getAllUsers", () => {
|
||||
it("should return all users", async () => {
|
||||
describe("getAllUsers", function() {
|
||||
it("should return all users", async function() {
|
||||
userFindStub.returns({
|
||||
select: sinon.stub().returns({
|
||||
select: sinon.stub().resolves([mockUser]),
|
||||
@@ -254,7 +270,8 @@ describe("userModule", () => {
|
||||
const result = await getAllUsers();
|
||||
expect(result).to.deep.equal([mockUser]);
|
||||
});
|
||||
it("should handle an error", async () => {
|
||||
|
||||
it("should handle an error", async function() {
|
||||
const err = new Error("test error");
|
||||
userFindStub.throws(err);
|
||||
try {
|
||||
@@ -266,13 +283,14 @@ describe("userModule", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("logoutUser", async () => {
|
||||
it("should return true if user logged out", async () => {
|
||||
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 () => {
|
||||
|
||||
it("should handle an error", async function() {
|
||||
const err = new Error("test error");
|
||||
userUpdateOneStub.throws(err);
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user