| 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 { assertUsagePlanDeleted } from "./assertions.ts"; |
| 8 | |
| 9 | const { test } = Test.make({ providers: AWS.providers() }); |
| 10 | |
| 11 | test.provider.skipIf(!!process.env.FAST)( |
| 12 | "create and delete usage plan", |
| 13 | (stack) => |
| 14 | Effect.gen(function* () { |
| 15 | yield* stack.destroy(); |
| 16 | |
| 17 | const plan = yield* stack.deploy( |
| 18 | Effect.gen(function* () { |
| 19 | return yield* AWS.ApiGateway.UsagePlan("AgUsagePlan", { |
| 20 | description: "test plan", |
| 21 | }); |
| 22 | }), |
| 23 | ); |
| 24 | |
| 25 | expect(plan.id).toBeDefined(); |
| 26 | |
| 27 | yield* stack.destroy(); |
| 28 | yield* assertUsagePlanDeleted(plan.id); |
| 29 | }), |
| 30 | { tags: ["provider:aws", "provider:aws:apigateway", "live"] }, |
| 31 | ); |
| 32 | |
| 33 | test.provider.skipIf(!!process.env.FAST)( |
| 34 | "usage plan throttle updates in place", |
| 35 | (stack) => |
| 36 | Effect.gen(function* () { |
| 37 | yield* stack.destroy(); |
| 38 | |
| 39 | const plan = yield* stack.deploy( |
| 40 | Effect.gen(function* () { |
| 41 | return yield* AWS.ApiGateway.UsagePlan("AgUsagePlanThrottle", { |
| 42 | throttle: { burstLimit: 10, rateLimit: 100 }, |
| 43 | }); |
| 44 | }), |
| 45 | ); |
| 46 | |
| 47 | yield* stack.deploy( |
| 48 | Effect.gen(function* () { |
| 49 | return yield* AWS.ApiGateway.UsagePlan("AgUsagePlanThrottle", { |
| 50 | throttle: { burstLimit: 20, rateLimit: 200 }, |
| 51 | }); |
| 52 | }), |
| 53 | ); |
| 54 | |
| 55 | const remote = yield* ag.getUsagePlan({ usagePlanId: plan.id }); |
| 56 | expect(remote.throttle?.burstLimit).toEqual(20); |
| 57 | expect(remote.throttle?.rateLimit).toEqual(200); |
| 58 | |
| 59 | yield* stack.destroy(); |
| 60 | yield* assertUsagePlanDeleted(plan.id); |
| 61 | }), |
| 62 | { tags: ["provider:aws", "provider:aws:apigateway", "live"] }, |
| 63 | ); |
| 64 | |
| 65 | test.provider.skipIf(!!process.env.FAST)( |
| 66 | "list enumerates the deployed usage plan", |
| 67 | (stack) => |
| 68 | Effect.gen(function* () { |
| 69 | yield* stack.destroy(); |
| 70 | |
| 71 | const plan = yield* stack.deploy( |
| 72 | Effect.gen(function* () { |
| 73 | return yield* AWS.ApiGateway.UsagePlan("AgUsagePlanList", { |
| 74 | description: "list test plan", |
| 75 | }); |
| 76 | }), |
| 77 | ); |
| 78 | |
| 79 | const provider = yield* Provider.findProvider(AWS.ApiGateway.UsagePlan); |
| 80 | const all = yield* provider.list(); |
| 81 | |
| 82 | expect(all.some((p) => p.id === plan.id)).toBe(true); |
| 83 | |
| 84 | yield* stack.destroy(); |
| 85 | yield* assertUsagePlanDeleted(plan.id); |
| 86 | }), |
| 87 | { tags: ["provider:aws", "provider:aws:apigateway", "live"] }, |
| 88 | ); |