@geekmidas/testkit 0.0.4 → 0.0.5
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.mjs +1 -1
- package/dist/{KyselyFactory-BGvSMLtd.cjs → KyselyFactory-BX7Kv2uP.cjs} +1 -1
- package/dist/{KyselyFactory-ionH4gvk.mjs → KyselyFactory-pOMOFQWE.mjs} +2 -2
- package/dist/KyselyFactory.cjs +2 -2
- package/dist/KyselyFactory.mjs +3 -3
- package/dist/{ObjectionFactory-CFrtXe7i.mjs → ObjectionFactory-ChuX8sZN.mjs} +1 -1
- package/dist/ObjectionFactory.mjs +2 -2
- package/dist/{PostgresKyselyMigrator-CbtiZgfI.mjs → PostgresKyselyMigrator-D8fm35-s.mjs} +1 -1
- package/dist/{PostgresKyselyMigrator-Cxf2Dp9y.cjs → PostgresKyselyMigrator-JTY2LfwD.cjs} +2 -2
- package/dist/PostgresKyselyMigrator.cjs +2 -2
- package/dist/PostgresKyselyMigrator.mjs +2 -2
- package/dist/{PostgresMigrator-eqyAFSf-.cjs → PostgresMigrator-Bz-tnjB6.cjs} +1 -1
- package/dist/PostgresMigrator.cjs +1 -1
- package/dist/PostgresMigrator.mjs +1 -1
- package/dist/{VitestKyselyTransactionIsolator-DXjWQtDN.mjs → VitestKyselyTransactionIsolator-BS3R-V0I.mjs} +1 -1
- package/dist/{VitestKyselyTransactionIsolator-Dh2AgJDd.cjs → VitestKyselyTransactionIsolator-DWSTKIe3.cjs} +1 -1
- package/dist/VitestKyselyTransactionIsolator.cjs +2 -3
- package/dist/VitestKyselyTransactionIsolator.mjs +2 -3
- package/dist/{VitestTransactionIsolator-pLwsDo_A.mjs → VitestTransactionIsolator-BjVXqFs6.mjs} +1 -1
- package/dist/{VitestTransactionIsolator-zK5NJ7DQ.cjs → VitestTransactionIsolator-Bx2c4OzK.cjs} +3 -2
- package/dist/VitestTransactionIsolator.cjs +1 -2
- package/dist/VitestTransactionIsolator.mjs +1 -2
- package/dist/__tests__/Factory.spec.cjs +42 -42
- package/dist/__tests__/Factory.spec.mjs +23 -24
- package/dist/__tests__/KyselyFactory.spec.cjs +46 -47
- package/dist/__tests__/KyselyFactory.spec.mjs +40 -41
- package/dist/__tests__/ObjectionFactory.spec.cjs +80 -81
- package/dist/__tests__/ObjectionFactory.spec.mjs +52 -53
- package/dist/__tests__/PostgresMigrator.spec.cjs +59 -60
- package/dist/__tests__/PostgresMigrator.spec.mjs +31 -32
- package/dist/__tests__/faker.spec.cjs +60 -60
- package/dist/__tests__/faker.spec.mjs +35 -36
- package/dist/__tests__/integration.spec.cjs +40 -40
- package/dist/__tests__/integration.spec.mjs +42 -43
- package/dist/{chunk-DWy1uDak.cjs → chunk-CUT6urMc.cjs} +0 -9
- package/dist/example.cjs +2 -2
- package/dist/example.mjs +3 -3
- package/dist/{faker-h6CkRloU.cjs → faker-caz-8zt8.cjs} +1 -1
- package/dist/faker.cjs +1 -1
- package/dist/faker.mjs +1 -1
- package/dist/{helpers-C_RZk04R.cjs → helpers-B9Jdk_C7.cjs} +3 -3
- package/dist/{helpers-C2NH7xcz.cjs → helpers-DKEBHABj.cjs} +1 -1
- package/dist/{helpers-BnARb5Ap.mjs → helpers-DOiGIkaU.mjs} +2 -2
- package/dist/helpers.cjs +3 -4
- package/dist/helpers.mjs +3 -4
- package/dist/kysely.cjs +6 -7
- package/dist/kysely.mjs +7 -8
- package/dist/objection.mjs +2 -2
- package/package.json +2 -1
- package/dist/dist-BM2KvLG1.mjs +0 -5618
- package/dist/dist-DE3gAxQI.cjs +0 -5736
- package/dist/magic-string.es-C6yzoryu.mjs +0 -1014
- package/dist/magic-string.es-jdtJrR0A.cjs +0 -1015
- package/dist/vi.bdSIJ99Y-BgRxGeO2.mjs +0 -9382
- package/dist/vi.bdSIJ99Y-CFuzUeY6.cjs +0 -9393
- /package/dist/{Factory-D52Lsc6Z.mjs → Factory-DlzMkMzb.mjs} +0 -0
- /package/dist/{PostgresMigrator-DqeuPy-e.mjs → PostgresMigrator-CEoRKTdq.mjs} +0 -0
- /package/dist/{faker-cGCFcrj2.mjs → faker-BwaXA_RF.mjs} +0 -0
- /package/dist/{helpers-CukcFAU9.mjs → helpers-BfuX-cjN.mjs} +0 -0
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
const require_chunk = require('../chunk-
|
|
1
|
+
const require_chunk = require('../chunk-CUT6urMc.cjs');
|
|
2
2
|
require('../Factory-DREHoms3.cjs');
|
|
3
|
-
require('../faker-
|
|
4
|
-
const require_KyselyFactory = require('../KyselyFactory-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
require('../
|
|
8
|
-
require('../
|
|
9
|
-
const require_helpers = require('../helpers-C_RZk04R.cjs');
|
|
10
|
-
const require_helpers$1 = require('../helpers-C2NH7xcz.cjs');
|
|
3
|
+
require('../faker-caz-8zt8.cjs');
|
|
4
|
+
const require_KyselyFactory = require('../KyselyFactory-BX7Kv2uP.cjs');
|
|
5
|
+
require('../VitestTransactionIsolator-Bx2c4OzK.cjs');
|
|
6
|
+
require('../VitestKyselyTransactionIsolator-DWSTKIe3.cjs');
|
|
7
|
+
const require_helpers = require('../helpers-B9Jdk_C7.cjs');
|
|
8
|
+
const require_helpers$1 = require('../helpers-DKEBHABj.cjs');
|
|
11
9
|
const pg = require_chunk.__toESM(require("pg"));
|
|
10
|
+
const vitest = require_chunk.__toESM(require("vitest"));
|
|
12
11
|
|
|
13
12
|
//#region src/__tests__/KyselyFactory.spec.ts
|
|
14
13
|
const db = require_helpers.createKyselyDb(require_helpers$1.TEST_DATABASE_CONFIG);
|
|
@@ -17,10 +16,10 @@ const int8TypeId = 20;
|
|
|
17
16
|
pg.default.types.setTypeParser(int8TypeId, (val) => {
|
|
18
17
|
return parseInt(val, 10);
|
|
19
18
|
});
|
|
20
|
-
|
|
19
|
+
(0, vitest.describe)("KyselyFactory", () => {
|
|
21
20
|
let db$1;
|
|
22
21
|
let trx;
|
|
23
|
-
|
|
22
|
+
(0, vitest.describe)("KyselyFactory.insert", () => {
|
|
24
23
|
itWithTransaction("should insert a record with defaults", async ({ trx: trx$1 }) => {
|
|
25
24
|
const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
26
25
|
name: "John Doe",
|
|
@@ -30,12 +29,12 @@ require_dist.describe("KyselyFactory", () => {
|
|
|
30
29
|
const builders = { user: userBuilder };
|
|
31
30
|
const factory = new require_KyselyFactory.KyselyFactory(builders, {}, trx$1);
|
|
32
31
|
const user = await factory.insert("user");
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
(0, vitest.expect)(user).toBeDefined();
|
|
33
|
+
(0, vitest.expect)(user.id).toBeDefined();
|
|
34
|
+
(0, vitest.expect)(user.name).toBe("John Doe");
|
|
35
|
+
(0, vitest.expect)(user.email).toContain("user");
|
|
36
|
+
(0, vitest.expect)(user.email).toContain("@example.com");
|
|
37
|
+
(0, vitest.expect)(user.createdAt).toBeInstanceOf(Date);
|
|
39
38
|
});
|
|
40
39
|
itWithTransaction("should override defaults with provided attributes", async ({ trx: trx$1 }) => {
|
|
41
40
|
const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
@@ -51,8 +50,8 @@ require_dist.describe("KyselyFactory", () => {
|
|
|
51
50
|
email: customEmail,
|
|
52
51
|
name: customName
|
|
53
52
|
});
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
(0, vitest.expect)(user.name).toBe(customName);
|
|
54
|
+
(0, vitest.expect)(user.email).toBe(customEmail);
|
|
56
55
|
});
|
|
57
56
|
itWithTransaction("should handle relations", async ({ trx: trx$1 }) => {
|
|
58
57
|
const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
@@ -82,17 +81,17 @@ require_dist.describe("KyselyFactory", () => {
|
|
|
82
81
|
};
|
|
83
82
|
const factory = new require_KyselyFactory.KyselyFactory(builders, {}, trx$1);
|
|
84
83
|
const post = await factory.insert("post", { title: "Test Post" });
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
84
|
+
(0, vitest.expect)(post).toBeDefined();
|
|
85
|
+
(0, vitest.expect)(post.title).toBe("Test Post");
|
|
86
|
+
(0, vitest.expect)(post.userId).toBeDefined();
|
|
87
|
+
(0, vitest.expect)(typeof post.userId).toBe("number");
|
|
89
88
|
});
|
|
90
89
|
itWithTransaction("should throw error for non-existent builder", async ({ trx: trx$1 }) => {
|
|
91
90
|
const factory = new require_KyselyFactory.KyselyFactory({}, {}, trx$1);
|
|
92
|
-
await
|
|
91
|
+
await (0, vitest.expect)(factory.insert("nonExistent")).rejects.toThrow("Factory \"nonExistent\" does not exist");
|
|
93
92
|
});
|
|
94
93
|
});
|
|
95
|
-
|
|
94
|
+
(0, vitest.describe)("KyselyFactory.insertMany", () => {
|
|
96
95
|
itWithTransaction("should insert multiple records with same attributes", async ({ trx: trx$1 }) => {
|
|
97
96
|
const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
98
97
|
name: "John Doe",
|
|
@@ -102,11 +101,11 @@ require_dist.describe("KyselyFactory", () => {
|
|
|
102
101
|
const builders = { user: userBuilder };
|
|
103
102
|
const factory = new require_KyselyFactory.KyselyFactory(builders, {}, trx$1);
|
|
104
103
|
const users = await factory.insertMany(3, "user");
|
|
105
|
-
|
|
104
|
+
(0, vitest.expect)(users).toHaveLength(3);
|
|
106
105
|
users.forEach((user, index) => {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
106
|
+
(0, vitest.expect)(user.id).toBeDefined();
|
|
107
|
+
(0, vitest.expect)(user.name).toBe("John Doe");
|
|
108
|
+
(0, vitest.expect)(user.email).toContain("@example.com");
|
|
110
109
|
});
|
|
111
110
|
});
|
|
112
111
|
itWithTransaction("should insert multiple records with dynamic attributes", async ({ trx: trx$1 }) => {
|
|
@@ -117,17 +116,17 @@ require_dist.describe("KyselyFactory", () => {
|
|
|
117
116
|
const builders = { user: userBuilder };
|
|
118
117
|
const factory = new require_KyselyFactory.KyselyFactory(builders, {}, trx$1);
|
|
119
118
|
const users = await factory.insertMany(3, "user", (idx) => ({ name: `User ${idx}` }));
|
|
120
|
-
|
|
119
|
+
(0, vitest.expect)(users).toHaveLength(3);
|
|
121
120
|
users.forEach((user, index) => {
|
|
122
|
-
|
|
121
|
+
(0, vitest.expect)(user.name).toBe(`User ${index}`);
|
|
123
122
|
});
|
|
124
123
|
});
|
|
125
124
|
itWithTransaction("should throw error for non-existent builder", async ({ trx: trx$1 }) => {
|
|
126
125
|
const factory = new require_KyselyFactory.KyselyFactory({}, {}, trx$1);
|
|
127
|
-
await
|
|
126
|
+
await (0, vitest.expect)(factory.insertMany(2, "nonExistent")).rejects.toThrow("Builder \"nonExistent\" is not registered");
|
|
128
127
|
});
|
|
129
128
|
});
|
|
130
|
-
|
|
129
|
+
(0, vitest.describe)("KyselyFactory.createBuilder", () => {
|
|
131
130
|
itWithTransaction("should work with async defaults", async ({ trx: trx$1 }) => {
|
|
132
131
|
let counter = 0;
|
|
133
132
|
const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder("users", async (attrs) => {
|
|
@@ -143,11 +142,11 @@ require_dist.describe("KyselyFactory", () => {
|
|
|
143
142
|
const factory = new require_KyselyFactory.KyselyFactory(builders, {}, trx$1);
|
|
144
143
|
const user1 = await factory.insert("user");
|
|
145
144
|
const user2 = await factory.insert("user");
|
|
146
|
-
|
|
147
|
-
|
|
145
|
+
(0, vitest.expect)(user1.name).toBe("Async User 1");
|
|
146
|
+
(0, vitest.expect)(user2.name).toBe("Async User 2");
|
|
148
147
|
});
|
|
149
148
|
});
|
|
150
|
-
|
|
149
|
+
(0, vitest.describe)("KyselyFactory.seed", () => {
|
|
151
150
|
itWithTransaction("should execute seed functions", async ({ trx: trx$1 }) => {
|
|
152
151
|
const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
153
152
|
name: "John Doe",
|
|
@@ -163,9 +162,9 @@ require_dist.describe("KyselyFactory", () => {
|
|
|
163
162
|
}) };
|
|
164
163
|
const factory = new require_KyselyFactory.KyselyFactory(builders, seeds, trx$1);
|
|
165
164
|
const adminUser = await factory.seed("createAdminUser");
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
165
|
+
(0, vitest.expect)(adminUser).toBeDefined();
|
|
166
|
+
(0, vitest.expect)(adminUser.name).toBe("Admin User");
|
|
167
|
+
(0, vitest.expect)(adminUser.email).toBe("admin@example.com");
|
|
169
168
|
});
|
|
170
169
|
itWithTransaction("should pass attributes to seed functions", async ({ trx: trx$1 }) => {
|
|
171
170
|
const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
@@ -182,15 +181,15 @@ require_dist.describe("KyselyFactory", () => {
|
|
|
182
181
|
name: "Custom User",
|
|
183
182
|
email: "custom@test.com"
|
|
184
183
|
});
|
|
185
|
-
|
|
186
|
-
|
|
184
|
+
(0, vitest.expect)(customUser.name).toBe("Custom User");
|
|
185
|
+
(0, vitest.expect)(customUser.email).toBe("custom@test.com");
|
|
187
186
|
});
|
|
188
187
|
itWithTransaction("should throw error for non-existent seed", async ({ trx: trx$1 }) => {
|
|
189
188
|
const factory = new require_KyselyFactory.KyselyFactory({}, {}, trx$1);
|
|
190
|
-
|
|
189
|
+
(0, vitest.expect)(() => factory.seed("nonExistent")).toThrow("Seed \"nonExistent\" is not registered");
|
|
191
190
|
});
|
|
192
191
|
});
|
|
193
|
-
|
|
192
|
+
(0, vitest.describe)("Factory integration", () => {
|
|
194
193
|
itWithTransaction("should work with controlled transactions", async ({ trx: trx$1 }) => {
|
|
195
194
|
const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
196
195
|
name: "John Doe",
|
|
@@ -201,8 +200,8 @@ require_dist.describe("KyselyFactory", () => {
|
|
|
201
200
|
const factory = new require_KyselyFactory.KyselyFactory(builders, {}, trx$1);
|
|
202
201
|
const user = await factory.insert("user");
|
|
203
202
|
const foundUser = await trx$1.selectFrom("users").selectAll().where("id", "=", user.id).executeTakeFirst();
|
|
204
|
-
|
|
205
|
-
|
|
203
|
+
(0, vitest.expect)(foundUser).toBeDefined();
|
|
204
|
+
(0, vitest.expect)(foundUser?.id).toBe(user.id);
|
|
206
205
|
});
|
|
207
206
|
itWithTransaction("should work with factory passed to defaults", async ({ trx: trx$1 }) => {
|
|
208
207
|
const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
@@ -225,9 +224,9 @@ require_dist.describe("KyselyFactory", () => {
|
|
|
225
224
|
};
|
|
226
225
|
const factory = new require_KyselyFactory.KyselyFactory(builders, {}, trx$1);
|
|
227
226
|
const post = await factory.insert("post");
|
|
228
|
-
|
|
227
|
+
(0, vitest.expect)(post.userId).toBeDefined();
|
|
229
228
|
const relatedUser = await trx$1.selectFrom("users").selectAll().where("id", "=", post.userId).executeTakeFirst();
|
|
230
|
-
|
|
229
|
+
(0, vitest.expect)(relatedUser).toBeDefined();
|
|
231
230
|
});
|
|
232
231
|
});
|
|
233
232
|
});
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import "../
|
|
3
|
-
import "../
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import "../
|
|
7
|
-
import "../
|
|
8
|
-
import { createKyselyDb, wrapVitestKyselyTransaction } from "../helpers-BnARb5Ap.mjs";
|
|
9
|
-
import { TEST_DATABASE_CONFIG, createTestTables } from "../helpers-CukcFAU9.mjs";
|
|
1
|
+
import "../Factory-DlzMkMzb.mjs";
|
|
2
|
+
import "../faker-BwaXA_RF.mjs";
|
|
3
|
+
import { KyselyFactory } from "../KyselyFactory-pOMOFQWE.mjs";
|
|
4
|
+
import "../VitestTransactionIsolator-BjVXqFs6.mjs";
|
|
5
|
+
import "../VitestKyselyTransactionIsolator-BS3R-V0I.mjs";
|
|
6
|
+
import { createKyselyDb, wrapVitestKyselyTransaction } from "../helpers-DOiGIkaU.mjs";
|
|
7
|
+
import { TEST_DATABASE_CONFIG, createTestTables } from "../helpers-BfuX-cjN.mjs";
|
|
10
8
|
import pg from "pg";
|
|
9
|
+
import { describe, expect } from "vitest";
|
|
11
10
|
|
|
12
11
|
//#region src/__tests__/KyselyFactory.spec.ts
|
|
13
12
|
const db = createKyselyDb(TEST_DATABASE_CONFIG);
|
|
@@ -29,12 +28,12 @@ describe("KyselyFactory", () => {
|
|
|
29
28
|
const builders = { user: userBuilder };
|
|
30
29
|
const factory = new KyselyFactory(builders, {}, trx$1);
|
|
31
30
|
const user = await factory.insert("user");
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
expect(user).toBeDefined();
|
|
32
|
+
expect(user.id).toBeDefined();
|
|
33
|
+
expect(user.name).toBe("John Doe");
|
|
34
|
+
expect(user.email).toContain("user");
|
|
35
|
+
expect(user.email).toContain("@example.com");
|
|
36
|
+
expect(user.createdAt).toBeInstanceOf(Date);
|
|
38
37
|
});
|
|
39
38
|
itWithTransaction("should override defaults with provided attributes", async ({ trx: trx$1 }) => {
|
|
40
39
|
const userBuilder = KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
@@ -50,8 +49,8 @@ describe("KyselyFactory", () => {
|
|
|
50
49
|
email: customEmail,
|
|
51
50
|
name: customName
|
|
52
51
|
});
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
expect(user.name).toBe(customName);
|
|
53
|
+
expect(user.email).toBe(customEmail);
|
|
55
54
|
});
|
|
56
55
|
itWithTransaction("should handle relations", async ({ trx: trx$1 }) => {
|
|
57
56
|
const userBuilder = KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
@@ -81,14 +80,14 @@ describe("KyselyFactory", () => {
|
|
|
81
80
|
};
|
|
82
81
|
const factory = new KyselyFactory(builders, {}, trx$1);
|
|
83
82
|
const post = await factory.insert("post", { title: "Test Post" });
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
83
|
+
expect(post).toBeDefined();
|
|
84
|
+
expect(post.title).toBe("Test Post");
|
|
85
|
+
expect(post.userId).toBeDefined();
|
|
86
|
+
expect(typeof post.userId).toBe("number");
|
|
88
87
|
});
|
|
89
88
|
itWithTransaction("should throw error for non-existent builder", async ({ trx: trx$1 }) => {
|
|
90
89
|
const factory = new KyselyFactory({}, {}, trx$1);
|
|
91
|
-
await
|
|
90
|
+
await expect(factory.insert("nonExistent")).rejects.toThrow("Factory \"nonExistent\" does not exist");
|
|
92
91
|
});
|
|
93
92
|
});
|
|
94
93
|
describe("KyselyFactory.insertMany", () => {
|
|
@@ -101,11 +100,11 @@ describe("KyselyFactory", () => {
|
|
|
101
100
|
const builders = { user: userBuilder };
|
|
102
101
|
const factory = new KyselyFactory(builders, {}, trx$1);
|
|
103
102
|
const users = await factory.insertMany(3, "user");
|
|
104
|
-
|
|
103
|
+
expect(users).toHaveLength(3);
|
|
105
104
|
users.forEach((user, index) => {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
105
|
+
expect(user.id).toBeDefined();
|
|
106
|
+
expect(user.name).toBe("John Doe");
|
|
107
|
+
expect(user.email).toContain("@example.com");
|
|
109
108
|
});
|
|
110
109
|
});
|
|
111
110
|
itWithTransaction("should insert multiple records with dynamic attributes", async ({ trx: trx$1 }) => {
|
|
@@ -116,14 +115,14 @@ describe("KyselyFactory", () => {
|
|
|
116
115
|
const builders = { user: userBuilder };
|
|
117
116
|
const factory = new KyselyFactory(builders, {}, trx$1);
|
|
118
117
|
const users = await factory.insertMany(3, "user", (idx) => ({ name: `User ${idx}` }));
|
|
119
|
-
|
|
118
|
+
expect(users).toHaveLength(3);
|
|
120
119
|
users.forEach((user, index) => {
|
|
121
|
-
|
|
120
|
+
expect(user.name).toBe(`User ${index}`);
|
|
122
121
|
});
|
|
123
122
|
});
|
|
124
123
|
itWithTransaction("should throw error for non-existent builder", async ({ trx: trx$1 }) => {
|
|
125
124
|
const factory = new KyselyFactory({}, {}, trx$1);
|
|
126
|
-
await
|
|
125
|
+
await expect(factory.insertMany(2, "nonExistent")).rejects.toThrow("Builder \"nonExistent\" is not registered");
|
|
127
126
|
});
|
|
128
127
|
});
|
|
129
128
|
describe("KyselyFactory.createBuilder", () => {
|
|
@@ -142,8 +141,8 @@ describe("KyselyFactory", () => {
|
|
|
142
141
|
const factory = new KyselyFactory(builders, {}, trx$1);
|
|
143
142
|
const user1 = await factory.insert("user");
|
|
144
143
|
const user2 = await factory.insert("user");
|
|
145
|
-
|
|
146
|
-
|
|
144
|
+
expect(user1.name).toBe("Async User 1");
|
|
145
|
+
expect(user2.name).toBe("Async User 2");
|
|
147
146
|
});
|
|
148
147
|
});
|
|
149
148
|
describe("KyselyFactory.seed", () => {
|
|
@@ -162,9 +161,9 @@ describe("KyselyFactory", () => {
|
|
|
162
161
|
}) };
|
|
163
162
|
const factory = new KyselyFactory(builders, seeds, trx$1);
|
|
164
163
|
const adminUser = await factory.seed("createAdminUser");
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
164
|
+
expect(adminUser).toBeDefined();
|
|
165
|
+
expect(adminUser.name).toBe("Admin User");
|
|
166
|
+
expect(adminUser.email).toBe("admin@example.com");
|
|
168
167
|
});
|
|
169
168
|
itWithTransaction("should pass attributes to seed functions", async ({ trx: trx$1 }) => {
|
|
170
169
|
const userBuilder = KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
@@ -181,12 +180,12 @@ describe("KyselyFactory", () => {
|
|
|
181
180
|
name: "Custom User",
|
|
182
181
|
email: "custom@test.com"
|
|
183
182
|
});
|
|
184
|
-
|
|
185
|
-
|
|
183
|
+
expect(customUser.name).toBe("Custom User");
|
|
184
|
+
expect(customUser.email).toBe("custom@test.com");
|
|
186
185
|
});
|
|
187
186
|
itWithTransaction("should throw error for non-existent seed", async ({ trx: trx$1 }) => {
|
|
188
187
|
const factory = new KyselyFactory({}, {}, trx$1);
|
|
189
|
-
|
|
188
|
+
expect(() => factory.seed("nonExistent")).toThrow("Seed \"nonExistent\" is not registered");
|
|
190
189
|
});
|
|
191
190
|
});
|
|
192
191
|
describe("Factory integration", () => {
|
|
@@ -200,8 +199,8 @@ describe("KyselyFactory", () => {
|
|
|
200
199
|
const factory = new KyselyFactory(builders, {}, trx$1);
|
|
201
200
|
const user = await factory.insert("user");
|
|
202
201
|
const foundUser = await trx$1.selectFrom("users").selectAll().where("id", "=", user.id).executeTakeFirst();
|
|
203
|
-
|
|
204
|
-
|
|
202
|
+
expect(foundUser).toBeDefined();
|
|
203
|
+
expect(foundUser?.id).toBe(user.id);
|
|
205
204
|
});
|
|
206
205
|
itWithTransaction("should work with factory passed to defaults", async ({ trx: trx$1 }) => {
|
|
207
206
|
const userBuilder = KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
@@ -224,9 +223,9 @@ describe("KyselyFactory", () => {
|
|
|
224
223
|
};
|
|
225
224
|
const factory = new KyselyFactory(builders, {}, trx$1);
|
|
226
225
|
const post = await factory.insert("post");
|
|
227
|
-
|
|
226
|
+
expect(post.userId).toBeDefined();
|
|
228
227
|
const relatedUser = await trx$1.selectFrom("users").selectAll().where("id", "=", post.userId).executeTakeFirst();
|
|
229
|
-
|
|
228
|
+
expect(relatedUser).toBeDefined();
|
|
230
229
|
});
|
|
231
230
|
});
|
|
232
231
|
});
|