-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathseedTestEnvironment.ts
More file actions
50 lines (43 loc) · 1.46 KB
/
seedTestEnvironment.ts
File metadata and controls
50 lines (43 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import type { PrismaClient } from "@trigger.dev/database";
import { randomBytes } from "crypto";
function randomHex(len = 12): string {
return randomBytes(Math.ceil(len / 2)).toString("hex").slice(0, len);
}
export async function seedTestEnvironment(prisma: PrismaClient) {
const suffix = randomHex(8);
const apiKey = `tr_dev_${randomHex(24)}`;
const pkApiKey = `pk_dev_${randomHex(24)}`;
const t0 = Date.now();
process.stderr.write(`[seed] creating organization (${suffix})...\n`);
const organization = await prisma.organization.create({
data: {
title: `e2e-test-org-${suffix}`,
slug: `e2e-org-${suffix}`,
v3Enabled: true,
},
});
process.stderr.write(`[seed] organization created in ${Date.now() - t0}ms\n`);
const project = await prisma.project.create({
data: {
name: `e2e-test-project-${suffix}`,
slug: `e2e-proj-${suffix}`,
externalRef: `proj_${suffix}`,
organizationId: organization.id,
engine: "V2",
},
});
process.stderr.write(`[seed] project created in ${Date.now() - t0}ms\n`);
const environment = await prisma.runtimeEnvironment.create({
data: {
slug: "dev",
type: "DEVELOPMENT",
apiKey,
pkApiKey,
shortcode: suffix.slice(0, 4),
projectId: project.id,
organizationId: organization.id,
},
});
process.stderr.write(`[seed] environment created in ${Date.now() - t0}ms\n`);
return { organization, project, environment, apiKey };
}