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

+16 -17
View File
@@ -7,33 +7,32 @@ import {
} from "../../db/mongo/modules/inviteModule.js";
import { errorMessages } from "../../utils/messages.js";
describe("Invite Module", function () {
describe("Invite Module", function() {
const mockUserData = {
email: "test@test.com",
teamId: "123",
role: ["admin"],
token: "123",
};
const mockLanguage = 'en';
const mockInviteToken = { _id: 123, time: 123 };
let inviteTokenDeleteManyStub,
inviteTokenSaveStub,
inviteTokenFindOneStub,
inviteTokenFindOneAndDeleteStub;
beforeEach(function () {
beforeEach(function() {
inviteTokenDeleteManyStub = sinon.stub(InviteToken, "deleteMany");
inviteTokenSaveStub = sinon.stub(InviteToken.prototype, "save");
inviteTokenFindOneStub = sinon.stub(InviteToken, "findOne");
inviteTokenFindOneAndDeleteStub = sinon.stub(InviteToken, "findOneAndDelete");
});
afterEach(function () {
afterEach(function() {
sinon.restore();
});
describe("requestInviteToken", function () {
it("should return a new invite token", async function () {
describe("requestInviteToken", function() {
it("should return a new invite token", async function() {
inviteTokenDeleteManyStub.resolves();
inviteTokenSaveStub.resolves();
const inviteToken = await requestInviteToken(mockUserData);
@@ -42,7 +41,7 @@ describe("Invite Module", function () {
expect(inviteToken.token).to.exist;
});
it("should handle an error", async function () {
it("should handle an error", async function() {
const err = new Error("test error");
inviteTokenDeleteManyStub.rejects(err);
try {
@@ -53,23 +52,23 @@ describe("Invite Module", function () {
});
});
describe("getInviteToken", function () {
it("should return an invite token", async function () {
describe("getInviteToken", function() {
it("should return an invite token", async function() {
inviteTokenFindOneStub.resolves(mockInviteToken);
const inviteToken = await getInviteToken(mockUserData.token);
expect(inviteToken).to.deep.equal(mockInviteToken);
});
it("should handle a token not found", async function () {
it("should handle a token not found", async function() {
inviteTokenFindOneStub.resolves(null);
try {
await getInviteToken(mockUserData.token);
} catch (error) {
expect(error.message).to.equal(errorMessages.AUTH_INVITE_NOT_FOUND(mockLanguage));
expect(error.message).to.equal(errorMessages.AUTH_INVITE_NOT_FOUND);
}
});
it("should handle DB errors", async function () {
it("should handle DB errors", async function() {
const err = new Error("test error");
inviteTokenFindOneStub.rejects(err);
try {
@@ -81,23 +80,23 @@ describe("Invite Module", function () {
});
});
describe("getInviteTokenAndDelete", function () {
it("should return a deleted invite", async function () {
describe("getInviteTokenAndDelete", function() {
it("should return a deleted invite", async function() {
inviteTokenFindOneAndDeleteStub.resolves(mockInviteToken);
const deletedInvite = await getInviteTokenAndDelete(mockUserData.token);
expect(deletedInvite).to.deep.equal(mockInviteToken);
});
it("should handle a token not found", async function () {
it("should handle a token not found", async function() {
inviteTokenFindOneAndDeleteStub.resolves(null);
try {
await getInviteTokenAndDelete(mockUserData.token);
} catch (error) {
expect(error.message).to.equal(errorMessages.AUTH_INVITE_NOT_FOUND(mockLanguage));
expect(error.message).to.equal(errorMessages.AUTH_INVITE_NOT_FOUND);
}
});
it("should handle DB errors", async function () {
it("should handle DB errors", async function() {
const err = new Error("test error");
inviteTokenFindOneAndDeleteStub.rejects(err);
try {