zerobyte/app/test/helpers/backup.ts
Nicolas Meienberger 7bcf380198
Some checks failed
Release Workflow / determine-release-type (push) Has been cancelled
Release Workflow / checks (push) Has been cancelled
Release Workflow / e2e-tests (push) Has been cancelled
Release Workflow / build-images (push) Has been cancelled
Release Workflow / publish-release (push) Has been cancelled
test: fix impossible test scenarios
2026-02-16 23:20:33 +01:00

32 lines
1.1 KiB
TypeScript

import { db } from "~/server/db/db";
import { faker } from "@faker-js/faker";
import { backupSchedulesTable, type BackupScheduleInsert } from "~/server/db/schema";
import { createTestOrganization, ensureTestOrganization, TEST_ORG_ID } from "./organization";
import { createTestVolume } from "./volume";
import { createTestRepository } from "./repository";
export const createTestBackupSchedule = async (overrides: Partial<BackupScheduleInsert> = {}) => {
const organizationId = overrides.organizationId ?? TEST_ORG_ID;
if (organizationId === TEST_ORG_ID) {
await ensureTestOrganization();
} else {
await createTestOrganization({ id: organizationId });
}
const volumeId = overrides.volumeId ?? (await createTestVolume({ organizationId })).id;
const repositoryId = overrides.repositoryId ?? (await createTestRepository({ organizationId })).id;
const backup: BackupScheduleInsert = {
name: faker.system.fileName(),
cronExpression: "0 0 * * *",
repositoryId,
volumeId,
shortId: faker.string.uuid(),
organizationId,
...overrides,
};
const data = await db.insert(backupSchedulesTable).values(backup).returning();
return data[0];
};