| 1 | import * as AWS from "@/AWS"; |
| 2 | import { PreparedStatement } from "@/AWS/Athena/PreparedStatement.ts"; |
| 3 | import { WorkGroup } from "@/AWS/Athena/WorkGroup.ts"; |
| 4 | import * as Provider from "@/Provider"; |
| 5 | import * as Test from "@/Test/Alchemy"; |
| 6 | import * as athena from "@distilled.cloud/aws/athena"; |
| 7 | import { expect } from "alchemy-test"; |
| 8 | import * as Effect from "effect/Effect"; |
| 9 | |
| 10 | const { test } = Test.make({ providers: AWS.providers() }); |
| 11 | |
| 12 | const wgName = "alchemy-test-athena-ps-wg"; |
| 13 | const stmtName = "alchemy_test_prepared_stmt"; |
| 14 | |
| 15 | const getStatement = athena |
| 16 | .getPreparedStatement({ WorkGroup: wgName, StatementName: stmtName }) |
| 17 | .pipe( |
| 18 | Effect.map((res) => res.PreparedStatement), |
| 19 | Effect.catchTag(["ResourceNotFoundException", "WorkGroupNotFound"], () => |
| 20 | Effect.succeed(undefined), |
| 21 | ), |
| 22 | ); |
| 23 | |
| 24 | test.provider( |
| 25 | "lifecycle: create in a workgroup, update statement text, destroy", |
| 26 | (stack) => |
| 27 | Effect.gen(function* () { |
| 28 | yield* stack.destroy(); |
| 29 | |
| 30 | // Create — a named statement saved in a dedicated workgroup. |
| 31 | const deployed = yield* stack.deploy( |
| 32 | Effect.gen(function* () { |
| 33 | const wg = yield* WorkGroup("PSWorkGroup", { |
| 34 | workGroupName: wgName, |
| 35 | }); |
| 36 | return yield* PreparedStatement("Stmt", { |
| 37 | statementName: stmtName, |
| 38 | workGroup: wg.workGroupName, |
| 39 | queryStatement: "SELECT 1 AS one", |
| 40 | description: "alchemy prepared statement test", |
| 41 | }); |
| 42 | }), |
| 43 | ); |
| 44 | expect(deployed.statementName).toBe(stmtName); |
| 45 | expect(deployed.workGroup).toBe(wgName); |
| 46 | expect(deployed.queryStatement).toBe("SELECT 1 AS one"); |
| 47 | |
| 48 | // Out-of-band verification via distilled. |
| 49 | const created = yield* getStatement; |
| 50 | expect(created?.StatementName).toBe(stmtName); |
| 51 | expect(created?.QueryStatement).toBe("SELECT 1 AS one"); |
| 52 | expect(created?.Description).toBe("alchemy prepared statement test"); |
| 53 | |
| 54 | // Canonical list() coverage. |
| 55 | const provider = yield* Provider.findProvider(PreparedStatement); |
| 56 | const all = yield* provider.list(); |
| 57 | expect( |
| 58 | all.some( |
| 59 | (ps) => ps.statementName === stmtName && ps.workGroup === wgName, |
| 60 | ), |
| 61 | ).toBe(true); |
| 62 | |
| 63 | // Update — statement text and description are updatable in place. |
| 64 | yield* stack.deploy( |
| 65 | Effect.gen(function* () { |
| 66 | const wg = yield* WorkGroup("PSWorkGroup", { |
| 67 | workGroupName: wgName, |
| 68 | }); |
| 69 | return yield* PreparedStatement("Stmt", { |
| 70 | statementName: stmtName, |
| 71 | workGroup: wg.workGroupName, |
| 72 | queryStatement: "SELECT 2 AS two", |
| 73 | description: "updated", |
| 74 | }); |
| 75 | }), |
| 76 | ); |
| 77 | const updated = yield* getStatement; |
| 78 | expect(updated?.QueryStatement).toBe("SELECT 2 AS two"); |
| 79 | expect(updated?.Description).toBe("updated"); |
| 80 | |
| 81 | // Destroy — statement (and its workgroup) are gone. |
| 82 | yield* stack.destroy(); |
| 83 | const after = yield* getStatement; |
| 84 | expect(after).toBeUndefined(); |
| 85 | }), |
| 86 | { tags: ["provider:aws", "provider:aws:athena", "live"], timeout: 180_000 }, |
| 87 | ); |