* Revert "Revert "chore: Chore team metadata table + isOrganization migration from metadata (#12828)""
This reverts commit 2408338ed4.
* Remove constraint slug,isOrganization and reset migration
* fix: conflicts
* change schema to bust cache
* Fix issues reported by TS
* change schema to bust cache
* Review fixes
* Colaesce for orgAutoAcceptEmail as well
* Fix missing negation
---------
Co-authored-by: zomars <zomars@me.com>
Co-authored-by: Peer Richelsen <peeroke@gmail.com>
Co-authored-by: Keith Williams <keithwillcode@gmail.com>
Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com>
65 lines
1.7 KiB
TypeScript
65 lines
1.7 KiB
TypeScript
import type { Page } from "@playwright/test";
|
|
import type { Team } from "@prisma/client";
|
|
|
|
import { prisma } from "@calcom/prisma";
|
|
import { teamMetadataSchema } from "@calcom/prisma/zod-utils";
|
|
|
|
const getRandomSlug = () => `org-${Math.random().toString(36).substring(7)}`;
|
|
|
|
// creates a user fixture instance and stores the collection
|
|
export const createOrgsFixture = (page: Page) => {
|
|
const store = { orgs: [], page } as { orgs: Team[]; page: typeof page };
|
|
return {
|
|
create: async (opts: { name: string; slug?: string; requestedSlug?: string }) => {
|
|
const org = await createOrgInDb({
|
|
name: opts.name,
|
|
slug: opts.slug || getRandomSlug(),
|
|
requestedSlug: opts.requestedSlug,
|
|
});
|
|
const orgWithMetadata = {
|
|
...org,
|
|
metadata: teamMetadataSchema.parse(org.metadata),
|
|
};
|
|
store.orgs.push(orgWithMetadata);
|
|
return orgWithMetadata;
|
|
},
|
|
get: () => store.orgs,
|
|
deleteAll: async () => {
|
|
await prisma.team.deleteMany({ where: { id: { in: store.orgs.map((org) => org.id) } } });
|
|
store.orgs = [];
|
|
},
|
|
delete: async (id: number) => {
|
|
await prisma.team.delete({ where: { id } });
|
|
store.orgs = store.orgs.filter((b) => b.id !== id);
|
|
},
|
|
};
|
|
};
|
|
|
|
export async function createOrgInDb({
|
|
name,
|
|
slug,
|
|
requestedSlug,
|
|
}: {
|
|
name: string;
|
|
slug: string | null;
|
|
requestedSlug?: string;
|
|
}) {
|
|
return await prisma.team.create({
|
|
data: {
|
|
name: name,
|
|
slug: slug,
|
|
isOrganization: true,
|
|
metadata: {
|
|
...(requestedSlug
|
|
? {
|
|
requestedSlug,
|
|
}
|
|
: null),
|
|
},
|
|
},
|
|
include: {
|
|
organizationSettings: true,
|
|
},
|
|
});
|
|
}
|