1import * as AWS from "@/AWS";
2import * as Provider from "@/Provider";
3import * as Test from "./Test.ts";
4import * as ag from "@distilled.cloud/aws/api-gateway";
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// DeleteRestApi has a hard regional quota of roughly one request every 30s.
12// Exercise create/read/list and both directions of the mutable media-type
13// lifecycle on one deterministic API rather than provisioning and deleting
14// four equivalent parents. Every former assertion remains out-of-band; the
15// file now pays the deletion wall once.
16test.provider.skipIf(!!process.env.FAST)(
17 "REST API lifecycle, binary media updates, and list",
18 (stack) =>
19 Effect.gen(function* () {
20 yield* stack.destroy();
21
22 const api = yield* stack.deploy(
23 Effect.gen(function* () {
24 return yield* AWS.ApiGateway.RestApi("AgRestApiLifecycle", {
25 endpointConfiguration: { types: ["REGIONAL"] },
26 binaryMediaTypes: ["application/octet-stream"],
27 });
28 }),
29 );
30
31 expect(api.restApiId).toBeDefined();
32 expect(api.rootResourceId).toBeDefined();
33 expect(api.binaryMediaTypes?.includes("application/octet-stream")).toBe(
34 true,
35 );
36
37 const created = yield* ag.getRestApi({ restApiId: api.restApiId });
38 expect(created.id).toEqual(api.restApiId);
39
40 const provider = yield* Provider.findProvider(AWS.ApiGateway.RestApi);
41 const all = yield* provider.list();
42 expect(all.some((a) => a.restApiId === api.restApiId)).toBe(true);
43
44 yield* stack.deploy(
45 Effect.gen(function* () {
46 return yield* AWS.ApiGateway.RestApi("AgRestApiLifecycle", {
47 endpointConfiguration: { types: ["REGIONAL"] },
48 binaryMediaTypes: ["application/octet-stream", "image/png"],
49 });
50 }),
51 );
52
53 const widened = yield* ag.getRestApi({ restApiId: api.restApiId });
54 expect(widened.binaryMediaTypes?.includes("image/png")).toBe(true);
55
56 yield* stack.deploy(
57 Effect.gen(function* () {
58 return yield* AWS.ApiGateway.RestApi("AgRestApiLifecycle", {
59 endpointConfiguration: { types: ["REGIONAL"] },
60 binaryMediaTypes: ["image/png"],
61 });
62 }),
63 );
64
65 const narrowed = yield* ag.getRestApi({ restApiId: api.restApiId });
66 expect(narrowed.binaryMediaTypes?.includes("image/png")).toBe(true);
67 expect(
68 narrowed.binaryMediaTypes?.includes("application/octet-stream"),
69 ).toBe(false);
70
71 yield* stack.destroy();
72 yield* assertRestApiDeleted(api.restApiId);
73 }),
74 { tags: ["provider:aws", "provider:aws:apigateway", "live"] },
75);