feat: i18n support for backend

This commit is contained in:
cihatata
2025-01-28 00:09:56 +03:00
committed by cihat
parent 0eceac1587
commit 10713428b9
34 changed files with 1106 additions and 838 deletions
+17 -16
View File
@@ -7,32 +7,33 @@ 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);
@@ -41,7 +42,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 {
@@ -52,23 +53,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);
expect(error.message).to.equal(errorMessages.AUTH_INVITE_NOT_FOUND(mockLanguage));
}
});
it("should handle DB errors", async function() {
it("should handle DB errors", async function () {
const err = new Error("test error");
inviteTokenFindOneStub.rejects(err);
try {
@@ -80,23 +81,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);
expect(error.message).to.equal(errorMessages.AUTH_INVITE_NOT_FOUND(mockLanguage));
}
});
it("should handle DB errors", async function() {
it("should handle DB errors", async function () {
const err = new Error("test error");
inviteTokenFindOneAndDeleteStub.rejects(err);
try {