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
1 parent
3d9c4df
commit e26e6a4
Showing
8 changed files
with
86 additions
and
12 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 |
---|---|---|
|
@@ -15,4 +15,4 @@ reviews: | |
- develop | ||
- main | ||
chat: | ||
auto_reply: true | ||
auto_reply: true |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
version: '3.8' | ||
version: "3.8" | ||
|
||
services: | ||
mongodb: | ||
|
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,75 @@ | ||
import "dotenv/config"; | ||
import { connect, disconnect } from "../../helpers/db"; | ||
import type mongoose from "mongoose"; | ||
import { beforeAll, afterAll, describe, it, expect } from "vitest"; | ||
import type { TestPostType } from "../../helpers/posts"; | ||
import { createTestPost } from "../../helpers/posts"; | ||
import type { TestOrganizationType, TestUserType } from "../../helpers/userAndOrg"; | ||
import type { InterfacePost} from "../../../src/models"; | ||
import { Organization, Post } from "../../../src/models"; | ||
import { posts as postResolver } from "../../../src/resolvers/Organization/posts"; | ||
|
||
let testPost: TestPostType; | ||
let testUser: TestUserType; | ||
let testOrganization: TestOrganizationType; | ||
let MONGOOSE_INSTANCE: typeof mongoose; | ||
|
||
beforeAll(async () => { | ||
MONGOOSE_INSTANCE = await connect(); | ||
[testUser, testOrganization, testPost] = await createTestPost(); | ||
await Post.updateOne( | ||
{ | ||
_id: testPost?._id, | ||
}, | ||
{ | ||
$push: { | ||
likedBy: testUser?._id, | ||
}, | ||
$inc: { | ||
likeCount: 1, | ||
commentCount: 1, | ||
}, | ||
}, | ||
); | ||
}); | ||
|
||
afterAll(async () => { | ||
await disconnect(MONGOOSE_INSTANCE); | ||
}); | ||
|
||
describe("resolvers -> organization -> posts", () => { | ||
it(`returns the post object for parent post`, async () => { | ||
const parent = await Organization.findById(testOrganization?._id).lean(); | ||
|
||
if (!parent) { | ||
throw new Error("Parent organization not found."); | ||
} | ||
|
||
const postPayload = (await postResolver?.(parent, { first: 1 }, {})) as { | ||
edges: { node: InterfacePost }[]; | ||
totalCount: number; | ||
}; | ||
|
||
expect(postPayload).toBeDefined(); | ||
if (!postPayload) { | ||
throw new Error("postPayload is null or undefined"); | ||
} | ||
expect(postPayload.edges).toBeDefined(); | ||
expect(Array.isArray(postPayload.edges)).toBe(true); | ||
|
||
const posts = await Post.find({ | ||
organization: testOrganization?._id, | ||
}).lean(); | ||
|
||
console.log("postPayloadedge:", postPayload.edges[0].node.likedBy[0]); | ||
console.log("posts:", posts[0].likedBy[0]); | ||
|
||
expect(postPayload.edges.length).toEqual(posts.length); | ||
expect(postPayload.totalCount).toEqual(posts.length); | ||
const returnedPost = postPayload.edges[0].node; | ||
expect(returnedPost._id).toEqual(testPost?._id.toString()); | ||
expect(returnedPost.likedBy).toHaveLength(1); | ||
expect(returnedPost.likedBy[0]._id).toEqual(testUser?._id); | ||
expect(returnedPost.likedBy[0].image).not.toBeNull(); | ||
}); | ||
}); |
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