The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
| 1 | import * as Stripe from "@alchemy.run/stripe"; |
| 2 | import { isMissingStripeResource } from "@alchemy.run/stripe/missing"; |
| 3 | import { expect } from "@alchemy.run/test"; |
| 4 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 5 | import { GetApplePayDomain } from "@distilled.cloud/stripe/stripe"; |
| 6 | import * as Provider from "alchemy/Provider"; |
| 7 | import * as Effect from "effect/Effect"; |
| 8 | import { MinimumLogLevel } from "effect/References"; |
| 9 | import * as Schedule from "effect/Schedule"; |
| 10 | |
| 11 | const { test } = Test.make({ providers: Stripe.providers() }); |
| 12 | |
| 13 | const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info"); |
| 14 | |
| 15 | const LIFECYCLE_DOMAIN = "alchemy-apple-pay-lifecycle.example.com"; |
| 16 | const REPLACE_FROM_DOMAIN = "alchemy-apple-pay-replace-a.example.com"; |
| 17 | const REPLACE_TO_DOMAIN = "alchemy-apple-pay-replace-b.example.com"; |
| 18 | const LIST_DOMAIN = "alchemy-apple-pay-list.example.com"; |
| 19 | |
| 20 | const waitUntilGone = (id: string) => |
| 21 | GetApplePayDomain({ domain: id }).pipe( |
| 22 | Effect.as("found" as const), |
| 23 | Effect.catchIf(isMissingStripeResource, () => Effect.succeed("gone" as const)), |
| 24 | Effect.repeat({ |
| 25 | schedule: Schedule.spaced("1 second"), |
| 26 | until: (status) => status === "gone", |
| 27 | times: 10, |
| 28 | }), |
| 29 | ); |
| 30 | |
| 31 | test.provider( |
| 32 | "create, update, and delete an apple pay domain", |
| 33 | (stack) => |
| 34 | Effect.gen(function* () { |
| 35 | yield* stack.destroy(); |
| 36 | |
| 37 | const created = yield* stack.deploy( |
| 38 | Effect.gen(function* () { |
| 39 | return yield* Stripe.ApplePayDomain("Checkout", { |
| 40 | domainName: LIFECYCLE_DOMAIN, |
| 41 | }); |
| 42 | }), |
| 43 | ); |
| 44 | |
| 45 | expect(created.id).toMatch(/^apwc_/); |
| 46 | expect(created.domainName).toEqual(LIFECYCLE_DOMAIN); |
| 47 | expect(created.created).toEqual(expect.any(Number)); |
| 48 | expect(created.livemode).toEqual(false); |
| 49 | |
| 50 | const fetched = yield* GetApplePayDomain({ |
| 51 | domain: created.id, |
| 52 | }); |
| 53 | expect(fetched.id).toEqual(created.id); |
| 54 | expect(fetched.domain_name).toEqual(LIFECYCLE_DOMAIN); |
| 55 | expect(fetched.livemode).toEqual(false); |
| 56 | |
| 57 | const updated = yield* stack.deploy( |
| 58 | Effect.gen(function* () { |
| 59 | return yield* Stripe.ApplePayDomain("Checkout", { |
| 60 | domainName: LIFECYCLE_DOMAIN, |
| 61 | }); |
| 62 | }), |
| 63 | ); |
| 64 | |
| 65 | expect(updated.id).toEqual(created.id); |
| 66 | expect(updated.domainName).toEqual(LIFECYCLE_DOMAIN); |
| 67 | |
| 68 | const refetched = yield* GetApplePayDomain({ |
| 69 | domain: updated.id, |
| 70 | }); |
| 71 | expect(refetched.id).toEqual(updated.id); |
| 72 | expect(refetched.domain_name).toEqual(LIFECYCLE_DOMAIN); |
| 73 | |
| 74 | yield* stack.destroy(); |
| 75 | |
| 76 | const gone = yield* waitUntilGone(created.id); |
| 77 | expect(gone).toEqual("gone"); |
| 78 | }).pipe(logLevel), |
| 79 | { |
| 80 | tags: ["provider:stripe", "provider:stripe:applepaydomain", "live"], |
| 81 | timeout: 120_000, |
| 82 | }, |
| 83 | ); |
| 84 | |
| 85 | test.provider( |
| 86 | "replace when domainName changes", |
| 87 | (stack) => |
| 88 | Effect.gen(function* () { |
| 89 | yield* stack.destroy(); |
| 90 | |
| 91 | const created = yield* stack.deploy( |
| 92 | Effect.gen(function* () { |
| 93 | return yield* Stripe.ApplePayDomain("ReplaceDomain", { |
| 94 | domainName: REPLACE_FROM_DOMAIN, |
| 95 | }); |
| 96 | }), |
| 97 | ); |
| 98 | |
| 99 | expect(created.domainName).toEqual(REPLACE_FROM_DOMAIN); |
| 100 | |
| 101 | const replaced = yield* stack.deploy( |
| 102 | Effect.gen(function* () { |
| 103 | return yield* Stripe.ApplePayDomain("ReplaceDomain", { |
| 104 | domainName: REPLACE_TO_DOMAIN, |
| 105 | }); |
| 106 | }), |
| 107 | ); |
| 108 | |
| 109 | expect(replaced.id).not.toEqual(created.id); |
| 110 | expect(replaced.domainName).toEqual(REPLACE_TO_DOMAIN); |
| 111 | |
| 112 | const fetched = yield* GetApplePayDomain({ |
| 113 | domain: replaced.id, |
| 114 | }); |
| 115 | expect(fetched.id).toEqual(replaced.id); |
| 116 | expect(fetched.domain_name).toEqual(REPLACE_TO_DOMAIN); |
| 117 | |
| 118 | const oldGone = yield* waitUntilGone(created.id); |
| 119 | expect(oldGone).toEqual("gone"); |
| 120 | |
| 121 | yield* stack.destroy(); |
| 122 | |
| 123 | const gone = yield* waitUntilGone(replaced.id); |
| 124 | expect(gone).toEqual("gone"); |
| 125 | }).pipe(logLevel), |
| 126 | { |
| 127 | tags: ["provider:stripe", "provider:stripe:applepaydomain", "live"], |
| 128 | timeout: 120_000, |
| 129 | }, |
| 130 | ); |
| 131 | |
| 132 | test.provider( |
| 133 | "list enumerates the deployed apple pay domain", |
| 134 | (stack) => |
| 135 | Effect.gen(function* () { |
| 136 | yield* stack.destroy(); |
| 137 | |
| 138 | const deployed = yield* stack.deploy( |
| 139 | Effect.gen(function* () { |
| 140 | return yield* Stripe.ApplePayDomain("ListDomain", { |
| 141 | domainName: LIST_DOMAIN, |
| 142 | }); |
| 143 | }), |
| 144 | ); |
| 145 | |
| 146 | const provider = yield* Provider.findProvider(Stripe.ApplePayDomain); |
| 147 | const all = yield* provider.list(); |
| 148 | const found = all.find((domain) => domain.id === deployed.id); |
| 149 | expect(found).toBeDefined(); |
| 150 | expect(found?.domainName).toEqual(LIST_DOMAIN); |
| 151 | |
| 152 | yield* stack.destroy(); |
| 153 | |
| 154 | const gone = yield* waitUntilGone(deployed.id); |
| 155 | expect(gone).toEqual("gone"); |
| 156 | }).pipe(logLevel), |
| 157 | { |
| 158 | tags: ["provider:stripe", "provider:stripe:applepaydomain", "live"], |
| 159 | timeout: 120_000, |
| 160 | }, |
| 161 | ); |