Skip to content

Commit

Permalink
tests: Added tests for updateActionItemCategories.ts (PalisadoesFou…
Browse files Browse the repository at this point in the history
…ndation#2121)

* tests: Added tests for `updateActionItemCategories.ts`

- Added tests for the uncovered lines
- Ensured code coverage for this file is 100%

Signed-off-by: Akhilender <akhilenderb9@gmail.com>

* fix: checking the workflow again

- The test runs successfully on the local setup

Signed-off-by: Akhilender <akhilenderb9@gmail.com>

---------

Signed-off-by: Akhilender <akhilenderb9@gmail.com>
  • Loading branch information
akhilender-bongirwar authored Mar 29, 2024
1 parent cf3b42d commit 4c7d3ea
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions tests/resolvers/Mutation/updateActionItemCategory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type mongoose from "mongoose";
import { Types } from "mongoose";
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
import {
ACTION_ITEM_CATEGORY_ALREADY_EXISTS,
ACTION_ITEM_CATEGORY_NOT_FOUND_ERROR,
USER_NOT_AUTHORIZED_ADMIN,
USER_NOT_FOUND_ERROR,
Expand All @@ -14,8 +15,7 @@ import type {
TestUserType,
} from "../../helpers/userAndOrg";
import { createTestUser } from "../../helpers/userAndOrg";

import { AppUserProfile } from "../../../src/models";
import { ActionItemCategory, AppUserProfile } from "../../../src/models";
import { updateActionItemCategory as updateActionItemCategoryResolver } from "../../../src/resolvers/Mutation/updateActionItemCategory";
import type { TestActionItemCategoryType } from "../../helpers/actionItemCategory";
import { createTestCategory } from "../../helpers/actionItemCategory";
Expand Down Expand Up @@ -174,4 +174,35 @@ describe("resolvers -> Mutation -> updateActionItemCategoryResolver", () => {
}),
);
});

it(`throws ConflictError if an action item category already exists with the provided name`, async () => {
const newCategory = await ActionItemCategory.create({
name: "newCategory",
organizationId: testOrganization?._id,
isDisabled: false,
creatorId: testUser?._id,
});

await newCategory.save();

try {
const args: MutationUpdateActionItemCategoryArgs = {
id: testCategory?._id,
data: {
name: "newCategory",
isDisabled: false,
},
};

const context = {
userId: testUser?._id,
};

await updateActionItemCategoryResolver?.({}, args, context);
} catch (error: unknown) {
expect((error as Error).message).toEqual(
ACTION_ITEM_CATEGORY_ALREADY_EXISTS.MESSAGE,
);
}
});
});

0 comments on commit 4c7d3ea

Please sign in to comment.