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 { LinkedWhatsAppBusinessAccount } from "@alchemy.run/aws/SocialMessaging"; |
| 3 | import { expect } from "@alchemy.run/test"; |
| 4 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 5 | import * as socialmessaging from "@distilled.cloud/aws/socialmessaging"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | |
| 8 | const { test } = Test.make({ providers: AWS.providers() }); |
| 9 | |
| 10 | // WhatsApp Business onboarding requires the Meta embedded-signup OAuth flow |
| 11 | // in the AWS console (cannot be automated), so the full lifecycle is gated |
| 12 | // behind AWS_TEST_SOCIALMESSAGING=1 + AWS_TEST_SOCIALMESSAGING_WABA_ID. |
| 13 | // The ungated probes below prove the distilled error union carries the typed |
| 14 | // tags the provider's read/reconcile/delete paths depend on, in every CI run. |
| 15 | |
| 16 | test.provider( |
| 17 | "listLinkedWhatsAppBusinessAccounts succeeds (no onboarding required)", |
| 18 | () => |
| 19 | Effect.gen(function* () { |
| 20 | const response = yield* socialmessaging.listLinkedWhatsAppBusinessAccounts({}); |
| 21 | expect(Array.isArray(response.linkedAccounts ?? [])).toBe(true); |
| 22 | }), |
| 23 | { tags: ["provider:aws", "provider:aws:socialmessaging", "live"] }, |
| 24 | ); |
| 25 | |
| 26 | test.provider( |
| 27 | "getLinkedWhatsAppBusinessAccount on a nonexistent id fails with ResourceNotFoundException", |
| 28 | () => |
| 29 | Effect.gen(function* () { |
| 30 | const error = yield* Effect.flip( |
| 31 | socialmessaging.getLinkedWhatsAppBusinessAccount({ |
| 32 | // well-formed but nonexistent linked-WABA id |
| 33 | id: "waba-0123456789abcdef0123456789abcdef", |
| 34 | }), |
| 35 | ); |
| 36 | expect(error._tag).toBe("ResourceNotFoundException"); |
| 37 | }), |
| 38 | { tags: ["provider:aws", "provider:aws:socialmessaging", "live"] }, |
| 39 | ); |
| 40 | |
| 41 | test.provider( |
| 42 | "disassociateWhatsAppBusinessAccount on a nonexistent id fails with ResourceNotFoundException", |
| 43 | () => |
| 44 | Effect.gen(function* () { |
| 45 | const error = yield* Effect.flip( |
| 46 | socialmessaging.disassociateWhatsAppBusinessAccount({ |
| 47 | id: "waba-0123456789abcdef0123456789abcdef", |
| 48 | }), |
| 49 | ); |
| 50 | expect(error._tag).toBe("ResourceNotFoundException"); |
| 51 | }), |
| 52 | { tags: ["provider:aws", "provider:aws:socialmessaging", "live"] }, |
| 53 | ); |
| 54 | |
| 55 | // Full lifecycle — requires a WhatsApp Business Account already linked via |
| 56 | // the AWS End User Messaging Social console (Meta embedded signup). Set |
| 57 | // AWS_TEST_SOCIALMESSAGING=1 and AWS_TEST_SOCIALMESSAGING_WABA_ID=waba-... |
| 58 | // to run. NOTE: the final stack.destroy() disassociates the WABA from the |
| 59 | // AWS account; re-running afterwards requires redoing the console signup. |
| 60 | test.provider.skipIf( |
| 61 | !process.env.AWS_TEST_SOCIALMESSAGING || !process.env.AWS_TEST_SOCIALMESSAGING_WABA_ID, |
| 62 | )( |
| 63 | "adopt linked WABA, sync tags + event destinations, destroy", |
| 64 | (stack) => |
| 65 | Effect.gen(function* () { |
| 66 | const wabaId = process.env.AWS_TEST_SOCIALMESSAGING_WABA_ID!; |
| 67 | yield* stack.destroy(); |
| 68 | |
| 69 | const { account } = yield* stack.deploy( |
| 70 | Effect.gen(function* () { |
| 71 | const account = yield* LinkedWhatsAppBusinessAccount("Business", { |
| 72 | accountId: wabaId, |
| 73 | tags: { fixture: "socialmessaging" }, |
| 74 | }); |
| 75 | return { account }; |
| 76 | }), |
| 77 | ); |
| 78 | |
| 79 | expect(account.id).toBe(wabaId); |
| 80 | expect(account.arn).toContain(":waba/"); |
| 81 | expect(account.wabaId).toBeDefined(); |
| 82 | expect(account.wabaName).toBeDefined(); |
| 83 | expect(account.tags.fixture).toBe("socialmessaging"); |
| 84 | |
| 85 | // Out-of-band verification via distilled. |
| 86 | const observed = yield* socialmessaging.getLinkedWhatsAppBusinessAccount({ id: wabaId }); |
| 87 | expect(observed.account?.id).toBe(wabaId); |
| 88 | const observedTags = yield* socialmessaging.listTagsForResource({ resourceArn: account.arn }); |
| 89 | const tagMap = Object.fromEntries( |
| 90 | (observedTags.tags ?? []).map((tag) => [tag.key, tag.value]), |
| 91 | ); |
| 92 | expect(tagMap.fixture).toBe("socialmessaging"); |
| 93 | expect(tagMap["alchemy::id"]).toBe("Business"); |
| 94 | |
| 95 | // Update — change tags only. |
| 96 | const updated = yield* stack.deploy( |
| 97 | Effect.gen(function* () { |
| 98 | const account = yield* LinkedWhatsAppBusinessAccount("Business", { |
| 99 | accountId: wabaId, |
| 100 | tags: { fixture: "socialmessaging", updated: "true" }, |
| 101 | }); |
| 102 | return { account }; |
| 103 | }), |
| 104 | ); |
| 105 | expect(updated.account.tags.updated).toBe("true"); |
| 106 | |
| 107 | // Destroy — disassociates the WABA; verify it is gone. |
| 108 | yield* stack.destroy(); |
| 109 | const gone = yield* Effect.flip( |
| 110 | socialmessaging.getLinkedWhatsAppBusinessAccount({ id: wabaId }), |
| 111 | ); |
| 112 | expect(gone._tag).toBe("ResourceNotFoundException"); |
| 113 | }), |
| 114 | { tags: ["provider:aws", "provider:aws:socialmessaging", "live"], timeout: 120_000 }, |
| 115 | ); |