| 1 | import { assert, it } from "@effect/vitest"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Layer from "effect/Layer"; |
| 4 | import * as SqlClient from "effect/sql/SqlClient"; |
| 5 | |
| 6 | import { runMigrations } from "../Migrations.ts"; |
| 7 | import * as NodeSqliteClient from "@t3tools/shared/nodeSqliteClient"; |
| 8 | |
| 9 | const layer = it.layer(Layer.mergeAll(NodeSqliteClient.layer({ filename: ":memory:" }))); |
| 10 | |
| 11 | layer("041_AuthSessionClientConnection", (it) => { |
| 12 | it.effect("adds nullable client surface and app version columns to auth sessions", () => |
| 13 | Effect.gen(function* () { |
| 14 | const sql = yield* SqlClient.SqlClient; |
| 15 | |
| 16 | yield* runMigrations({ toMigrationInclusive: 40 }); |
| 17 | yield* runMigrations({ toMigrationInclusive: 41 }); |
| 18 | |
| 19 | const columns = yield* sql<{ readonly name: string; readonly notnull: number }>` |
| 20 | PRAGMA table_info(auth_sessions) |
| 21 | `; |
| 22 | const surface = columns.find((column) => column.name === "client_surface"); |
| 23 | const appVersion = columns.find((column) => column.name === "client_app_version"); |
| 24 | |
| 25 | assert.equal(surface?.name, "client_surface"); |
| 26 | assert.equal(surface?.notnull, 0); |
| 27 | assert.equal(appVersion?.name, "client_app_version"); |
| 28 | assert.equal(appVersion?.notnull, 0); |
| 29 | }), |
| 30 | ); |
| 31 | }); |