1import * as AWS from "@/AWS";
2import { BasePathMapping } from "@/AWS/ApiGateway/BasePathMapping";
3import * as Provider from "@/Provider";
4import * as Test from "./Test.ts";
5import { expect } from "alchemy-test";
6import * as Effect from "effect/Effect";
7import { assertRestApiDeleted } from "./assertions.ts";
8
9const { 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
18const testDomainName = process.env.AWS_TEST_APIGATEWAY_DOMAIN;
19const testCertificateArn = process.env.AWS_TEST_ACM_CERTIFICATE_ARN;
20
21test.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
38test.provider.skipIf(
39 !!process.env.FAST || !testDomainName || !testCertificateArn,
40)(
41 "list includes a deployed base path mapping",
42 (stack) =>
43 Effect.gen(function* () {
44 yield* stack.destroy();
45
46 const deployed = yield* stack.deploy(
47 Effect.gen(function* () {
48 const api = yield* AWS.ApiGateway.RestApi("BpmListApi", {
49 endpointConfiguration: { types: ["REGIONAL"] },
50 });
51
52 yield* AWS.ApiGateway.Method("BpmListRootGet", {
53 restApi: api,
54 httpMethod: "GET",
55 authorizationType: "NONE",
56 integration: { type: "MOCK" },
57 });
58
59 const deployment = yield* AWS.ApiGateway.Deployment("BpmListDep", {
60 restApi: api,
61 description: "list test",
62 });
63
64 const stage = yield* AWS.ApiGateway.Stage("BpmListStage", {
65 restApi: api,
66 stageName: "test",
67 deploymentId: deployment.deploymentId,
68 });
69
70 const domain = yield* AWS.ApiGateway.DomainName("BpmListDomain", {
71 domainName: testDomainName!,
72 regionalCertificateArn: testCertificateArn!,
73 endpointConfiguration: { types: ["REGIONAL"] },
74 securityPolicy: "TLS_1_2",
75 });
76
77 return yield* BasePathMapping("BpmListMapping", {
78 domainName: domain.domainName,
79 restApiId: api.restApiId,
80 stage: stage.stageName,
81 });
82 }),
83 );
84
85 const provider = yield* Provider.findProvider(BasePathMapping);
86 const all = yield* provider.list();
87
88 expect(
89 all.some(
90 (m) =>
91 m.domainName === deployed.domainName &&
92 m.basePath === deployed.basePath &&
93 m.restApiId === deployed.restApiId,
94 ),
95 ).toBe(true);
96
97 yield* stack.destroy();
98 yield* assertRestApiDeleted(deployed.restApiId);
99 }),
100 {
101 tags: ["provider:aws", "provider:aws:apigateway", "live"],
102 timeout: 600_000,
103 },
104);