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.
This commit is contained in:
parent
9323a7ce08
commit
2be1081e92
2 changed files with 55 additions and 2 deletions
|
|
@ -196,6 +196,27 @@ describe("Marketplace", () => {
|
||||||
for (const locker of lockers.docs) {
|
for (const locker of lockers.docs) {
|
||||||
await payload.delete({ collection: "locker-storages", id: locker.id, overrideAccess: true });
|
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 });
|
await payload.delete({ collection: "users", id: user.id, overrideAccess: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,29 @@ let payload: Payload;
|
||||||
|
|
||||||
const RUN = `tk-${Date.now().toString(36)}`;
|
const RUN = `tk-${Date.now().toString(36)}`;
|
||||||
|
|
||||||
const makeUser = async (label: string, roles: NonNullable<User["roles"]> = ["user"]): Promise<User> => {
|
// 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<number> => {
|
||||||
|
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<User> => {
|
||||||
const tag = `${RUN}-${label}`;
|
const tag = `${RUN}-${label}`;
|
||||||
|
const roleDocs = await Promise.all(roleSlugs.map((slug) => getRoleDocId(slug)));
|
||||||
return (await payload.create({
|
return (await payload.create({
|
||||||
collection: "users",
|
collection: "users",
|
||||||
data: {
|
data: {
|
||||||
|
|
@ -22,7 +43,7 @@ const makeUser = async (label: string, roles: NonNullable<User["roles"]> = ["use
|
||||||
displayName: label.toUpperCase(),
|
displayName: label.toUpperCase(),
|
||||||
steamId: `7656119${Math.floor(Math.random() * 1e9)}`,
|
steamId: `7656119${Math.floor(Math.random() * 1e9)}`,
|
||||||
password: "Test123",
|
password: "Test123",
|
||||||
roles,
|
roleDocs,
|
||||||
},
|
},
|
||||||
overrideAccess: true,
|
overrideAccess: true,
|
||||||
depth: 0,
|
depth: 0,
|
||||||
|
|
@ -93,6 +114,17 @@ describe("Tickets", () => {
|
||||||
|
|
||||||
for (const user of [reporter, assignee, staff]) {
|
for (const user of [reporter, assignee, staff]) {
|
||||||
if (!user) continue;
|
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 });
|
await payload.delete({ collection: "users", id: user.id, overrideAccess: true });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue