Files
zerobyte/app/test/helpers/organization.ts
Nico 35773a6969 refactor: upgrade to drizzle v1 (#450)
* refactor: move migrations to new structure

* refactor: convert all findMany to new structure

* fix(backups-schedule): missing null matching for last backup status

* chore: move root lib to server
2026-02-01 19:14:52 +01:00

36 lines
929 B
TypeScript

import { db } from "~/server/db/db";
import { organization, type OrganizationMetadata } from "~/server/db/schema";
import { faker } from "@faker-js/faker";
export const TEST_ORG_ID = "test-org-00000001";
export const createTestOrganization = async (overrides: Partial<typeof organization.$inferInsert> = {}) => {
const metadata: OrganizationMetadata = {
resticPassword: "test-encrypted-restic-password",
};
const org: typeof organization.$inferInsert = {
id: TEST_ORG_ID,
name: "Test Organization",
slug: `test-org-${faker.string.alphanumeric(6)}`,
createdAt: new Date(),
metadata,
...overrides,
};
const existing = await db.query.organization.findFirst({
where: { id: org.id },
});
if (existing) {
return existing;
}
const data = await db.insert(organization).values(org).returning();
return data[0];
};
export const ensureTestOrganization = async () => {
return createTestOrganization();
};