-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigrate.utils.test.js
More file actions
46 lines (42 loc) · 1.11 KB
/
migrate.utils.test.js
File metadata and controls
46 lines (42 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import assert from "assert";
import {
ENV,
MIGRATIONS_DIR,
DB_CONFIG,
getAllMigrations,
readMigrationContent,
executeInTransaction,
executeSQL,
filterMigrations,
filterMigrationsToTimestamp,
withClient,
} from "./migrate.utils.js";
describe("Migration Utilities", () => {
it("should have correct environment variables", () => {
assert(ENV);
assert(MIGRATIONS_DIR);
assert(DB_CONFIG);
});
it("should get all migrations", async () => {
const migrations = await getAllMigrations();
assert(Array.isArray(migrations));
});
it("should read migration content", async () => {
const migrations = await getAllMigrations();
if (migrations.length > 0) {
const content = await readMigrationContent(migrations[0]);
assert(typeof content === "string");
}
});
});
it("should execute SQL within a transaction", async () => {
await withClient(async (client) => {
const action = async () => {
await client.query("SELECT 1");
};
await executeInTransaction(client, action);
assert(true);
}).catch(() => {
assert(false, "Transaction failed");
});
});