Skip to content

Commit

Permalink
Added test for updateAgendaCategory.ts (PalisadoesFoundation#2207)
Browse files Browse the repository at this point in the history
* Replace package vm2 with isolated-vm (PalisadoesFoundation#1532)

* Replace package vm2 with isolated-vm

* Removed package isolated-vm

* chore(deps): bump follow-redirects from 1.15.3 to 1.15.4 (PalisadoesFoundation#1668)

Bumps [follow-redirects](https://github.com/follow-redirects/follow-redirects) from 1.15.3 to 1.15.4.
- [Release notes](https://github.com/follow-redirects/follow-redirects/releases)
- [Commits](follow-redirects/follow-redirects@v1.15.3...v1.15.4)

---
updated-dependencies:
- dependency-name: follow-redirects
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps): bump vite from 3.2.7 to 3.2.8 (PalisadoesFoundation#1724)

Bumps [vite](https://github.com/vitejs/vite/tree/HEAD/packages/vite) from 3.2.7 to 3.2.8.
- [Release notes](https://github.com/vitejs/vite/releases)
- [Changelog](https://github.com/vitejs/vite/blob/v3.2.8/packages/vite/CHANGELOG.md)
- [Commits](https://github.com/vitejs/vite/commits/v3.2.8/packages/vite)

---
updated-dependencies:
- dependency-name: vite
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Update README.md

* Update pull-request.yml

* Update INSTALLATION.md

Adding information for MongoDB retry writes feature access.

* Bug Fix Issue#1792

* Fix Issue#1792

* Conflicitng  fix Issue#1792

* Conflicitng  fix Issue#1792

* Conflicitng  fix Issue#1792

* fixed code cov

* fixed tests

* fixed cov

* fixed cov

* fixed prettier

* fixed prettier

* fixed coverage

* fixed req changes

* added test for getWhere.ts

* added test for getWhere.ts

* added test for createAgendaCategory.ts

* added test for updateAgendaCategory.ts

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Sarthak Patel <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Peter Harrison <[email protected]>
Co-authored-by: Crystian I <[email protected]>
Co-authored-by: krishna <[email protected]>
  • Loading branch information
6 people authored Apr 15, 2024
1 parent 7674f57 commit 9c9ae2e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 58 deletions.
10 changes: 2 additions & 8 deletions src/resolvers/Mutation/updateAgendaCategory.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Types } from "mongoose";
import {
AGENDA_CATEGORY_NOT_FOUND_ERROR,
USER_NOT_AUTHORIZED_ERROR,
Expand Down Expand Up @@ -96,16 +95,11 @@ export const updateAgendaCategory: MutationResolvers["updateAgendaCategory"] =
)
.select("organizationId")
.lean();
// console.log(currentOrg);

const currentUserIsOrgAdmin = currentUserAppProfile.adminFor.some(
(organizationId) =>
new Types.ObjectId(organizationId?.toString()).equals(
currentOrg?.organizationId?.toString() || "",
),
(organizationId) => organizationId?.toString() === currentOrg?.toString(),
);
// console.log(currentUserIsOrgAdmin, currentUserAppProfile.isSuperAdmin);
// If the user is a normal user, throw an error

if (
currentUserIsOrgAdmin === false &&
!currentUserAppProfile.isSuperAdmin
Expand Down
86 changes: 36 additions & 50 deletions tests/resolvers/Mutation/updateAgendaCategory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
AgendaCategoryModel,
AppUserProfile,
Organization,
User,
} from "../../../src/models";
import type { TestUserType } from "../../helpers/user";
import { createTestUser } from "../../helpers/user";
Expand Down Expand Up @@ -47,16 +46,6 @@ beforeAll(async () => {
creatorId: testUser?._id,
});

await User.updateOne(
{
_id: testUser?._id,
},
{
$push: {
adminFor: testOrganization?._id,
},
},
);
testAgendaCategory = await AgendaCategoryModel.create({
name: "Sample Agenda Category",
organization: testOrganization?._id,
Expand Down Expand Up @@ -142,29 +131,32 @@ describe("resolvers -> Mutation -> updateAgendaCategory", () => {
description: "Updated Description",
},
};

await AppUserProfile.findOneAndUpdate(
{ userId: testUser?._id },
{
$set: {
adminFor: [testOrganization?._id.toString()],
isSuperAdmin: true,
},
},
{ new: true, upsert: true },
);
const context = {
userId: testUser?._id,
};

try {
const updatedAgendaCategoryPayload = await updateAgendaCategoryResolver?.(
{},
args,
context,
);
const updatedAgendaCategoryPayload = await updateAgendaCategoryResolver?.(
{},
args,
context,
);

expect(updatedAgendaCategoryPayload).toEqual(
expect.objectContaining({
name: "Updated Name",
description: "Updated Description",
}),
);
} catch (error: unknown) {
expect((error as Error).message).toEqual(
USER_NOT_AUTHORIZED_ERROR.MESSAGE,
);
}
expect(updatedAgendaCategoryPayload).toEqual(
expect.objectContaining({
name: "Updated Name",
description: "Updated Description",
}),
);
});
// it(`updates the agenda category and returns it for the admin`, async () => {
// const args: MutationUpdateAgendaCategoryArgs = {
Expand Down Expand Up @@ -193,19 +185,19 @@ describe("resolvers -> Mutation -> updateAgendaCategory", () => {
// );
// });
it(`updates the agenda category and returns it as superadmin`, async () => {
const superAdminTestUser = await User.findOneAndUpdate(
await AppUserProfile.findOneAndUpdate(
{
_id: randomUser?._id,
userId: testUser?._id,
},
{
userType: "SUPERADMIN",
isSuperAdmin: true,
},
{
new: true,
},
);
const context = {
userId: superAdminTestUser?._id,
userId: testUser?._id,
};
const args: MutationUpdateAgendaCategoryArgs = {
id: testAgendaCategory?._id,
Expand All @@ -215,24 +207,18 @@ describe("resolvers -> Mutation -> updateAgendaCategory", () => {
},
};

try {
const updatedAgendaCategoryPayload = await updateAgendaCategoryResolver?.(
{},
args,
context,
);
const updatedAgendaCategoryPayload = await updateAgendaCategoryResolver?.(
{},
args,
context,
);

expect(updatedAgendaCategoryPayload).toEqual(
expect.objectContaining({
name: "Updated Name",
description: "Updated Description",
}),
);
} catch (error: unknown) {
expect((error as Error).message).toEqual(
USER_NOT_AUTHORIZED_ERROR.MESSAGE,
);
}
expect(updatedAgendaCategoryPayload).toEqual(
expect.objectContaining({
name: "Updated Name",
description: "Updated Description",
}),
);
});
it("throws an error if the user does not have appUserProfile", async () => {
await AppUserProfile.deleteOne({
Expand Down

0 comments on commit 9c9ae2e

Please sign in to comment.