Skip to content

Commit

Permalink
solved event creation problem (PalisadoesFoundation#2031)
Browse files Browse the repository at this point in the history
* solved event creation problem

* new commit

* new commit

* new commit

* new commit

* fixed tests

* new commit

* new commit

* new commit

---------

Co-authored-by: Peter Harrison <[email protected]>
  • Loading branch information
AdityaRaimec22 and palisadoes authored Apr 1, 2024
1 parent 3ae36fb commit 0f489b3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/resolvers/Mutation/createEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ export const createEvent: MutationResolvers["createEvent"] = async (
}

const organization = await Organization.findOne({
_id: args.data?.organizationId,
_id: args.data.organizationId.startsWith("id=")
? args.data.organizationId.toString().substring(3)
: args.data.organizationId,
}).lean();

// Checks whether organization exists.
Expand Down
40 changes: 40 additions & 0 deletions tests/resolvers/Mutation/createEvent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,46 @@ describe("resolvers -> Mutation -> createEvent", () => {
}
});

it(`throws NotFoundError if no organization exists with _id === id=args.data.organizationId`, async () => {
try {
const args: MutationCreateEventArgs = {
data: {
organizationId: "id=" + new Types.ObjectId().toString(),
allDay: false,
description: "",
endDate: "",
endTime: "",
isPublic: false,
isRegisterable: false,
latitude: 1,
longitude: 1,
location: "",
recurring: false,
startDate: "",
startTime: "",
title: "",
images: null,
},
};

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

const { createEvent: createEventResolverError } = await import(
"../../../src/resolvers/Mutation/createEvent"
);

await createEventResolverError?.({}, args, context);
} catch (error: unknown) {
if (error instanceof NotFoundError) {
expect(error.message).toEqual(ORGANIZATION_NOT_FOUND_ERROR.MESSAGE);
} else {
fail(`Expected NotFoundError, but got ${error}`);
}
}
});

it(`throws UnauthorizedError if user with _id === context.userId is neither the creator
nor a member of the organization with _id === args.organizationId`, async () => {
try {
Expand Down

0 comments on commit 0f489b3

Please sign in to comment.