forked from EduCraft/curriculum-project-hub
fix(hub): restore project create payload and stabilize integration DB seed
Explorer POST /projects was dropping projectId/folderId/workspaceDir after a narrowed response shape, breaking admin-explorer. Make seedTestOrganization idempotent under shared-DB isolation, force single-worker vitest, and align the OAuth no-membership redirect expectation with authRoutes.
This commit is contained in:
@@ -242,7 +242,8 @@ describe("admin auth + org API guards", () => {
|
||||
headers: { cookie: `${OAUTH_STATE_COOKIE_NAME}=${nonce}` },
|
||||
});
|
||||
expect(res.statusCode).toBe(302);
|
||||
expect(res.headers.location).toBe("/admin");
|
||||
// New users without membership land on login error; session is still set.
|
||||
expect(res.headers.location).toBe("/admin/login?error=no_organization");
|
||||
expect(JSON.stringify(res.headers["set-cookie"])).toContain("cph_session=");
|
||||
|
||||
const user = await prisma.user.findUnique({ where: { feishuOpenId: "ou_new" } });
|
||||
|
||||
@@ -80,42 +80,51 @@ export async function seedTestOrganization(
|
||||
id: string = DEFAULT_ORG_ID,
|
||||
slug: string = "test-default",
|
||||
): Promise<void> {
|
||||
// Serialise generate+inbox against concurrent callers in the same process.
|
||||
// Integration tests share one DB and some files call seed without resetDb.
|
||||
await prisma.$transaction(async (tx) => {
|
||||
await tx.organization.create({
|
||||
data: {
|
||||
id,
|
||||
slug,
|
||||
name: "Test Default Organization",
|
||||
projectSettings: {
|
||||
create: { membersCanCreateProjects: true },
|
||||
},
|
||||
agentRoles: {
|
||||
create: {
|
||||
id: `agent_role_draft_${id}`,
|
||||
roleId: "draft",
|
||||
label: "草稿",
|
||||
sortOrder: 10,
|
||||
isDefault: true,
|
||||
const existing = await tx.organization.findUnique({
|
||||
where: { id },
|
||||
select: { id: true },
|
||||
});
|
||||
if (existing === null) {
|
||||
await tx.organization.create({
|
||||
data: {
|
||||
id,
|
||||
slug,
|
||||
name: "Test Default Organization",
|
||||
projectSettings: {
|
||||
create: { membersCanCreateProjects: true },
|
||||
},
|
||||
agentRoles: {
|
||||
create: {
|
||||
id: `agent_role_draft_${id}`,
|
||||
roleId: "draft",
|
||||
label: "草稿",
|
||||
sortOrder: 10,
|
||||
isDefault: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const inbox = await tx.folder.findFirst({
|
||||
where: { organizationId: id, kind: "SYSTEM_INBOX", archivedAt: null },
|
||||
select: { id: true },
|
||||
});
|
||||
if (inbox === null) {
|
||||
await tx.folder.create({
|
||||
data: {
|
||||
id: `folder_inbox_${id}`,
|
||||
organizationId: id,
|
||||
name: "Inbox",
|
||||
kind: "SYSTEM_INBOX",
|
||||
sortKey: "000000",
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
const inbox = await prisma.folder.findFirst({
|
||||
where: { organizationId: id, kind: "SYSTEM_INBOX", archivedAt: null },
|
||||
select: { id: true },
|
||||
});
|
||||
if (inbox === null) {
|
||||
await prisma.folder.create({
|
||||
data: {
|
||||
id: `folder_inbox_${id}`,
|
||||
organizationId: id,
|
||||
name: "Inbox",
|
||||
kind: "SYSTEM_INBOX",
|
||||
sortKey: "000000",
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/** A logger that discards everything (tests don't need fastify's pino). */
|
||||
|
||||
Reference in New Issue
Block a user