-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp-presenter.test.ts
More file actions
278 lines (256 loc) · 7.79 KB
/
Copy pathapp-presenter.test.ts
File metadata and controls
278 lines (256 loc) · 7.79 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
import { describe, expect, it } from "vitest";
import {
renderAppDeploy,
renderAppDeployAll,
renderAppDomainAdd,
renderAppDomainRetry,
renderAppDomainShow,
serializeAppDeploy,
} from "../src/presenters/app";
import { getCommandDescriptor } from "../src/shell/command-meta";
import type {
AppDeployResult,
AppDomainAddResult,
AppDomainRetryResult,
AppDomainShowResult,
AppDomainSummary,
} from "../src/types/app";
import { createTestCommandContext } from "./helpers";
function createDomain(
overrides: Partial<AppDomainSummary> = {},
): AppDomainSummary {
return {
id: "dom_123",
type: "custom-domain",
url: "https://api.prisma.io/v1/domains/dom_123",
hostname: "shop.acme.com",
appId: "app_1",
status: "pending_dns",
foundryStatus: "pending",
failureReason: null,
failureCategory: null,
certExpiresAt: null,
createdAt: "2026-05-22T09:14:00.000Z",
updatedAt: "2026-05-22T09:14:00.000Z",
dnsRecords: [
{
type: "CNAME",
name: "shop.acme.com",
value: "switchboard.fra.prisma.build",
ttl: 300,
},
],
...overrides,
};
}
function createTarget() {
return {
workspace: { id: "ws_123", name: "Acme Inc" },
project: { id: "proj_123", name: "Acme Dashboard" },
branch: { name: "production", kind: "production" as const },
app: { id: "app_1", name: "shop" },
};
}
function createDeployResult(): AppDeployResult {
return {
workspace: { id: "wksp_123", name: "Prisma Team" },
project: { id: "proj_123", name: "Billing API" },
branch: { id: "br_main", name: "main", kind: "production" },
resolution: {
projectSource: "local-pin",
targetName: "Billing API",
targetNameSource: "local-pin",
},
app: { id: "app_123", name: "api" },
deployment: {
id: "dep_123",
status: "running",
url: "https://api.prisma.build",
},
deploySettings: {
config: {
path: null,
status: "inferred",
},
buildCommand: {
value: "bun run build",
source: null,
},
outputDirectory: {
value: ".",
source: null,
},
framework: {
key: "hono",
buildType: "bun",
name: "Hono",
source: "detected from package.json",
},
entrypoint: "src/index.ts",
httpPort: 8080,
region: "fra",
envVars: ["DATABASE_URL"],
},
durationMs: 12_345,
localPin: {
path: ".prisma/local.json",
written: true,
},
};
}
describe("app domain presenters", () => {
it("shows when DNS records were not provided by the platform", async () => {
const { context } = await createTestCommandContext({});
const result: AppDomainAddResult = {
...createTarget(),
domain: createDomain({ dnsRecords: [] }),
existing: false,
};
const lines = renderAppDomainAdd(
context,
getCommandDescriptor("app.domain.add"),
result,
).join("\n");
expect(lines).toContain("dns record");
expect(lines).toContain("not provided by platform");
expect(lines).not.toContain("switchboard.fra.prisma.build");
});
it("does not print CNAME fixes for certificate failures", async () => {
const { context } = await createTestCommandContext({});
const result: AppDomainShowResult = {
...createTarget(),
domain: createDomain({
status: "failed",
failureCategory: "acme",
failureReason: "Certificate issuance failed",
}),
};
const lines = renderAppDomainShow(
context,
getCommandDescriptor("app.domain.show"),
result,
).join("\n");
expect(lines).toContain("Retry TLS issuance");
expect(lines).not.toContain("Add CNAME");
});
it("renders failure categories without reasons as errors", async () => {
const { context } = await createTestCommandContext({});
context.ui.error = (text) => `error(${text})`;
context.ui.dim = (text) => `dim(${text})`;
const result: AppDomainShowResult = {
...createTarget(),
domain: createDomain({
status: "failed",
failureCategory: "acme",
failureReason: null,
}),
};
const lines = renderAppDomainShow(
context,
getCommandDescriptor("app.domain.show"),
result,
).join("\n");
expect(lines).toContain("error(acme)");
expect(lines).not.toContain("dim(acme)");
});
it("includes DNS and recovery guidance in retry output", async () => {
const { context } = await createTestCommandContext({});
const result: AppDomainRetryResult = {
...createTarget(),
domain: createDomain({
status: "failed",
failureCategory: "dns",
failureReason: "CNAME record not found",
}),
};
const lines = renderAppDomainRetry(
context,
getCommandDescriptor("app.domain.retry"),
result,
).join("\n");
expect(lines).toContain("dns record");
expect(lines).toContain(
"CNAME shop.acme.com -> switchboard.fra.prisma.build ttl 300",
);
expect(lines).toContain(
"Add CNAME shop.acme.com -> switchboard.fra.prisma.build, then run prisma-cli app domain retry shop.acme.com.",
);
});
});
describe("app deploy presenter", () => {
it("adds safe resolved context when verbose output is enabled", async () => {
const { context } = await createTestCommandContext({
flags: { verbose: true },
env: { ...process.env, HOME: "/Users/aman" },
cwd: "/Users/aman/dev/app",
});
const result = createDeployResult();
const lines = renderAppDeploy(
context,
getCommandDescriptor("app.deploy"),
result,
).join("\n");
expect(lines).toContain("Resolved context:");
expect(lines).toContain("workspace:");
expect(lines).toContain("Prisma Team");
expect(lines).toContain("project source:");
expect(lines).toContain(".prisma/local.json");
expect(lines).toContain("branch id:");
expect(lines).toContain("br_main");
expect(lines).toContain("deploy duration:");
expect(lines).toContain("Deploy settings:");
expect(lines).toContain("framework:");
expect(lines).toContain("Hono (bun)");
expect(lines).toContain("entrypoint:");
expect(lines).toContain("src/index.ts");
expect(lines).toContain("http port:");
expect(lines).toContain("8080");
expect(lines).toContain("env vars:");
expect(lines).toContain("DATABASE_URL");
expect(lines).not.toContain("postgresql://");
});
it("names each target in the deploy-all logs hints", async () => {
const { context } = await createTestCommandContext({});
const lines = renderAppDeployAll(
context,
getCommandDescriptor("app.deploy"),
{
deployments: [
{ target: "api", result: createDeployResult() },
{ target: "web", result: createDeployResult() },
],
},
).join("\n");
expect(lines).toContain("prisma-cli app logs api");
expect(lines).toContain("prisma-cli app logs web");
expect(lines).not.toMatch(/prisma-cli app logs$/m);
});
it("keeps verbose-only deploy details out of JSON serialization", () => {
const json = JSON.parse(
JSON.stringify(serializeAppDeploy(createDeployResult())),
);
expect(json.deploySettings).toEqual({
config: {
path: null,
status: "inferred",
},
buildCommand: {
value: "bun run build",
source: null,
},
outputDirectory: {
value: ".",
source: null,
},
});
expect(json.deploySettings).not.toHaveProperty("framework");
expect(json.deploySettings).not.toHaveProperty("entrypoint");
expect(json.deploySettings).not.toHaveProperty("httpPort");
expect(json).not.toHaveProperty("localPin");
expect(json.branch).toEqual({
name: "main",
kind: "production",
});
expect(json.branch).not.toHaveProperty("id");
});
});