| 1 | import * as AWS from "@/AWS"; |
| 2 | import * as Provider from "@/Provider"; |
| 3 | import * as Test from "./Test.ts"; |
| 4 | import * as ag from "@distilled.cloud/aws/api-gateway"; |
| 5 | import { expect } from "alchemy-test"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | import { assertRestApiDeleted } from "./assertions.ts"; |
| 8 | |
| 9 | const { test } = Test.make({ providers: AWS.providers() }); |
| 10 | |
| 11 | // Both resource cases require the same parent and child shape. Keep their |
| 12 | // out-of-band read and provider-list assertions in one lifecycle so the |
| 13 | // regional DeleteRestApi throttle is crossed once rather than twice. |
| 14 | test.provider.skipIf(!!process.env.FAST)( |
| 15 | "API Gateway resource lifecycle and list", |
| 16 | (stack) => |
| 17 | Effect.gen(function* () { |
| 18 | yield* stack.destroy(); |
| 19 | |
| 20 | const { api, res } = yield* stack.deploy( |
| 21 | Effect.gen(function* () { |
| 22 | const api = yield* AWS.ApiGateway.RestApi("AgResApi", { |
| 23 | endpointConfiguration: { types: ["REGIONAL"] }, |
| 24 | }); |
| 25 | const res = yield* AWS.ApiGateway.Resource("AgSubPath", { |
| 26 | restApi: api, |
| 27 | parentId: api.rootResourceId, |
| 28 | pathPart: "items", |
| 29 | }); |
| 30 | return { api, res }; |
| 31 | }), |
| 32 | ); |
| 33 | |
| 34 | const remote = yield* ag.getResource({ |
| 35 | restApiId: api.restApiId, |
| 36 | resourceId: res.resourceId, |
| 37 | }); |
| 38 | expect(remote.pathPart).toEqual("items"); |
| 39 | |
| 40 | const provider = yield* Provider.findProvider( |
| 41 | AWS.ApiGateway.GatewayResource, |
| 42 | ); |
| 43 | const all = yield* provider.list(); |
| 44 | expect(all.some((r) => r.resourceId === res.resourceId)).toBe(true); |
| 45 | |
| 46 | yield* stack.destroy(); |
| 47 | yield* assertRestApiDeleted(api.restApiId); |
| 48 | }), |
| 49 | { tags: ["provider:aws", "provider:aws:apigateway", "live"] }, |
| 50 | ); |