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.
Added a field level resolver for Users
- Loading branch information
1 parent
b2d0e8d
commit 200066a
Showing
3 changed files
with
86 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 { AgendaItemResolvers } from "../../types/generatedGraphQLTypes"; | ||
import { User } from "../../models"; | ||
|
||
export const users: AgendaItemResolvers["users"] = async (parent) => { | ||
const userIds = parent.users; // Assuming parent.users is an array of user ids | ||
const users = await User.find({ _id: { $in: userIds } }); // Assuming User.find() returns a promise | ||
return users; | ||
}; |
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
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,76 @@ | ||
import type mongoose from "mongoose"; | ||
import { afterAll, beforeAll, describe, expect, it } from "vitest"; | ||
import { AgendaItemModel, Organization, Event } from "../../../src/models"; | ||
import { users as usersResolver } from "../../../src/resolvers/AgendaItem/Users"; | ||
import type { TestAgendaItemType } from "../../helpers/agendaItem"; | ||
import { connect, disconnect } from "../../helpers/db"; | ||
import type { | ||
TestOrganizationType, | ||
createTestUser, | ||
type TestUserType, | ||
} from "../../helpers/userAndOrg"; | ||
|
||
import type { TestEventType } from "../../helpers/events"; | ||
|
||
let MONGOOSE_INSTANCE: typeof mongoose; | ||
let testUser1: TestUserType; | ||
let testUser2: TestUserType; | ||
let testAgendaItem: TestAgendaItemType; | ||
let testOrganization: TestOrganizationType; | ||
let testEvent: TestEventType; | ||
|
||
beforeAll(async () => { | ||
MONGOOSE_INSTANCE = await connect(); | ||
testUser1 = await createTestUser(); | ||
testUser2 = await createTestUser(); | ||
testOrganization = await Organization.create({ | ||
name: "name", | ||
description: "description", | ||
isPublic: true, | ||
creator: testUser1?._id, | ||
admins: [testUser1?._id, testUser2?._id], | ||
members: [testUser1?._id, testUser2?._id], | ||
creatorId: testUser1?._id, | ||
}); | ||
testEvent = await Event.create({ | ||
title: "title", | ||
description: "description", | ||
allDay: true, | ||
startDate: new Date(), | ||
recurring: true, | ||
isPublic: true, | ||
isRegisterable: true, | ||
creator: testUser1?._id, | ||
admins: [testUser1?._id, testUser2?._id], | ||
registrants: [], | ||
organization: testOrganization?._id, | ||
creatorId: testUser1?._id, | ||
}); | ||
|
||
testAgendaItem = await AgendaItemModel.create({ | ||
title: "Regular Agenda Item", | ||
description: "Description for the regular agenda item", | ||
duration: "1 hour", | ||
relatedEventId: testEvent?._id, | ||
sequence: 1, | ||
itemType: "Regular", | ||
organizationId: testOrganization?._id, | ||
isNote: false, | ||
createdBy: testUser1?._id, | ||
createdAt: Date.now(), | ||
updatedBy: testUser1?._id, | ||
updatedAt: Date.now(), | ||
users: [testUser1?._id, testUser2?._id], // Assuming users field is an array of user ids | ||
}); | ||
}); | ||
|
||
afterAll(async () => { | ||
await disconnect(MONGOOSE_INSTANCE); | ||
}); | ||
|
||
describe("AgendaItem.Users", () => { | ||
it("Should return the users of the agenda item", async () => { | ||
const users = await usersResolver?.(testAgendaItem, {}, {}); | ||
expect(users).toEqual([testUser1, testUser2]); | ||
}); | ||
}); |