From 2be1081e92b613bf9259c68953c8ee495a6085a6 Mon Sep 17 00:00:00 2001 From: Z8MB1E Date: Thu, 27 Aug 2026 14:01:16 -0400 Subject: [PATCH] test(int): fix pre-existing tickets and market spec failures tickets: makeUser now assigns roleDocs because getStaffUserIds queries the RBAC relationship and the legacy roles select field is not synced at runtime. Both specs: teardown deletes profiles (and user-notifications in market) before users, since those relationships are NOT NULL. --- tests/int/market.int.spec.ts | 21 ++++++++++++++++++++ tests/int/tickets.int.spec.ts | 36 +++++++++++++++++++++++++++++++++-- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/tests/int/market.int.spec.ts b/tests/int/market.int.spec.ts index e79a548..9552a78 100644 --- a/tests/int/market.int.spec.ts +++ b/tests/int/market.int.spec.ts @@ -196,6 +196,27 @@ describe("Marketplace", () => { for (const locker of lockers.docs) { await payload.delete({ collection: "locker-storages", id: locker.id, overrideAccess: true }); } + // profiles.user and user-notifications.user are NOT NULL — delete them before the user. + const profiles = await payload.find({ + collection: "profiles", + where: { user: { equals: user.id } }, + limit: 5, + depth: 0, + overrideAccess: true, + }); + for (const profile of profiles.docs) { + await payload.delete({ collection: "profiles", id: profile.id, overrideAccess: true }); + } + const notifications = await payload.find({ + collection: "user-notifications", + where: { user: { equals: user.id } }, + limit: 100, + depth: 0, + overrideAccess: true, + }); + for (const notification of notifications.docs) { + await payload.delete({ collection: "user-notifications", id: notification.id, overrideAccess: true }); + } await payload.delete({ collection: "users", id: user.id, overrideAccess: true }); } diff --git a/tests/int/tickets.int.spec.ts b/tests/int/tickets.int.spec.ts index 32a3376..1bc992c 100644 --- a/tests/int/tickets.int.spec.ts +++ b/tests/int/tickets.int.spec.ts @@ -12,8 +12,29 @@ let payload: Payload; const RUN = `tk-${Date.now().toString(36)}`; -const makeUser = async (label: string, roles: NonNullable = ["user"]): Promise => { +// getStaffUserIds resolves staff via the RBAC `roleDocs` relationship — the legacy +// `roles` select field is not synced at runtime, so tests must assign role docs. +const getRoleDocId = async (slug: string): Promise => { + const existing = await payload.find({ + collection: "roles", + where: { slug: { equals: slug } }, + limit: 1, + depth: 0, + overrideAccess: true, + }); + if (existing.docs[0]) return existing.docs[0].id; + const created = await payload.create({ + collection: "roles", + data: { name: slug, slug }, + overrideAccess: true, + depth: 0, + }); + return created.id; +}; + +const makeUser = async (label: string, roleSlugs: string[] = ["user"]): Promise => { const tag = `${RUN}-${label}`; + const roleDocs = await Promise.all(roleSlugs.map((slug) => getRoleDocId(slug))); return (await payload.create({ collection: "users", data: { @@ -22,7 +43,7 @@ const makeUser = async (label: string, roles: NonNullable = ["use displayName: label.toUpperCase(), steamId: `7656119${Math.floor(Math.random() * 1e9)}`, password: "Test123", - roles, + roleDocs, }, overrideAccess: true, depth: 0, @@ -93,6 +114,17 @@ describe("Tickets", () => { for (const user of [reporter, assignee, staff]) { if (!user) continue; + // profiles.user is NOT NULL — delete the auto-created profile before its user. + const profiles = await payload.find({ + collection: "profiles", + where: { user: { equals: user.id } }, + limit: 5, + depth: 0, + overrideAccess: true, + }); + for (const profile of profiles.docs) { + await payload.delete({ collection: "profiles", id: profile.id, overrideAccess: true }); + } await payload.delete({ collection: "users", id: user.id, overrideAccess: true }); } });