| 1 | import * as AWS from "@/AWS"; |
| 2 | import { MethodResource } from "@/AWS/ApiGateway/Method.ts"; |
| 3 | import * as Provider from "@/Provider"; |
| 4 | import * as Test from "./Test.ts"; |
| 5 | import * as ag from "@distilled.cloud/aws/api-gateway"; |
| 6 | import { expect } from "alchemy-test"; |
| 7 | import * as Effect from "effect/Effect"; |
| 8 | import { assertRestApiDeleted } from "./assertions.ts"; |
| 9 | |
| 10 | const { test } = Test.make({ providers: AWS.providers() }); |
| 11 | |
| 12 | test.provider.skipIf(!!process.env.FAST)( |
| 13 | "create and delete MOCK method", |
| 14 | (stack) => |
| 15 | Effect.gen(function* () { |
| 16 | yield* stack.destroy(); |
| 17 | |
| 18 | const { api } = yield* stack.deploy( |
| 19 | Effect.gen(function* () { |
| 20 | const api = yield* AWS.ApiGateway.RestApi("AgMethodApi", { |
| 21 | endpointConfiguration: { types: ["REGIONAL"] }, |
| 22 | }); |
| 23 | yield* AWS.ApiGateway.Method("AgMockGet", { |
| 24 | restApi: api, |
| 25 | httpMethod: "GET", |
| 26 | authorizationType: "NONE", |
| 27 | integration: { |
| 28 | type: "MOCK", |
| 29 | requestTemplates: { "application/json": '{"statusCode": 200}' }, |
| 30 | }, |
| 31 | }); |
| 32 | return { api }; |
| 33 | }), |
| 34 | ); |
| 35 | |
| 36 | const method = yield* ag.getMethod({ |
| 37 | restApiId: api.restApiId, |
| 38 | resourceId: api.rootResourceId, |
| 39 | httpMethod: "GET", |
| 40 | }); |
| 41 | expect(method.httpMethod).toEqual("GET"); |
| 42 | |
| 43 | yield* stack.destroy(); |
| 44 | yield* assertRestApiDeleted(api.restApiId); |
| 45 | }), |
| 46 | { tags: ["provider:aws", "provider:aws:apigateway", "live"] }, |
| 47 | ); |
| 48 | |
| 49 | // Canonical `list()` test: deploy a RestApi + Method (parents included), then |
| 50 | // enumerate every method across all RestApis via the typed provider and assert |
| 51 | // the deployed method appears with its full Attributes shape. |
| 52 | test.provider.skipIf(!!process.env.FAST)( |
| 53 | "list enumerates the deployed method", |
| 54 | (stack) => |
| 55 | Effect.gen(function* () { |
| 56 | yield* stack.destroy(); |
| 57 | |
| 58 | const { api } = yield* stack.deploy( |
| 59 | Effect.gen(function* () { |
| 60 | const api = yield* AWS.ApiGateway.RestApi("AgMethodListApi", { |
| 61 | endpointConfiguration: { types: ["REGIONAL"] }, |
| 62 | }); |
| 63 | yield* AWS.ApiGateway.Method("AgListMockGet", { |
| 64 | restApi: api, |
| 65 | httpMethod: "GET", |
| 66 | authorizationType: "NONE", |
| 67 | integration: { |
| 68 | type: "MOCK", |
| 69 | requestTemplates: { "application/json": '{"statusCode": 200}' }, |
| 70 | }, |
| 71 | }); |
| 72 | return { api }; |
| 73 | }), |
| 74 | ); |
| 75 | |
| 76 | const provider = yield* Provider.findProvider(MethodResource); |
| 77 | const all = yield* provider.list(); |
| 78 | |
| 79 | expect( |
| 80 | all.some( |
| 81 | (m) => |
| 82 | m.restApiId === api.restApiId && |
| 83 | m.resourceId === api.rootResourceId && |
| 84 | m.httpMethod === "GET", |
| 85 | ), |
| 86 | ).toBe(true); |
| 87 | |
| 88 | yield* stack.destroy(); |
| 89 | yield* assertRestApiDeleted(api.restApiId); |
| 90 | }), |
| 91 | { tags: ["provider:aws", "provider:aws:apigateway", "live"] }, |
| 92 | ); |