diff --git a/src/resolvers/Task/creator.ts b/src/resolvers/Task/creator.ts new file mode 100644 index 0000000000..25e84606bc --- /dev/null +++ b/src/resolvers/Task/creator.ts @@ -0,0 +1,8 @@ +import type { TaskResolvers } from "../../types/generatedGraphQLTypes"; +import { User } from "../../models"; + +export const creator: TaskResolvers["creator"] = async (parent) => { + return User.findOne({ + _id: parent.creator, + }).lean(); +}; diff --git a/src/resolvers/Task/event.ts b/src/resolvers/Task/event.ts new file mode 100644 index 0000000000..191bfa7f7e --- /dev/null +++ b/src/resolvers/Task/event.ts @@ -0,0 +1,12 @@ +import type { TaskResolvers } from "../../types/generatedGraphQLTypes"; +import { EventProject } from "../../models"; + +export const event: TaskResolvers["event"] = async (parent) => { + const eventProjectObject = await EventProject.findOne({ + _id: parent.eventProjectId, + }) + .populate("event") + .lean(); + + return eventProjectObject!.event; +}; diff --git a/src/resolvers/Task/index.ts b/src/resolvers/Task/index.ts index e46555d6df..b6b2952efd 100644 --- a/src/resolvers/Task/index.ts +++ b/src/resolvers/Task/index.ts @@ -1,6 +1,10 @@ import type { TaskResolvers } from "../../types/generatedGraphQLTypes"; +import { creator } from "./creator"; +import { event } from "./event"; import { volunteers } from "./volunteers"; export const Task: TaskResolvers = { + creator, + event, volunteers, }; diff --git a/tests/resolvers/Task/creator.spec.ts b/tests/resolvers/Task/creator.spec.ts new file mode 100644 index 0000000000..e7db52d8da --- /dev/null +++ b/tests/resolvers/Task/creator.spec.ts @@ -0,0 +1,35 @@ +import "dotenv/config"; +import { creator as creatorResolver } from "../../../src/resolvers/Task/creator"; +import { connect, disconnect } from "../../helpers/db"; +import type mongoose from "mongoose"; +import { beforeAll, afterAll, describe, it, expect } from "vitest"; +import { createAndAssignTestTask, type TestTaskType } from "../../helpers/task"; +import type { TestUserType } from "../../helpers/userAndOrg"; +import { User } from "../../../src/models"; + +let MONGOOSE_INSTANCE: typeof mongoose; +let testUser: TestUserType; +let testTask: TestTaskType; + +beforeAll(async () => { + MONGOOSE_INSTANCE = await connect(); + [testUser, , , , testTask] = await createAndAssignTestTask(); +}); + +afterAll(async () => { + await disconnect(MONGOOSE_INSTANCE); +}); + +describe("resolvers -> Task -> Creator", () => { + it(`returns the creator user object for parent task`, async () => { + const parent = testTask!.toObject(); + + const creatorPayload = await creatorResolver?.(parent, {}, {}); + + const creatorObject = await User.findOne({ + _id: testUser!._id, + }).lean(); + + expect(creatorPayload).toEqual(creatorObject); + }); +}); diff --git a/tests/resolvers/Task/event.spec.ts b/tests/resolvers/Task/event.spec.ts new file mode 100644 index 0000000000..cf8db54b66 --- /dev/null +++ b/tests/resolvers/Task/event.spec.ts @@ -0,0 +1,35 @@ +import "dotenv/config"; +import { event as eventResolver } from "../../../src/resolvers/Task/event"; +import { connect, disconnect } from "../../helpers/db"; +import type mongoose from "mongoose"; +import { beforeAll, afterAll, describe, it, expect } from "vitest"; +import { createAndAssignTestTask, type TestTaskType } from "../../helpers/task"; +import { Event } from "../../../src/models"; +import type { TestEventType } from "../../helpers/events"; + +let MONGOOSE_INSTANCE: typeof mongoose; +let testEvent: TestEventType; +let testTask: TestTaskType; + +beforeAll(async () => { + MONGOOSE_INSTANCE = await connect(); + [, , testEvent, , testTask] = await createAndAssignTestTask(); +}); + +afterAll(async () => { + await disconnect(MONGOOSE_INSTANCE); +}); + +describe("resolvers -> Task -> event", () => { + it(`returns the correct event object for parent task`, async () => { + const parent = testTask!.toObject(); + + const eventPayload = await eventResolver?.(parent, {}, {}); + + const eventObject = await Event.findOne({ + _id: testEvent!._id, + }).lean(); + + expect(eventPayload).toEqual(eventObject); + }); +});