Skip to content

Commit 04b0657

Browse files
committed
CodeRabbit's suggestions.
1 parent cf391c9 commit 04b0657

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

test/graphql/types/Organization/creator.test.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,8 @@ type UserFromDB = {
105105
role: UserRole;
106106
homePhoneNumber: string | null;
107107
workPhoneNumber: string | null;
108-
avatarMimeType:
109-
| "image/avif"
110-
| "image/jpeg"
111-
| "image/png"
112-
| "image/webp"
113-
| null;
114-
avatarBase64: string | null;
108+
avatarMimeType: "image/avif" | "image/jpeg" | "image/png" | "image/webp" | null
109+
avatarBase64: string | null;
115110
educationGrade: string | null;
116111
employmentStatus: string | null;
117112
maritalStatus: string | null;
@@ -177,7 +172,7 @@ const createMockContext = (overrides?: Partial<TestContext>): TestContext => ({
177172
decorate: vi.fn(),
178173
get: vi.fn(),
179174
post: vi.fn(),
180-
} as unknown as FastifyInstance,
175+
} as Partial<Pick<FastifyInstance, 'addHook' | 'decorate' | 'get' | 'post'>>,
181176
reply: {
182177
code: vi.fn(),
183178
send: vi.fn(),
@@ -228,6 +223,11 @@ const resolveCreator = async (
228223
});
229224
}
230225

226+
// Early return if organization has no creator
227+
if (parent.creatorId === null) {
228+
return null;
229+
}
230+
231231
const currentUserOrganizationMembership =
232232
currentUser.organizationMembershipsWhereMember[0];
233233

@@ -378,6 +378,23 @@ describe("Organization Resolver - Creator Field", () => {
378378
});
379379
});
380380

381+
it("should throw unauthorized error if user has no organization membership", async () => {
382+
const mockUser = createCompleteMockUser("regular", []);
383+
ctx.drizzleClient.query.usersTable.findFirst.mockResolvedValueOnce(mockUser);
384+
385+
await expect(async () => {
386+
await resolveCreator(
387+
mockOrganization,
388+
{},
389+
ctx as unknown as ResolverContext,
390+
);
391+
}).rejects.toThrow(
392+
new TalawaGraphQLError({
393+
extensions: { code: "unauthorized_action" },
394+
}),
395+
);
396+
});
397+
381398
describe("Error Handling", () => {
382399
it("should throw unexpected error if creator user is not found", async () => {
383400
const mockUser = createCompleteMockUser("administrator");

0 commit comments

Comments
 (0)