| 1 | import * as AWS from "@/AWS"; |
| 2 | import { Group, UserPool } from "@/AWS/Cognito"; |
| 3 | import * as Test from "@/Test/Alchemy"; |
| 4 | import * as cip from "@distilled.cloud/aws/cognito-identity-provider"; |
| 5 | import { expect } from "alchemy-test"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | |
| 8 | const { test } = Test.make({ providers: AWS.providers() }); |
| 9 | |
| 10 | test.provider( |
| 11 | "create, update, rename (replace), delete group", |
| 12 | (stack) => |
| 13 | Effect.gen(function* () { |
| 14 | yield* stack.destroy(); |
| 15 | |
| 16 | const outputs = yield* stack.deploy( |
| 17 | Effect.gen(function* () { |
| 18 | const pool = yield* UserPool("GroupTestPool", {}); |
| 19 | const group = yield* Group("Team", { |
| 20 | userPoolId: pool.userPoolId, |
| 21 | description: "first description", |
| 22 | precedence: 5, |
| 23 | }); |
| 24 | return { pool, group }; |
| 25 | }), |
| 26 | ); |
| 27 | |
| 28 | expect(outputs.group.groupName).toBeDefined(); |
| 29 | |
| 30 | // out-of-band verification via distilled |
| 31 | const created = yield* cip.getGroup({ |
| 32 | UserPoolId: outputs.pool.userPoolId, |
| 33 | GroupName: outputs.group.groupName, |
| 34 | }); |
| 35 | expect(created.Group?.Description).toBe("first description"); |
| 36 | expect(created.Group?.Precedence).toBe(5); |
| 37 | |
| 38 | // description/precedence mutate in place |
| 39 | const updated = yield* stack.deploy( |
| 40 | Effect.gen(function* () { |
| 41 | const pool = yield* UserPool("GroupTestPool", {}); |
| 42 | const group = yield* Group("Team", { |
| 43 | userPoolId: pool.userPoolId, |
| 44 | description: "second description", |
| 45 | precedence: 7, |
| 46 | }); |
| 47 | return { pool, group }; |
| 48 | }), |
| 49 | ); |
| 50 | expect(updated.group.groupName).toBe(outputs.group.groupName); |
| 51 | const afterUpdate = yield* cip.getGroup({ |
| 52 | UserPoolId: outputs.pool.userPoolId, |
| 53 | GroupName: outputs.group.groupName, |
| 54 | }); |
| 55 | expect(afterUpdate.Group?.Description).toBe("second description"); |
| 56 | expect(afterUpdate.Group?.Precedence).toBe(7); |
| 57 | |
| 58 | // renaming replaces the group |
| 59 | const renamed = yield* stack.deploy( |
| 60 | Effect.gen(function* () { |
| 61 | const pool = yield* UserPool("GroupTestPool", {}); |
| 62 | const group = yield* Group("Team", { |
| 63 | userPoolId: pool.userPoolId, |
| 64 | groupName: "explicit-team-name", |
| 65 | description: "second description", |
| 66 | precedence: 7, |
| 67 | }); |
| 68 | return { pool, group }; |
| 69 | }), |
| 70 | ); |
| 71 | expect(renamed.group.groupName).toBe("explicit-team-name"); |
| 72 | const oldGone = yield* cip |
| 73 | .getGroup({ |
| 74 | UserPoolId: outputs.pool.userPoolId, |
| 75 | GroupName: outputs.group.groupName, |
| 76 | }) |
| 77 | .pipe( |
| 78 | Effect.map(() => false), |
| 79 | Effect.catchTag("ResourceNotFoundException", () => |
| 80 | Effect.succeed(true), |
| 81 | ), |
| 82 | ); |
| 83 | expect(oldGone).toBe(true); |
| 84 | |
| 85 | yield* stack.destroy(); |
| 86 | const gone = yield* cip |
| 87 | .getGroup({ |
| 88 | UserPoolId: outputs.pool.userPoolId, |
| 89 | GroupName: "explicit-team-name", |
| 90 | }) |
| 91 | .pipe( |
| 92 | Effect.map(() => false), |
| 93 | Effect.catchTag("ResourceNotFoundException", () => |
| 94 | Effect.succeed(true), |
| 95 | ), |
| 96 | ); |
| 97 | expect(gone).toBe(true); |
| 98 | }), |
| 99 | { tags: ["provider:aws", "provider:aws:cognito", "live"], timeout: 120_000 }, |
| 100 | ); |