The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as AWS from "@alchemy.run/aws"; |
| 2 | import { expect } from "@alchemy.run/test"; |
| 3 | import * as ag from "@distilled.cloud/aws/api-gateway"; |
| 4 | import * as Provider from "alchemy/Provider"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { assertRestApiDeleted } from "./assertions.ts"; |
| 7 | import * as Test from "./Test.ts"; |
| 8 | |
| 9 | const { test } = Test.make({ providers: AWS.providers() }); |
| 10 | |
| 11 | test.provider.skipIf(!!process.env.FAST)( |
| 12 | "create and delete gateway response", |
| 13 | (stack) => |
| 14 | Effect.gen(function* () { |
| 15 | yield* stack.destroy(); |
| 16 | |
| 17 | const { api } = yield* stack.deploy( |
| 18 | Effect.gen(function* () { |
| 19 | const api = yield* AWS.ApiGateway.RestApi("AgGwRespApi", { |
| 20 | endpointConfiguration: { types: ["REGIONAL"] }, |
| 21 | }); |
| 22 | yield* AWS.ApiGateway.GatewayResponse("AgDefault4xx", { |
| 23 | restApiId: api.restApiId, |
| 24 | responseType: "DEFAULT_4XX", |
| 25 | responseTemplates: { "application/json": '{"message":"test"}' }, |
| 26 | }); |
| 27 | return { api }; |
| 28 | }), |
| 29 | ); |
| 30 | |
| 31 | const g = yield* ag.getGatewayResponse({ |
| 32 | restApiId: api.restApiId, |
| 33 | responseType: "DEFAULT_4XX", |
| 34 | }); |
| 35 | expect(g.responseType).toEqual("DEFAULT_4XX"); |
| 36 | |
| 37 | yield* stack.destroy(); |
| 38 | yield* assertRestApiDeleted(api.restApiId); |
| 39 | }), |
| 40 | { tags: ["provider:aws", "provider:aws:apigateway", "live"] }, |
| 41 | ); |
| 42 | |
| 43 | test.provider.skipIf(!!process.env.FAST)( |
| 44 | "update gateway response status and templates", |
| 45 | (stack) => |
| 46 | Effect.gen(function* () { |
| 47 | yield* stack.destroy(); |
| 48 | |
| 49 | const { api } = yield* stack.deploy( |
| 50 | Effect.gen(function* () { |
| 51 | const api = yield* AWS.ApiGateway.RestApi("AgGwRespUpdateApi", { |
| 52 | endpointConfiguration: { types: ["REGIONAL"] }, |
| 53 | }); |
| 54 | yield* AWS.ApiGateway.GatewayResponse("AgDefault5xx", { |
| 55 | restApiId: api.restApiId, |
| 56 | responseType: "DEFAULT_5XX", |
| 57 | statusCode: "500", |
| 58 | responseTemplates: { "application/json": '{"message":"v1"}' }, |
| 59 | }); |
| 60 | return { api }; |
| 61 | }), |
| 62 | ); |
| 63 | |
| 64 | yield* stack.deploy( |
| 65 | Effect.gen(function* () { |
| 66 | const apiAgain = yield* AWS.ApiGateway.RestApi("AgGwRespUpdateApi", { |
| 67 | endpointConfiguration: { types: ["REGIONAL"] }, |
| 68 | }); |
| 69 | yield* AWS.ApiGateway.GatewayResponse("AgDefault5xx", { |
| 70 | restApiId: apiAgain.restApiId, |
| 71 | responseType: "DEFAULT_5XX", |
| 72 | statusCode: "502", |
| 73 | responseTemplates: { "application/json": '{"message":"v2"}' }, |
| 74 | }); |
| 75 | }), |
| 76 | ); |
| 77 | |
| 78 | const g = yield* ag.getGatewayResponse({ |
| 79 | restApiId: api.restApiId, |
| 80 | responseType: "DEFAULT_5XX", |
| 81 | }); |
| 82 | expect(g.statusCode).toEqual("502"); |
| 83 | expect(g.responseTemplates?.["application/json"]).toEqual('{"message":"v2"}'); |
| 84 | |
| 85 | yield* stack.destroy(); |
| 86 | yield* assertRestApiDeleted(api.restApiId); |
| 87 | }), |
| 88 | // Three sequential deploy/destroy cycles against API Gateway's account-wide |
| 89 | // throttle: ~95s alone, >120s under a saturated full-suite run. |
| 90 | { tags: ["provider:aws", "provider:aws:apigateway", "live"], timeout: 240_000 }, |
| 91 | ); |
| 92 | |
| 93 | test.provider.skipIf(!!process.env.FAST)( |
| 94 | "list enumerates the deployed gateway response", |
| 95 | (stack) => |
| 96 | Effect.gen(function* () { |
| 97 | yield* stack.destroy(); |
| 98 | |
| 99 | const { api } = yield* stack.deploy( |
| 100 | Effect.gen(function* () { |
| 101 | const api = yield* AWS.ApiGateway.RestApi("AgGwRespListApi", { |
| 102 | endpointConfiguration: { types: ["REGIONAL"] }, |
| 103 | }); |
| 104 | yield* AWS.ApiGateway.GatewayResponse("AgListDefault4xx", { |
| 105 | restApiId: api.restApiId, |
| 106 | responseType: "DEFAULT_4XX", |
| 107 | responseTemplates: { "application/json": '{"message":"list"}' }, |
| 108 | }); |
| 109 | return { api }; |
| 110 | }), |
| 111 | ); |
| 112 | |
| 113 | const provider = yield* Provider.findProvider(AWS.ApiGateway.GatewayResponse); |
| 114 | const all = yield* provider.list(); |
| 115 | |
| 116 | expect( |
| 117 | all.some((g) => g.restApiId === api.restApiId && g.responseType === "DEFAULT_4XX"), |
| 118 | ).toBe(true); |
| 119 | |
| 120 | yield* stack.destroy(); |
| 121 | yield* assertRestApiDeleted(api.restApiId); |
| 122 | }), |
| 123 | { tags: ["provider:aws", "provider:aws:apigateway", "live"] }, |
| 124 | ); |