| 1 | import * as AWS from "@/AWS"; |
| 2 | import { DomainName } from "@/AWS/ApiGateway"; |
| 3 | import * as Provider from "@/Provider"; |
| 4 | import * as Test from "./Test.ts"; |
| 5 | import { expect } from "alchemy-test"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | import { assertDomainNameDeleted } from "./assertions.ts"; |
| 8 | |
| 9 | const { test } = Test.make({ providers: AWS.providers() }); |
| 10 | |
| 11 | // Ungated live probe: `list()` enumerates every custom domain in the |
| 12 | // account/region. It paginates `getDomainNames` exhaustively and maps each item |
| 13 | // to the same Attributes shape `read` returns. We don't deploy here because an |
| 14 | // API Gateway custom domain can't be provisioned in CI (see the gated test |
| 15 | // below) — but this still verifies the pagination + mapping against the live |
| 16 | // API and asserts every returned row is well-formed. |
| 17 | test.provider.skipIf(!!process.env.FAST)( |
| 18 | "list returns the account/region domain names", |
| 19 | () => |
| 20 | Effect.gen(function* () { |
| 21 | const provider = yield* Provider.findProvider(DomainName); |
| 22 | const all = yield* provider.list(); |
| 23 | |
| 24 | expect(Array.isArray(all)).toBe(true); |
| 25 | for (const d of all) { |
| 26 | expect(typeof d.domainName).toBe("string"); |
| 27 | expect(d.tags).toBeDefined(); |
| 28 | } |
| 29 | }), |
| 30 | { tags: ["provider:aws", "provider:aws:apigateway", "live"] }, |
| 31 | ); |
| 32 | |
| 33 | // Full deploy-then-list assertion. SKIPPED by default because an API Gateway |
| 34 | // custom domain requires a certificate that AWS accepts: |
| 35 | // - EDGE + uploaded cert -> CloudFront rejects a self-signed cert: |
| 36 | // BadRequestException "The certificate that is attached to your |
| 37 | // distribution was not issued by a trusted Certificate Authority." |
| 38 | // - REGIONAL -> requires an ACM `regionalCertificateArn` for a |
| 39 | // domain you own (ACM issuance needs DNS/email validation). |
| 40 | // Set AWS_TEST_APIGATEWAY_DOMAIN_NAME (a domain you own) and |
| 41 | // AWS_TEST_APIGATEWAY_CERT_ARN (a validated regional ACM cert in this region) |
| 42 | // to run it on an entitled account unchanged. |
| 43 | const domainName = process.env.AWS_TEST_APIGATEWAY_DOMAIN_NAME; |
| 44 | const certificateArn = process.env.AWS_TEST_APIGATEWAY_CERT_ARN; |
| 45 | |
| 46 | test.provider.skipIf(!!process.env.FAST || !domainName || !certificateArn)( |
| 47 | "list enumerates the deployed domain name", |
| 48 | (stack) => |
| 49 | Effect.gen(function* () { |
| 50 | yield* stack.destroy(); |
| 51 | |
| 52 | const domain = yield* stack.deploy( |
| 53 | Effect.gen(function* () { |
| 54 | return yield* DomainName("ListDomain", { |
| 55 | domainName: domainName!, |
| 56 | regionalCertificateArn: certificateArn!, |
| 57 | endpointConfiguration: { types: ["REGIONAL"] }, |
| 58 | securityPolicy: "TLS_1_2", |
| 59 | }); |
| 60 | }), |
| 61 | ); |
| 62 | |
| 63 | const provider = yield* Provider.findProvider(DomainName); |
| 64 | const all = yield* provider.list(); |
| 65 | |
| 66 | expect(all.some((d) => d.domainName === domain.domainName)).toBe(true); |
| 67 | |
| 68 | yield* stack.destroy(); |
| 69 | yield* assertDomainNameDeleted(domain.domainName); |
| 70 | }), |
| 71 | { tags: ["provider:aws", "provider:aws:apigateway", "live"] }, |
| 72 | ); |