|
9 | 9 | parseCursor,
|
10 | 10 | posts as postResolver,
|
11 | 11 | } from "../../../src/resolvers/Organization/posts";
|
12 |
| -import type { PostEdge } from "../../../src/types/generatedGraphQLTypes"; |
13 | 12 | import type { DefaultGraphQLArgumentError } from "../../../src/utilities/graphQLConnection";
|
14 | 13 | import { connect, disconnect } from "../../helpers/db";
|
15 | 14 | import { createTestPost, type TestPostType } from "../../helpers/posts";
|
@@ -71,12 +70,66 @@ describe("resolvers -> Organization -> post", () => {
|
71 | 70 | creatorId: testUser?._id,
|
72 | 71 | }).countDocuments();
|
73 | 72 |
|
74 |
| - expect((connection?.edges[0] as unknown as PostEdge).cursor).toEqual( |
75 |
| - testPost2?._id.toString(), |
76 |
| - ); |
77 |
| - expect((connection?.edges[1] as unknown as PostEdge).cursor).toEqual( |
78 |
| - testPost?._id.toString(), |
79 |
| - ); |
| 73 | + const context = { apiRootUrl: "http://example.com" }; |
| 74 | + |
| 75 | + const formattedPost2 = { |
| 76 | + ...testPost2?.toObject(), |
| 77 | + imageUrl: testPost2?.imageUrl |
| 78 | + ? new URL(testPost2.imageUrl, context.apiRootUrl).toString() |
| 79 | + : null, |
| 80 | + videoUrl: testPost2?.videoUrl |
| 81 | + ? new URL(testPost2.videoUrl, context.apiRootUrl).toString() |
| 82 | + : null, |
| 83 | + }; |
| 84 | + |
| 85 | + const formattedPost = { |
| 86 | + ...testPost?.toObject(), |
| 87 | + imageUrl: testPost?.imageUrl |
| 88 | + ? new URL(testPost.imageUrl, context.apiRootUrl).toString() |
| 89 | + : null, |
| 90 | + videoUrl: testPost?.videoUrl |
| 91 | + ? new URL(testPost.videoUrl, context.apiRootUrl).toString() |
| 92 | + : null, |
| 93 | + }; |
| 94 | + |
| 95 | + expect(connection).toEqual({ |
| 96 | + edges: [ |
| 97 | + { |
| 98 | + cursor: formattedPost2._id?.toString(), |
| 99 | + node: { |
| 100 | + ...formattedPost2, |
| 101 | + _id: formattedPost2._id?.toString(), |
| 102 | + imageUrl: testPost?.imageUrl |
| 103 | + ? new URL(testPost.imageUrl, context.apiRootUrl).toString() |
| 104 | + : null, |
| 105 | + videoUrl: formattedPost2?.videoUrl |
| 106 | + ? new URL(formattedPost2.videoUrl, context.apiRootUrl).toString() |
| 107 | + : null, |
| 108 | + }, |
| 109 | + }, |
| 110 | + { |
| 111 | + cursor: formattedPost._id?.toString(), |
| 112 | + node: { |
| 113 | + ...formattedPost, |
| 114 | + _id: formattedPost?._id?.toString(), |
| 115 | + imageUrl: formattedPost?.imageUrl |
| 116 | + ? new URL(formattedPost.imageUrl, context.apiRootUrl).toString() |
| 117 | + : null, |
| 118 | + videoUrl: formattedPost?.videoUrl |
| 119 | + ? new URL(formattedPost.videoUrl, context.apiRootUrl).toString() |
| 120 | + : null, |
| 121 | + }, |
| 122 | + }, |
| 123 | + ], |
| 124 | + pageInfo: { |
| 125 | + endCursor: testPost?._id.toString(), |
| 126 | + hasNextPage: false, |
| 127 | + hasPreviousPage: false, |
| 128 | + startCursor: testPost2?._id.toString(), |
| 129 | + }, |
| 130 | + totalCount, |
| 131 | + }); |
| 132 | + |
80 | 133 | expect(connection?.pageInfo.endCursor).toEqual(testPost?._id.toString());
|
81 | 134 | expect(connection?.pageInfo.hasNextPage).toBe(false);
|
82 | 135 | expect(connection?.pageInfo.hasPreviousPage).toBe(false);
|
|
0 commit comments