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.
- Loading branch information
Showing
23 changed files
with
1,450 additions
and
5 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
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
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
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,124 @@ | ||
import type { InterfaceActionItem } from "../../src/models"; | ||
import { ActionItem, Category, Event } from "../../src/models"; | ||
import type { Document } from "mongoose"; | ||
import { | ||
createTestUser, | ||
createTestUserAndOrganization, | ||
type TestOrganizationType, | ||
type TestUserType, | ||
} from "./userAndOrg"; | ||
import type { TestCategoryType } from "./category"; | ||
import { createTestCategory } from "./category"; | ||
import { nanoid } from "nanoid"; | ||
import type { TestEventType } from "./events"; | ||
|
||
export type TestActionItemType = InterfaceActionItem & Document; | ||
|
||
export const createTestActionItem = async (): Promise< | ||
[ | ||
TestUserType, | ||
TestOrganizationType, | ||
TestCategoryType, | ||
TestActionItemType, | ||
TestUserType | ||
] | ||
> => { | ||
const [testUser, testOrganization] = await createTestUserAndOrganization(); | ||
const randomUser = await createTestUser(); | ||
|
||
const testCategory = await Category.create({ | ||
createdBy: testUser?._id, | ||
updatedBy: testUser?._id, | ||
org: testOrganization?._id, | ||
category: "Default", | ||
}); | ||
|
||
const testActionItem = await ActionItem.create({ | ||
createdBy: testUser?._id, | ||
updatedBy: testUser?._id, | ||
assignedTo: randomUser?._id, | ||
assignedBy: testUser?._id, | ||
category: testCategory?._id, | ||
}); | ||
|
||
return [testUser, testOrganization, testCategory, testActionItem, randomUser]; | ||
}; | ||
|
||
interface InterfaceCreateNewTestAction { | ||
currUserId: string; | ||
assignedUserId: string; | ||
categoryId: string; | ||
} | ||
|
||
export const createNewTestActionItem = async ({ | ||
currUserId, | ||
assignedUserId, | ||
categoryId, | ||
}: InterfaceCreateNewTestAction): Promise<TestActionItemType> => { | ||
const newTestActionItem = await ActionItem.create({ | ||
createdBy: currUserId, | ||
updatedBy: currUserId, | ||
assignedTo: assignedUserId, | ||
assignedBy: currUserId, | ||
category: categoryId, | ||
}); | ||
|
||
return newTestActionItem; | ||
}; | ||
|
||
export const createTestActionItems = async (): Promise< | ||
[TestUserType, TestEventType] | ||
> => { | ||
const randomUser = await createTestUser(); | ||
const [testUser, testOrganization, testCategory] = await createTestCategory(); | ||
|
||
const testActionItem1 = await ActionItem.create({ | ||
createdBy: testUser?._id, | ||
updatedBy: testUser?._id, | ||
assignedTo: randomUser?._id, | ||
assignedBy: testUser?._id, | ||
category: testCategory?._id, | ||
}); | ||
|
||
const testActionItem2 = await ActionItem.create({ | ||
createdBy: testUser?._id, | ||
updatedBy: testUser?._id, | ||
assignedTo: randomUser?._id, | ||
assignedBy: testUser?._id, | ||
category: testCategory?._id, | ||
}); | ||
|
||
const testEvent = await Event.create({ | ||
title: `title${nanoid().toLowerCase()}`, | ||
description: `description${nanoid().toLowerCase()}`, | ||
allDay: true, | ||
startDate: new Date(), | ||
recurring: true, | ||
isPublic: true, | ||
isRegisterable: true, | ||
creator: testUser?._id, | ||
admins: [testUser?._id], | ||
organization: testOrganization?._id, | ||
actionItems: [testActionItem1?._id, testActionItem2?._id], | ||
}); | ||
|
||
await ActionItem.updateOne( | ||
{ | ||
_id: testActionItem1?._id, | ||
}, | ||
{ | ||
event: testEvent?._id, | ||
} | ||
); | ||
|
||
await ActionItem.updateOne( | ||
{ | ||
_id: testActionItem2?._id, | ||
}, | ||
{ | ||
event: testEvent?._id, | ||
} | ||
); | ||
|
||
return [testUser, testEvent]; | ||
}; |
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,36 @@ | ||
import "dotenv/config"; | ||
import { assignedBy as assignedByResolver } from "../../../src/resolvers/ActionItem/assignedBy"; | ||
import { connect, disconnect } from "../../helpers/db"; | ||
import type mongoose from "mongoose"; | ||
import { beforeAll, afterAll, describe, it, expect } from "vitest"; | ||
import { User } from "../../../src/models"; | ||
import type { TestUserType } from "../../helpers/userAndOrg"; | ||
import type { TestActionItemType } from "../../helpers/actionItem"; | ||
import { createTestActionItem } from "../../helpers/actionItem"; | ||
|
||
let MONGOOSE_INSTANCE: typeof mongoose; | ||
let testUser: TestUserType; | ||
let testActionItem: TestActionItemType; | ||
|
||
beforeAll(async () => { | ||
MONGOOSE_INSTANCE = await connect(); | ||
[testUser, , , testActionItem] = await createTestActionItem(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await disconnect(MONGOOSE_INSTANCE); | ||
}); | ||
|
||
describe("resolvers -> ActionItem -> assignedBy", () => { | ||
it(`returns the assigner for parent action item`, async () => { | ||
const parent = testActionItem?.toObject(); | ||
|
||
const assignedByPayload = await assignedByResolver?.(parent, {}, {}); | ||
|
||
const assignedByObject = await User.findOne({ | ||
_id: testUser?._id, | ||
}).lean(); | ||
|
||
expect(assignedByPayload).toEqual(assignedByObject); | ||
}); | ||
}); |
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,36 @@ | ||
import "dotenv/config"; | ||
import { assignedTo as assignedToResolver } from "../../../src/resolvers/ActionItem/assignedTo"; | ||
import { connect, disconnect } from "../../helpers/db"; | ||
import type mongoose from "mongoose"; | ||
import { beforeAll, afterAll, describe, it, expect } from "vitest"; | ||
import { User } from "../../../src/models"; | ||
import type { TestUserType } from "../../helpers/userAndOrg"; | ||
import type { TestActionItemType } from "../../helpers/actionItem"; | ||
import { createTestActionItem } from "../../helpers/actionItem"; | ||
|
||
let MONGOOSE_INSTANCE: typeof mongoose; | ||
let randomTestUser: TestUserType; | ||
let testActionItem: TestActionItemType; | ||
|
||
beforeAll(async () => { | ||
MONGOOSE_INSTANCE = await connect(); | ||
[, , , testActionItem, randomTestUser] = await createTestActionItem(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await disconnect(MONGOOSE_INSTANCE); | ||
}); | ||
|
||
describe("resolvers -> ActionItem -> assignedBy", () => { | ||
it(`returns the assignee for parent action item`, async () => { | ||
const parent = testActionItem?.toObject(); | ||
|
||
const assignedToPayload = await assignedToResolver?.(parent, {}, {}); | ||
|
||
const assignedToObject = await User.findOne({ | ||
_id: randomTestUser?._id, | ||
}).lean(); | ||
|
||
expect(assignedToPayload).toEqual(assignedToObject); | ||
}); | ||
}); |
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,36 @@ | ||
import "dotenv/config"; | ||
import { category as categoryResolver } from "../../../src/resolvers/ActionItem/category"; | ||
import { connect, disconnect } from "../../helpers/db"; | ||
import type mongoose from "mongoose"; | ||
import { beforeAll, afterAll, describe, it, expect } from "vitest"; | ||
import { Category } from "../../../src/models"; | ||
import type { TestActionItemType } from "../../helpers/actionItem"; | ||
import { createTestActionItem } from "../../helpers/actionItem"; | ||
import type { TestCategoryType } from "../../helpers/category"; | ||
|
||
let MONGOOSE_INSTANCE: typeof mongoose; | ||
let testActionItem: TestActionItemType; | ||
let testCategory: TestCategoryType; | ||
|
||
beforeAll(async () => { | ||
MONGOOSE_INSTANCE = await connect(); | ||
[, , testCategory, testActionItem] = await createTestActionItem(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await disconnect(MONGOOSE_INSTANCE); | ||
}); | ||
|
||
describe("resolvers -> ActionItem -> category", () => { | ||
it(`returns the category for parent action item`, async () => { | ||
const parent = testActionItem?.toObject(); | ||
|
||
const categoryPayload = await categoryResolver?.(parent, {}, {}); | ||
|
||
const categoryObject = await Category.findOne({ | ||
_id: testCategory?._id, | ||
}).lean(); | ||
|
||
expect(categoryPayload).toEqual(categoryObject); | ||
}); | ||
}); |
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,36 @@ | ||
import "dotenv/config"; | ||
import { createdBy as createdByResolver } from "../../../src/resolvers/ActionItem/createdBy"; | ||
import { connect, disconnect } from "../../helpers/db"; | ||
import type mongoose from "mongoose"; | ||
import { beforeAll, afterAll, describe, it, expect } from "vitest"; | ||
import { User } from "../../../src/models"; | ||
import type { TestUserType } from "../../helpers/userAndOrg"; | ||
import type { TestActionItemType } from "../../helpers/actionItem"; | ||
import { createTestActionItem } from "../../helpers/actionItem"; | ||
|
||
let MONGOOSE_INSTANCE: typeof mongoose; | ||
let testUser: TestUserType; | ||
let testActionItem: TestActionItemType; | ||
|
||
beforeAll(async () => { | ||
MONGOOSE_INSTANCE = await connect(); | ||
[testUser, , , testActionItem] = await createTestActionItem(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await disconnect(MONGOOSE_INSTANCE); | ||
}); | ||
|
||
describe("resolvers -> ActionItem -> createdBy", () => { | ||
it(`returns the creator for parent action item`, async () => { | ||
const parent = testActionItem?.toObject(); | ||
|
||
const createdByPayload = await createdByResolver?.(parent, {}, {}); | ||
|
||
const createdByObject = await User.findOne({ | ||
_id: testUser?._id, | ||
}).lean(); | ||
|
||
expect(createdByPayload).toEqual(createdByObject); | ||
}); | ||
}); |
Oops, something went wrong.