The best way to control Claude Code, Codex and more from any computer or phone

main
ts 99 lines 3.48 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { BasePathMapping } from "@alchemy.run/aws/ApiGateway/BasePathMapping";
3 import { expect } from "@alchemy.run/test";
4 import * as Provider from "alchemy/Provider";
5 import * as Effect from "effect/Effect";
6 import { assertRestApiDeleted } from "./assertions.ts";
7 import * as Test from "./Test.ts";
8
9 const { test } = Test.make({ providers: AWS.providers() });
10
11 // A custom DomainName (the parent of a BasePathMapping) requires a validated
12 // ACM certificate + DNS, which cannot be provisioned in CI — that is why
13 // DomainName.test.ts is skipped. The full deploy+assert flow is therefore
14 // gated behind env vars pointing at a pre-provisioned domain/cert. The
15 // ungated test below still exercises `list()` live (it enumerates every
16 // domain name and its mappings) to prove the operation works end-to-end.
17
18 const testDomainName = process.env.AWS_TEST_APIGATEWAY_DOMAIN;
19 const testCertificateArn = process.env.AWS_TEST_ACM_CERTIFICATE_ARN;
20
21 test.provider.skipIf(!!process.env.FAST)(
22 "list enumerates base path mappings across domains",
23 () =>
24 Effect.gen(function* () {
25 const provider = yield* Provider.findProvider(BasePathMapping);
26 const all = yield* provider.list();
27
28 expect(Array.isArray(all)).toBe(true);
29 for (const m of all) {
30 expect(typeof m.domainName).toBe("string");
31 expect(typeof m.basePath).toBe("string");
32 expect(typeof m.restApiId).toBe("string");
33 }
34 }),
35 { tags: ["provider:aws", "provider:aws:apigateway", "live"] },
36 );
37
38 test.provider.skipIf(!!process.env.FAST || !testDomainName || !testCertificateArn)(
39 "list includes a deployed base path mapping",
40 (stack) =>
41 Effect.gen(function* () {
42 yield* stack.destroy();
43
44 const deployed = yield* stack.deploy(
45 Effect.gen(function* () {
46 const api = yield* AWS.ApiGateway.RestApi("BpmListApi", {
47 endpointConfiguration: { types: ["REGIONAL"] },
48 });
49
50 yield* AWS.ApiGateway.Method("BpmListRootGet", {
51 restApi: api,
52 httpMethod: "GET",
53 authorizationType: "NONE",
54 integration: { type: "MOCK" },
55 });
56
57 const deployment = yield* AWS.ApiGateway.Deployment("BpmListDep", {
58 restApi: api,
59 description: "list test",
60 });
61
62 const stage = yield* AWS.ApiGateway.Stage("BpmListStage", {
63 restApi: api,
64 stageName: "test",
65 deploymentId: deployment.deploymentId,
66 });
67
68 const domain = yield* AWS.ApiGateway.DomainName("BpmListDomain", {
69 domainName: testDomainName!,
70 regionalCertificateArn: testCertificateArn!,
71 endpointConfiguration: { types: ["REGIONAL"] },
72 securityPolicy: "TLS_1_2",
73 });
74
75 return yield* BasePathMapping("BpmListMapping", {
76 domainName: domain.domainName,
77 restApiId: api.restApiId,
78 stage: stage.stageName,
79 });
80 }),
81 );
82
83 const provider = yield* Provider.findProvider(BasePathMapping);
84 const all = yield* provider.list();
85
86 expect(
87 all.some(
88 (m) =>
89 m.domainName === deployed.domainName &&
90 m.basePath === deployed.basePath &&
91 m.restApiId === deployed.restApiId,
92 ),
93 ).toBe(true);
94
95 yield* stack.destroy();
96 yield* assertRestApiDeleted(deployed.restApiId);
97 }),
98 { tags: ["provider:aws", "provider:aws:apigateway", "live"], timeout: 600_000 },
99 );