forked from PalisadoesFoundation/talawa-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add field level resolvers for the task modal (PalisadoesFoundation#1389)
- Loading branch information
Showing
5 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); |