| 1 | import * as AWS from "@/AWS"; |
| 2 | import { VirtualMFADevice } from "@/AWS/IAM"; |
| 3 | import * as Provider from "@/Provider"; |
| 4 | import * as Test from "@/Test/Alchemy"; |
| 5 | import { describe, expect } from "alchemy-test"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | |
| 8 | const { test } = Test.make({ providers: AWS.providers() }); |
| 9 | |
| 10 | describe( |
| 11 | "AWS.IAM.VirtualMFADevice", |
| 12 | { tags: ["provider:aws", "provider:aws:iam", "live"] }, |
| 13 | () => { |
| 14 | test.provider("list enumerates the deployed virtual MFA device", (stack) => |
| 15 | Effect.gen(function* () { |
| 16 | yield* stack.destroy(); |
| 17 | |
| 18 | const device = yield* stack.deploy( |
| 19 | Effect.gen(function* () { |
| 20 | return yield* VirtualMFADevice("ListVirtualMfaDevice", { |
| 21 | tags: { |
| 22 | env: "test", |
| 23 | }, |
| 24 | }); |
| 25 | }), |
| 26 | ); |
| 27 | |
| 28 | const provider = yield* Provider.findProvider(VirtualMFADevice); |
| 29 | const all = yield* provider.list(); |
| 30 | |
| 31 | const found = all.find( |
| 32 | (entry) => entry.serialNumber === device.serialNumber, |
| 33 | ); |
| 34 | expect(found).toBeDefined(); |
| 35 | expect(found?.tags).toMatchObject({ env: "test" }); |
| 36 | |
| 37 | yield* stack.destroy(); |
| 38 | |
| 39 | // IAM has no get-virtual-mfa-device API; re-list exhaustively and |
| 40 | // assert the device's serial number no longer appears. |
| 41 | const remaining = yield* provider.list(); |
| 42 | expect( |
| 43 | remaining.some((entry) => entry.serialNumber === device.serialNumber), |
| 44 | ).toBe(false); |
| 45 | }), |
| 46 | ); |
| 47 | }, |
| 48 | ); |