@geekmidas/testkit 0.3.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Factory-BFVnMMCC.mjs.map +1 -1
- package/dist/Factory-BhjUOBWN.cjs.map +1 -1
- package/dist/{Factory-BK06XuDA.d.cts → Factory-Bx0AJXZB.d.cts} +3 -2
- package/dist/Factory-Bx0AJXZB.d.cts.map +1 -0
- package/dist/{Factory-BcGJjLc8.d.mts → Factory-SFupxRC2.d.mts} +2 -1
- package/dist/Factory-SFupxRC2.d.mts.map +1 -0
- package/dist/Factory.d.cts +2 -2
- package/dist/Factory.d.mts +1 -1
- package/dist/KyselyFactory-BFqVIn_0.cjs.map +1 -1
- package/dist/KyselyFactory-DMswpwji.mjs.map +1 -1
- package/dist/{KyselyFactory-Bu9ssWZP.d.cts → KyselyFactory-KLeKH43i.d.cts} +4 -3
- package/dist/KyselyFactory-KLeKH43i.d.cts.map +1 -0
- package/dist/{KyselyFactory-Cj-EultY.d.mts → KyselyFactory-vAxYodck.d.mts} +3 -2
- package/dist/KyselyFactory-vAxYodck.d.mts.map +1 -0
- package/dist/KyselyFactory.d.cts +3 -3
- package/dist/KyselyFactory.d.mts +2 -2
- package/dist/{ObjectionFactory-DL4qkuF1.d.mts → ObjectionFactory-BWjB49-i.d.mts} +3 -2
- package/dist/ObjectionFactory-BWjB49-i.d.mts.map +1 -0
- package/dist/ObjectionFactory-BeFBYcan.cjs.map +1 -1
- package/dist/ObjectionFactory-QCJ7u0Ql.mjs.map +1 -1
- package/dist/{ObjectionFactory-tKWZOiYO.d.cts → ObjectionFactory-aMGvAKt9.d.cts} +4 -3
- package/dist/ObjectionFactory-aMGvAKt9.d.cts.map +1 -0
- package/dist/ObjectionFactory.d.cts +3 -3
- package/dist/ObjectionFactory.d.mts +2 -2
- package/dist/{PostgresKyselyMigrator-upT-hmrz.mjs → PostgresKyselyMigrator-6sE1KOni.mjs} +2 -2
- package/dist/PostgresKyselyMigrator-6sE1KOni.mjs.map +1 -0
- package/dist/{PostgresKyselyMigrator-CIx3AFSR.d.mts → PostgresKyselyMigrator-CBltSOq5.d.cts} +3 -2
- package/dist/PostgresKyselyMigrator-CBltSOq5.d.cts.map +1 -0
- package/dist/{PostgresKyselyMigrator-CfytARcA.cjs → PostgresKyselyMigrator-D6IbPq8t.cjs} +2 -2
- package/dist/PostgresKyselyMigrator-D6IbPq8t.cjs.map +1 -0
- package/dist/{PostgresKyselyMigrator-CQ3aUoy_.d.cts → PostgresKyselyMigrator-DrVWncqd.d.mts} +3 -2
- package/dist/PostgresKyselyMigrator-DrVWncqd.d.mts.map +1 -0
- package/dist/PostgresKyselyMigrator.cjs +2 -2
- package/dist/PostgresKyselyMigrator.d.cts +2 -2
- package/dist/PostgresKyselyMigrator.d.mts +2 -2
- package/dist/PostgresKyselyMigrator.mjs +2 -2
- package/dist/{PostgresMigrator-DbuJGAVy.mjs → PostgresMigrator-BjjenqSd.mjs} +2 -2
- package/dist/PostgresMigrator-BjjenqSd.mjs.map +1 -0
- package/dist/{PostgresMigrator-D5UkK1_K.d.cts → PostgresMigrator-Bres0U6E.d.cts} +2 -1
- package/dist/PostgresMigrator-Bres0U6E.d.cts.map +1 -0
- package/dist/{PostgresMigrator-DFcNdCvD.cjs → PostgresMigrator-D6dQn0x2.cjs} +2 -2
- package/dist/PostgresMigrator-D6dQn0x2.cjs.map +1 -0
- package/dist/{PostgresMigrator-DQaRxoaY.d.mts → PostgresMigrator-S-YYosAC.d.mts} +2 -1
- package/dist/PostgresMigrator-S-YYosAC.d.mts.map +1 -0
- package/dist/PostgresMigrator.cjs +1 -1
- package/dist/PostgresMigrator.d.cts +1 -1
- package/dist/PostgresMigrator.d.mts +1 -1
- package/dist/PostgresMigrator.mjs +1 -1
- package/dist/{PostgresObjectionMigrator-CZHHcCOv.d.cts → PostgresObjectionMigrator-CPfBAP7r.d.cts} +3 -2
- package/dist/PostgresObjectionMigrator-CPfBAP7r.d.cts.map +1 -0
- package/dist/{PostgresObjectionMigrator-BG6ymgnt.cjs → PostgresObjectionMigrator-DK8ODIHQ.cjs} +2 -2
- package/dist/PostgresObjectionMigrator-DK8ODIHQ.cjs.map +1 -0
- package/dist/{PostgresObjectionMigrator-D_hCcrQu.d.mts → PostgresObjectionMigrator-DVEqB5tp.d.mts} +3 -2
- package/dist/PostgresObjectionMigrator-DVEqB5tp.d.mts.map +1 -0
- package/dist/{PostgresObjectionMigrator-DPj2pOpX.mjs → PostgresObjectionMigrator-D_QxXbIN.mjs} +2 -2
- package/dist/PostgresObjectionMigrator-D_QxXbIN.mjs.map +1 -0
- package/dist/PostgresObjectionMigrator.cjs +2 -2
- package/dist/PostgresObjectionMigrator.d.cts +2 -2
- package/dist/PostgresObjectionMigrator.d.mts +2 -2
- package/dist/PostgresObjectionMigrator.mjs +2 -2
- package/dist/{VitestKyselyTransactionIsolator-D3EZZhjZ.d.cts → VitestKyselyTransactionIsolator-CduJlHoT.d.cts} +4 -3
- package/dist/VitestKyselyTransactionIsolator-CduJlHoT.d.cts.map +1 -0
- package/dist/{VitestKyselyTransactionIsolator-Dxlp1u0f.d.mts → VitestKyselyTransactionIsolator-Cswnnj0k.d.mts} +4 -3
- package/dist/VitestKyselyTransactionIsolator-Cswnnj0k.d.mts.map +1 -0
- package/dist/{VitestKyselyTransactionIsolator-EvDLk5zg.cjs → VitestKyselyTransactionIsolator-D7RRXOBa.cjs} +2 -2
- package/dist/VitestKyselyTransactionIsolator-D7RRXOBa.cjs.map +1 -0
- package/dist/{VitestKyselyTransactionIsolator-CNURW8y6.mjs → VitestKyselyTransactionIsolator-DceyIqr4.mjs} +2 -2
- package/dist/VitestKyselyTransactionIsolator-DceyIqr4.mjs.map +1 -0
- package/dist/VitestKyselyTransactionIsolator.cjs +1 -1
- package/dist/VitestKyselyTransactionIsolator.d.cts +2 -2
- package/dist/VitestKyselyTransactionIsolator.d.mts +2 -2
- package/dist/VitestKyselyTransactionIsolator.mjs +1 -1
- package/dist/{VitestObjectionTransactionIsolator-1TpsPqfG.d.cts → VitestObjectionTransactionIsolator-BXoR6xdG.d.cts} +4 -3
- package/dist/VitestObjectionTransactionIsolator-BXoR6xdG.d.cts.map +1 -0
- package/dist/{VitestObjectionTransactionIsolator-CM5KTAFA.cjs → VitestObjectionTransactionIsolator-CdLRrzNf.cjs} +2 -2
- package/dist/VitestObjectionTransactionIsolator-CdLRrzNf.cjs.map +1 -0
- package/dist/{VitestObjectionTransactionIsolator-jQFaCz0u.mjs → VitestObjectionTransactionIsolator-OF2osYY5.mjs} +2 -2
- package/dist/VitestObjectionTransactionIsolator-OF2osYY5.mjs.map +1 -0
- package/dist/{VitestObjectionTransactionIsolator-i9jIgU8Q.d.mts → VitestObjectionTransactionIsolator-x6hY5j4u.d.mts} +4 -3
- package/dist/VitestObjectionTransactionIsolator-x6hY5j4u.d.mts.map +1 -0
- package/dist/VitestObjectionTransactionIsolator.cjs +1 -1
- package/dist/VitestObjectionTransactionIsolator.d.cts +2 -2
- package/dist/VitestObjectionTransactionIsolator.d.mts +2 -2
- package/dist/VitestObjectionTransactionIsolator.mjs +1 -1
- package/dist/{VitestTransactionIsolator-BvR19bYn.d.mts → VitestTransactionIsolator-BNWJqh9f.d.mts} +3 -2
- package/dist/VitestTransactionIsolator-BNWJqh9f.d.mts.map +1 -0
- package/dist/VitestTransactionIsolator-CMfJXZP8.cjs.map +1 -1
- package/dist/{VitestTransactionIsolator-CwQaxZLP.d.cts → VitestTransactionIsolator-CSroc7Df.d.cts} +3 -2
- package/dist/VitestTransactionIsolator-CSroc7Df.d.cts.map +1 -0
- package/dist/VitestTransactionIsolator-DQ7tLqgV.mjs.map +1 -1
- package/dist/VitestTransactionIsolator.d.cts +1 -1
- package/dist/VitestTransactionIsolator.d.mts +1 -1
- package/dist/aws.cjs.map +1 -1
- package/dist/aws.d.cts +2 -0
- package/dist/aws.d.cts.map +1 -0
- package/dist/aws.d.mts +2 -0
- package/dist/aws.d.mts.map +1 -0
- package/dist/aws.mjs.map +1 -1
- package/dist/benchmark.cjs.map +1 -1
- package/dist/benchmark.d.cts +1 -0
- package/dist/benchmark.d.cts.map +1 -0
- package/dist/benchmark.d.mts +1 -0
- package/dist/benchmark.d.mts.map +1 -0
- package/dist/benchmark.mjs.map +1 -1
- package/dist/better-auth.cjs +29 -30
- package/dist/better-auth.cjs.map +1 -1
- package/dist/better-auth.d.cts +2 -2
- package/dist/better-auth.d.cts.map +1 -0
- package/dist/better-auth.d.mts.map +1 -0
- package/dist/better-auth.mjs +29 -30
- package/dist/better-auth.mjs.map +1 -1
- package/dist/directory-B-Ozljzk.mjs.map +1 -1
- package/dist/directory-BVC8g7cX.cjs.map +1 -1
- package/dist/{directory-DlkPEzL4.d.cts → directory-CVrfTq1I.d.mts} +2 -1
- package/dist/directory-CVrfTq1I.d.mts.map +1 -0
- package/dist/directory-Cys9g76X.d.cts +13 -0
- package/dist/directory-Cys9g76X.d.cts.map +1 -0
- package/dist/faker-B14IEMIN.cjs.map +1 -1
- package/dist/faker-BGKYFoCT.mjs.map +1 -1
- package/dist/{faker-Cg76aFNO.d.cts → faker-BSH1EMtg.d.cts} +3 -3
- package/dist/faker-BSH1EMtg.d.cts.map +1 -0
- package/dist/faker-DHh7xs4u.d.mts.map +1 -0
- package/dist/faker.d.cts +1 -1
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.d.cts +1 -0
- package/dist/helpers.d.cts.map +1 -0
- package/dist/helpers.d.mts +1 -0
- package/dist/helpers.d.mts.map +1 -0
- package/dist/helpers.mjs.map +1 -1
- package/dist/kysely.cjs +3 -3
- package/dist/kysely.cjs.map +1 -1
- package/dist/kysely.d.cts +8 -7
- package/dist/kysely.d.cts.map +1 -0
- package/dist/kysely.d.mts +7 -6
- package/dist/kysely.d.mts.map +1 -0
- package/dist/kysely.mjs +3 -3
- package/dist/kysely.mjs.map +1 -1
- package/dist/logger.cjs.map +1 -1
- package/dist/logger.d.cts +1 -0
- package/dist/logger.d.cts.map +1 -0
- package/dist/logger.d.mts +1 -0
- package/dist/logger.d.mts.map +1 -0
- package/dist/logger.mjs.map +1 -1
- package/dist/objection.cjs +3 -3
- package/dist/objection.cjs.map +1 -1
- package/dist/objection.d.cts +8 -7
- package/dist/objection.d.cts.map +1 -0
- package/dist/objection.d.mts +7 -6
- package/dist/objection.d.mts.map +1 -0
- package/dist/objection.mjs +3 -3
- package/dist/objection.mjs.map +1 -1
- package/dist/os/directory.d.cts +1 -1
- package/dist/os/directory.d.mts +1 -1
- package/dist/os/index.d.cts +1 -1
- package/dist/os/index.d.mts +1 -1
- package/dist/timer.cjs.map +1 -1
- package/dist/timer.d.cts +2 -0
- package/dist/timer.d.cts.map +1 -0
- package/dist/timer.d.mts +2 -0
- package/dist/timer.d.mts.map +1 -0
- package/dist/timer.mjs.map +1 -1
- package/package.json +39 -5
- package/src/Factory.ts +72 -72
- package/src/KyselyFactory.ts +330 -330
- package/src/ObjectionFactory.ts +354 -355
- package/src/PostgresKyselyMigrator.ts +37 -37
- package/src/PostgresMigrator.ts +107 -107
- package/src/PostgresObjectionMigrator.ts +91 -91
- package/src/VitestKyselyTransactionIsolator.ts +27 -27
- package/src/VitestObjectionTransactionIsolator.ts +39 -39
- package/src/VitestTransactionIsolator.ts +196 -195
- package/src/__tests__/Factory.spec.ts +163 -155
- package/src/__tests__/KyselyFactory.spec.ts +443 -439
- package/src/__tests__/ObjectionFactory.spec.ts +563 -557
- package/src/__tests__/PostgresKyselyMigrator.spec.ts +641 -641
- package/src/__tests__/PostgresMigrator.spec.ts +341 -341
- package/src/__tests__/PostgresObjectionMigrator.spec.ts +578 -578
- package/src/__tests__/VitestObjectionTransactionIsolator.spec.ts +114 -114
- package/src/__tests__/benchmark.spec.ts +140 -0
- package/src/__tests__/better-auth.spec.ts +15 -15
- package/src/__tests__/faker.spec.ts +226 -137
- package/src/__tests__/integration.spec.ts +597 -597
- package/src/__tests__/utilities.spec.ts +211 -0
- package/src/aws.ts +104 -104
- package/src/benchmark.ts +12 -12
- package/src/better-auth.ts +286 -301
- package/src/faker.ts +153 -153
- package/src/helpers.ts +6 -6
- package/src/kysely.ts +33 -33
- package/src/logger.ts +10 -10
- package/src/objection.ts +31 -31
- package/src/os/directory.ts +11 -10
- package/src/timer.ts +1 -1
- package/test/globalSetup.ts +45 -45
- package/test/helpers.ts +189 -189
- package/test/migrations/1749664623372_user.ts +13 -13
- package/tsconfig.json +9 -0
- package/vitest.config.ts +4 -4
- package/dist/PostgresKyselyMigrator-CfytARcA.cjs.map +0 -1
- package/dist/PostgresKyselyMigrator-upT-hmrz.mjs.map +0 -1
- package/dist/PostgresMigrator-DFcNdCvD.cjs.map +0 -1
- package/dist/PostgresMigrator-DbuJGAVy.mjs.map +0 -1
- package/dist/PostgresObjectionMigrator-BG6ymgnt.cjs.map +0 -1
- package/dist/PostgresObjectionMigrator-DPj2pOpX.mjs.map +0 -1
- package/dist/VitestKyselyTransactionIsolator-CNURW8y6.mjs.map +0 -1
- package/dist/VitestKyselyTransactionIsolator-EvDLk5zg.cjs.map +0 -1
- package/dist/VitestObjectionTransactionIsolator-CM5KTAFA.cjs.map +0 -1
- package/dist/VitestObjectionTransactionIsolator-jQFaCz0u.mjs.map +0 -1
- package/dist/directory-BPf1LgNX.d.mts +0 -12
|
@@ -1,366 +1,366 @@
|
|
|
1
1
|
import { Client } from 'pg';
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
afterAll,
|
|
4
|
+
afterEach,
|
|
5
|
+
beforeAll,
|
|
6
|
+
beforeEach,
|
|
7
|
+
describe,
|
|
8
|
+
expect,
|
|
9
|
+
it,
|
|
10
|
+
vi,
|
|
11
11
|
} from 'vitest';
|
|
12
12
|
import { createTestDatabase } from '../../test/helpers';
|
|
13
13
|
import { PostgresMigrator } from '../PostgresMigrator';
|
|
14
14
|
|
|
15
15
|
// Create a concrete implementation for testing
|
|
16
16
|
class TestPostgresMigrator extends PostgresMigrator {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
17
|
+
public migrateCalled = false;
|
|
18
|
+
public migrateError?: Error;
|
|
19
|
+
public customMigrations: Array<() => Promise<void>> = [];
|
|
20
|
+
|
|
21
|
+
async migrate(): Promise<void> {
|
|
22
|
+
this.migrateCalled = true;
|
|
23
|
+
if (this.migrateError) {
|
|
24
|
+
throw this.migrateError;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Run any custom migrations
|
|
28
|
+
for (const migration of this.customMigrations) {
|
|
29
|
+
await migration();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
addMigration(migration: () => Promise<void>) {
|
|
34
|
+
this.customMigrations.push(migration);
|
|
35
|
+
}
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
describe('PostgresMigrator', () => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
39
|
+
let testDbName: string;
|
|
40
|
+
let cleanupDb: () => Promise<void>;
|
|
41
|
+
let consoleSpy: any;
|
|
42
|
+
|
|
43
|
+
beforeAll(async () => {
|
|
44
|
+
// Create a unique test database for each test run
|
|
45
|
+
testDbName = `test_postgres_migrator_${Date.now()}`;
|
|
46
|
+
cleanupDb = await createTestDatabase(testDbName);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
beforeEach(() => {
|
|
50
|
+
consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
afterEach(() => {
|
|
54
|
+
consoleSpy.mockRestore();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
afterAll(async () => {
|
|
58
|
+
await cleanupDb();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe('constructor', () => {
|
|
62
|
+
it('should create a PostgresMigrator instance', () => {
|
|
63
|
+
const migrator = new TestPostgresMigrator(
|
|
64
|
+
`postgresql://geekmidas:geekmidas@localhost:5432/${testDbName}`,
|
|
65
|
+
);
|
|
66
|
+
expect(migrator).toBeInstanceOf(PostgresMigrator);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
describe('start method', () => {
|
|
71
|
+
it('should create database, migrate, and return cleanup function', async () => {
|
|
72
|
+
const newDbName = `test_start_${Date.now()}`;
|
|
73
|
+
const uri = `postgresql://geekmidas:geekmidas@localhost:5432/${newDbName}`;
|
|
74
|
+
const migrator = new TestPostgresMigrator(uri);
|
|
75
|
+
|
|
76
|
+
// Add a simple migration to verify it runs
|
|
77
|
+
let migrationRan = false;
|
|
78
|
+
migrator.addMigration(async () => {
|
|
79
|
+
migrationRan = true;
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const cleanup = await migrator.start();
|
|
83
|
+
|
|
84
|
+
expect(migrator.migrateCalled).toBe(true);
|
|
85
|
+
expect(migrationRan).toBe(true);
|
|
86
|
+
expect(consoleSpy).toHaveBeenCalledWith(
|
|
87
|
+
`Migrating database: ${newDbName}`,
|
|
88
|
+
);
|
|
89
|
+
expect(typeof cleanup).toBe('function');
|
|
90
|
+
|
|
91
|
+
// Test cleanup
|
|
92
|
+
await cleanup();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('should handle existing database', async () => {
|
|
96
|
+
// Use the already created test database
|
|
97
|
+
const uri = `postgresql://geekmidas:geekmidas@localhost:5432/${testDbName}`;
|
|
98
|
+
const migrator = new TestPostgresMigrator(uri);
|
|
99
|
+
|
|
100
|
+
let migrationRan = false;
|
|
101
|
+
migrator.addMigration(async () => {
|
|
102
|
+
migrationRan = true;
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
const cleanup = await migrator.start();
|
|
106
|
+
|
|
107
|
+
expect(migrator.migrateCalled).toBe(true);
|
|
108
|
+
expect(migrationRan).toBe(true);
|
|
109
|
+
expect(typeof cleanup).toBe('function');
|
|
110
|
+
|
|
111
|
+
// Test cleanup (but don't actually run it since we need the db for other tests)
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('should handle URI with query parameters', async () => {
|
|
115
|
+
const queryDbName = `test_query_params_${Date.now()}`;
|
|
116
|
+
const uri = `postgresql://geekmidas:geekmidas@localhost:5432/${queryDbName}?ssl=false&timeout=30`;
|
|
117
|
+
const migrator = new TestPostgresMigrator(uri);
|
|
118
|
+
|
|
119
|
+
const cleanup = await migrator.start();
|
|
120
|
+
|
|
121
|
+
expect(migrator.migrateCalled).toBe(true);
|
|
122
|
+
expect(typeof cleanup).toBe('function');
|
|
123
|
+
|
|
124
|
+
await cleanup();
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('should clean up connections even if migration fails', async () => {
|
|
128
|
+
const failDbName = `test_fail_${Date.now()}`;
|
|
129
|
+
const uri = `postgresql://geekmidas:geekmidas@localhost:5432/${failDbName}`;
|
|
130
|
+
const migrator = new TestPostgresMigrator(uri);
|
|
131
|
+
migrator.migrateError = new Error('Migration failed');
|
|
132
|
+
|
|
133
|
+
await expect(migrator.start()).rejects.toThrow('Migration failed');
|
|
134
|
+
|
|
135
|
+
// Verify the database was still created but migration failed
|
|
136
|
+
expect(migrator.migrateCalled).toBe(true);
|
|
137
|
+
|
|
138
|
+
// Cleanup the failed database
|
|
139
|
+
const cleanupClient = new Client({
|
|
140
|
+
host: 'localhost',
|
|
141
|
+
port: 5432,
|
|
142
|
+
user: 'geekmidas',
|
|
143
|
+
password: 'geekmidas',
|
|
144
|
+
database: 'postgres',
|
|
145
|
+
});
|
|
146
|
+
try {
|
|
147
|
+
await cleanupClient.connect();
|
|
148
|
+
await cleanupClient.query(`DROP DATABASE IF EXISTS "${failDbName}"`);
|
|
149
|
+
} finally {
|
|
150
|
+
await cleanupClient.end();
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('should return cleanup function that drops database', async () => {
|
|
155
|
+
const cleanupDbName = `test_cleanup_${Date.now()}`;
|
|
156
|
+
const uri = `postgresql://geekmidas:geekmidas@localhost:5432/${cleanupDbName}`;
|
|
157
|
+
const migrator = new TestPostgresMigrator(uri);
|
|
158
|
+
|
|
159
|
+
const cleanup = await migrator.start();
|
|
160
|
+
|
|
161
|
+
expect(migrator.migrateCalled).toBe(true);
|
|
162
|
+
expect(typeof cleanup).toBe('function');
|
|
163
|
+
|
|
164
|
+
// Verify database exists before cleanup
|
|
165
|
+
const checkClient = new Client({
|
|
166
|
+
host: 'localhost',
|
|
167
|
+
port: 5432,
|
|
168
|
+
user: 'geekmidas',
|
|
169
|
+
password: 'geekmidas',
|
|
170
|
+
database: 'postgres',
|
|
171
|
+
});
|
|
172
|
+
await checkClient.connect();
|
|
173
|
+
const beforeResult = await checkClient.query(
|
|
174
|
+
`SELECT * FROM pg_catalog.pg_database WHERE datname = $1`,
|
|
175
|
+
[cleanupDbName],
|
|
176
|
+
);
|
|
177
|
+
expect(beforeResult.rowCount).toBe(1);
|
|
178
|
+
await checkClient.end();
|
|
179
|
+
|
|
180
|
+
// Call cleanup
|
|
181
|
+
await cleanup();
|
|
182
|
+
|
|
183
|
+
// Verify database was dropped
|
|
184
|
+
const checkClient2 = new Client({
|
|
185
|
+
host: 'localhost',
|
|
186
|
+
port: 5432,
|
|
187
|
+
user: 'geekmidas',
|
|
188
|
+
password: 'geekmidas',
|
|
189
|
+
database: 'postgres',
|
|
190
|
+
});
|
|
191
|
+
await checkClient2.connect();
|
|
192
|
+
const afterResult = await checkClient2.query(
|
|
193
|
+
`SELECT * FROM pg_catalog.pg_database WHERE datname = $1`,
|
|
194
|
+
[cleanupDbName],
|
|
195
|
+
);
|
|
196
|
+
expect(afterResult.rowCount).toBe(0);
|
|
197
|
+
await checkClient2.end();
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
describe('database creation', () => {
|
|
202
|
+
it('should handle connection errors gracefully', async () => {
|
|
203
|
+
// Use invalid credentials to test connection error
|
|
204
|
+
const badDbName = `test_bad_connection_${Date.now()}`;
|
|
205
|
+
const uri = `postgresql://invalid_user:invalid_pass@localhost:5432/${badDbName}`;
|
|
206
|
+
const migrator = new TestPostgresMigrator(uri);
|
|
207
|
+
|
|
208
|
+
await expect(migrator.start()).rejects.toThrow();
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it('should handle invalid database names', async () => {
|
|
212
|
+
// Use a database name with invalid characters
|
|
213
|
+
const invalidDbName = 'test-invalid-db-name!';
|
|
214
|
+
const uri = `postgresql://geekmidas:geekmidas@localhost:5432/${invalidDbName}`;
|
|
215
|
+
const migrator = new TestPostgresMigrator(uri);
|
|
216
|
+
|
|
217
|
+
await expect(migrator.start).rejects.toThrow();
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
describe('URI parsing', () => {
|
|
222
|
+
it('should parse different URI formats correctly', async () => {
|
|
223
|
+
const testDbName = `test_uri_parsing_${Date.now()}`;
|
|
224
|
+
const uri = `postgresql://geekmidas:geekmidas@localhost:5432/${testDbName}`;
|
|
225
|
+
const migrator = new TestPostgresMigrator(uri);
|
|
226
|
+
|
|
227
|
+
const cleanup = await migrator.start();
|
|
228
|
+
|
|
229
|
+
expect(migrator.migrateCalled).toBe(true);
|
|
230
|
+
expect(typeof cleanup).toBe('function');
|
|
231
|
+
|
|
232
|
+
await cleanup();
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
describe('error handling', () => {
|
|
237
|
+
it('should propagate migration errors', async () => {
|
|
238
|
+
const errorDbName = `test_migration_error_${Date.now()}`;
|
|
239
|
+
const uri = `postgresql://geekmidas:geekmidas@localhost:5432/${errorDbName}`;
|
|
240
|
+
const migrator = new TestPostgresMigrator(uri);
|
|
241
|
+
const migrationError = new Error('Custom migration error');
|
|
242
|
+
migrator.migrateError = migrationError;
|
|
243
|
+
|
|
244
|
+
await expect(migrator.start()).rejects.toThrow('Custom migration error');
|
|
245
|
+
|
|
246
|
+
// Cleanup the created database
|
|
247
|
+
const cleanupClient = new Client({
|
|
248
|
+
host: 'localhost',
|
|
249
|
+
port: 5432,
|
|
250
|
+
user: 'geekmidas',
|
|
251
|
+
password: 'geekmidas',
|
|
252
|
+
database: 'postgres',
|
|
253
|
+
});
|
|
254
|
+
try {
|
|
255
|
+
await cleanupClient.connect();
|
|
256
|
+
await cleanupClient.query(`DROP DATABASE IF EXISTS "${errorDbName}"`);
|
|
257
|
+
} finally {
|
|
258
|
+
await cleanupClient.end();
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it('should handle cleanup errors gracefully', async () => {
|
|
263
|
+
const cleanupErrorDbName = `test_cleanup_error_${Date.now()}`;
|
|
264
|
+
const uri = `postgresql://geekmidas:geekmidas@localhost:5432/${cleanupErrorDbName}`;
|
|
265
|
+
const migrator = new TestPostgresMigrator(uri);
|
|
266
|
+
|
|
267
|
+
const cleanup = await migrator.start();
|
|
268
|
+
|
|
269
|
+
// Manually drop the database to cause a cleanup error
|
|
270
|
+
const adminClient = new Client({
|
|
271
|
+
host: 'localhost',
|
|
272
|
+
port: 5432,
|
|
273
|
+
user: 'geekmidas',
|
|
274
|
+
password: 'geekmidas',
|
|
275
|
+
database: 'postgres',
|
|
276
|
+
});
|
|
277
|
+
await adminClient.connect();
|
|
278
|
+
await adminClient.query(
|
|
279
|
+
`DROP DATABASE IF EXISTS "${cleanupErrorDbName}"`,
|
|
280
|
+
);
|
|
281
|
+
await adminClient.end();
|
|
282
|
+
|
|
283
|
+
// Now cleanup should fail because database doesn't exist
|
|
284
|
+
await expect(cleanup()).rejects.toThrow();
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
describe('abstract method', () => {
|
|
289
|
+
it('should require concrete implementation of migrate method', () => {
|
|
290
|
+
// TypeScript ensures abstract methods are implemented
|
|
291
|
+
// This test verifies the TestPostgresMigrator implements migrate
|
|
292
|
+
const migrator = new TestPostgresMigrator(
|
|
293
|
+
`postgresql://geekmidas:geekmidas@localhost:5432/${testDbName}`,
|
|
294
|
+
);
|
|
295
|
+
expect(typeof migrator.migrate).toBe('function');
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
describe('integration scenarios', () => {
|
|
300
|
+
it('should handle complete workflow', async () => {
|
|
301
|
+
const integrationDbName = `test_integration_${Date.now()}`;
|
|
302
|
+
const uri = `postgresql://geekmidas:geekmidas@localhost:5432/${integrationDbName}`;
|
|
303
|
+
const migrator = new TestPostgresMigrator(uri);
|
|
304
|
+
|
|
305
|
+
// Add a migration that creates a table
|
|
306
|
+
migrator.addMigration(async () => {
|
|
307
|
+
const client = new Client({
|
|
308
|
+
host: 'localhost',
|
|
309
|
+
port: 5432,
|
|
310
|
+
user: 'geekmidas',
|
|
311
|
+
password: 'geekmidas',
|
|
312
|
+
database: integrationDbName,
|
|
313
|
+
});
|
|
314
|
+
await client.connect();
|
|
315
|
+
await client.query(`
|
|
316
316
|
CREATE TABLE IF NOT EXISTS test_table (
|
|
317
317
|
id SERIAL PRIMARY KEY,
|
|
318
318
|
name VARCHAR(255) NOT NULL
|
|
319
319
|
)
|
|
320
320
|
`);
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
321
|
+
await client.end();
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
// Start migration
|
|
325
|
+
const cleanup = await migrator.start();
|
|
326
|
+
|
|
327
|
+
expect(migrator.migrateCalled).toBe(true);
|
|
328
|
+
expect(consoleSpy).toHaveBeenCalledWith(
|
|
329
|
+
`Migrating database: ${integrationDbName}`,
|
|
330
|
+
);
|
|
331
|
+
|
|
332
|
+
// Verify the table was created
|
|
333
|
+
const verifyClient = new Client({
|
|
334
|
+
host: 'localhost',
|
|
335
|
+
port: 5432,
|
|
336
|
+
user: 'geekmidas',
|
|
337
|
+
password: 'geekmidas',
|
|
338
|
+
database: integrationDbName,
|
|
339
|
+
});
|
|
340
|
+
await verifyClient.connect();
|
|
341
|
+
const tableResult = await verifyClient.query(`
|
|
342
342
|
SELECT table_name FROM information_schema.tables
|
|
343
343
|
WHERE table_schema = 'public' AND table_name = 'test_table'
|
|
344
344
|
`);
|
|
345
|
-
|
|
346
|
-
|
|
345
|
+
expect(tableResult.rowCount).toBe(1);
|
|
346
|
+
await verifyClient.end();
|
|
347
347
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
348
|
+
// Cleanup
|
|
349
|
+
await cleanup();
|
|
350
|
+
});
|
|
351
351
|
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
352
|
+
it('should handle database that already exists and cleanup', async () => {
|
|
353
|
+
// Use the existing test database
|
|
354
|
+
const uri = `postgresql://geekmidas:geekmidas@localhost:5432/${testDbName}`;
|
|
355
|
+
const migrator = new TestPostgresMigrator(uri);
|
|
356
356
|
|
|
357
|
-
|
|
358
|
-
|
|
357
|
+
// Start migration (database already exists)
|
|
358
|
+
const cleanup = await migrator.start();
|
|
359
359
|
|
|
360
|
-
|
|
360
|
+
expect(migrator.migrateCalled).toBe(true);
|
|
361
361
|
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
362
|
+
// Don't call cleanup as we need the database for other tests
|
|
363
|
+
expect(typeof cleanup).toBe('function');
|
|
364
|
+
});
|
|
365
|
+
});
|
|
366
366
|
});
|