@geekmidas/testkit 0.0.14 → 0.0.16
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-D7P3bKKb.d.mts → Factory-BZ8uMoXl.d.cts} +3 -2
- package/dist/{Factory-pNV7ZQ7-.d.cts → Factory-Cmr3s3-s.d.mts} +3 -2
- package/dist/Factory-WMhTNZ9S.cjs +2 -1
- package/dist/Factory-WMhTNZ9S.cjs.map +1 -0
- package/dist/Factory-z2m01hMj.mjs +2 -1
- package/dist/Factory-z2m01hMj.mjs.map +1 -0
- package/dist/Factory.d.cts +2 -2
- package/dist/Factory.d.mts +2 -2
- package/dist/KyselyFactory-BcYkC0t2.mjs +2 -1
- package/dist/KyselyFactory-BcYkC0t2.mjs.map +1 -0
- package/dist/KyselyFactory-Cf0o2YxO.cjs +2 -1
- package/dist/KyselyFactory-Cf0o2YxO.cjs.map +1 -0
- package/dist/{KyselyFactory-72P98y5I.d.mts → KyselyFactory-Cx3sezwH.d.mts} +4 -3
- package/dist/{KyselyFactory-DLBrYWxU.d.cts → KyselyFactory-DRQ83r0o.d.cts} +4 -3
- package/dist/KyselyFactory.d.cts +3 -3
- package/dist/KyselyFactory.d.mts +3 -3
- package/dist/ObjectionFactory-8hebmnai.mjs +2 -1
- package/dist/ObjectionFactory-8hebmnai.mjs.map +1 -0
- package/dist/{ObjectionFactory-B40NQWSe.d.mts → ObjectionFactory-C-59Hjwj.d.mts} +4 -3
- package/dist/{ObjectionFactory-D3l1VuyX.d.cts → ObjectionFactory-C4X78k0B.d.cts} +4 -3
- package/dist/ObjectionFactory-CDriunkS.cjs +2 -1
- package/dist/ObjectionFactory-CDriunkS.cjs.map +1 -0
- package/dist/ObjectionFactory.d.cts +3 -3
- package/dist/ObjectionFactory.d.mts +3 -3
- package/dist/{PostgresKyselyMigrator-_6yHZigp.d.mts → PostgresKyselyMigrator-CIx3AFSR.d.mts} +3 -2
- package/dist/PostgresKyselyMigrator-CQ3aUoy_.d.cts +2 -1
- package/dist/PostgresKyselyMigrator-CfytARcA.cjs +2 -1
- package/dist/PostgresKyselyMigrator-CfytARcA.cjs.map +1 -0
- package/dist/{PostgresKyselyMigrator-Bdhl251C.mjs → PostgresKyselyMigrator-upT-hmrz.mjs} +3 -2
- package/dist/PostgresKyselyMigrator-upT-hmrz.mjs.map +1 -0
- package/dist/PostgresKyselyMigrator.d.mts +2 -2
- package/dist/PostgresKyselyMigrator.mjs +2 -2
- package/dist/PostgresMigrator-D5UkK1_K.d.cts +2 -1
- package/dist/PostgresMigrator-DFcNdCvD.cjs +2 -1
- package/dist/PostgresMigrator-DFcNdCvD.cjs.map +1 -0
- package/dist/{PostgresMigrator-BlvuQl7d.d.mts → PostgresMigrator-DQaRxoaY.d.mts} +2 -1
- package/dist/{PostgresMigrator-DxPC_gGu.mjs → PostgresMigrator-DbuJGAVy.mjs} +4 -3
- package/dist/PostgresMigrator-DbuJGAVy.mjs.map +1 -0
- package/dist/PostgresMigrator.d.mts +1 -1
- package/dist/PostgresMigrator.mjs +1 -1
- package/dist/PostgresObjectionMigrator-BG6ymgnt.cjs +2 -1
- package/dist/PostgresObjectionMigrator-BG6ymgnt.cjs.map +1 -0
- package/dist/PostgresObjectionMigrator-CZHHcCOv.d.cts +2 -1
- package/dist/{PostgresObjectionMigrator-G4h5FLvU.mjs → PostgresObjectionMigrator-DPj2pOpX.mjs} +3 -2
- package/dist/PostgresObjectionMigrator-DPj2pOpX.mjs.map +1 -0
- package/dist/{PostgresObjectionMigrator-C69n7vzr.d.mts → PostgresObjectionMigrator-D_hCcrQu.d.mts} +3 -2
- package/dist/PostgresObjectionMigrator.d.mts +2 -2
- package/dist/PostgresObjectionMigrator.mjs +2 -2
- package/dist/{VitestKyselyTransactionIsolator-Dq4Oeh-Y.mjs → VitestKyselyTransactionIsolator-BxjlD1YM.mjs} +3 -4
- package/dist/VitestKyselyTransactionIsolator-BxjlD1YM.mjs.map +1 -0
- package/dist/{VitestKyselyTransactionIsolator-CnxpE9cH.d.mts → VitestKyselyTransactionIsolator-COCVfvfr.d.mts} +3 -2
- package/dist/{VitestKyselyTransactionIsolator-Dqy3qNoJ.cjs → VitestKyselyTransactionIsolator-Cst3vFjb.cjs} +3 -4
- package/dist/VitestKyselyTransactionIsolator-Cst3vFjb.cjs.map +1 -0
- package/dist/VitestKyselyTransactionIsolator-DYUYVEh9.d.cts +2 -1
- package/dist/VitestKyselyTransactionIsolator.cjs +1 -1
- package/dist/VitestKyselyTransactionIsolator.d.mts +2 -2
- package/dist/VitestKyselyTransactionIsolator.mjs +1 -1
- package/dist/{VitestObjectionTransactionIsolator-DVtJG2F3.mjs → VitestObjectionTransactionIsolator-BU-jXEhz.mjs} +3 -4
- package/dist/VitestObjectionTransactionIsolator-BU-jXEhz.mjs.map +1 -0
- package/dist/VitestObjectionTransactionIsolator-CJ4ds5Qv.d.cts +2 -1
- package/dist/{VitestObjectionTransactionIsolator-LP4B0cqW.cjs → VitestObjectionTransactionIsolator-DzeF4UAq.cjs} +3 -4
- package/dist/VitestObjectionTransactionIsolator-DzeF4UAq.cjs.map +1 -0
- package/dist/{VitestObjectionTransactionIsolator-DIM79dCq.d.mts → VitestObjectionTransactionIsolator-b973r9O1.d.mts} +3 -2
- package/dist/VitestObjectionTransactionIsolator.cjs +1 -1
- package/dist/VitestObjectionTransactionIsolator.d.mts +2 -2
- package/dist/VitestObjectionTransactionIsolator.mjs +1 -1
- package/dist/VitestTransactionIsolator-BQ5FpLtC.cjs +2 -1
- package/dist/VitestTransactionIsolator-BQ5FpLtC.cjs.map +1 -0
- package/dist/{VitestTransactionIsolator-zdyiS_SY.d.mts → VitestTransactionIsolator-CsfJBxcb.d.mts} +2 -1
- package/dist/VitestTransactionIsolator-CskiiJbW.mjs +2 -1
- package/dist/VitestTransactionIsolator-CskiiJbW.mjs.map +1 -0
- package/dist/VitestTransactionIsolator-DdLNODZg.d.cts +2 -1
- package/dist/VitestTransactionIsolator.d.mts +1 -1
- package/dist/aws.cjs +126 -0
- package/dist/aws.cjs.map +1 -0
- package/dist/aws.d.cts +22 -0
- package/dist/aws.d.mts +22 -0
- package/dist/aws.mjs +123 -0
- package/dist/aws.mjs.map +1 -0
- package/dist/directory-B-Ozljzk.mjs +22 -0
- package/dist/directory-B-Ozljzk.mjs.map +1 -0
- package/dist/directory-B4oYx02C.d.mts +12 -0
- package/dist/directory-BUcnztHI.d.cts +12 -0
- package/dist/directory-BVC8g7cX.cjs +28 -0
- package/dist/directory-BVC8g7cX.cjs.map +1 -0
- package/dist/faker-B14IEMIN.cjs +2 -1
- package/dist/faker-B14IEMIN.cjs.map +1 -0
- package/dist/faker-BGKYFoCT.mjs +2 -1
- package/dist/faker-BGKYFoCT.mjs.map +1 -0
- package/dist/{faker-BSH1EMtg.d.cts → faker-Cg76aFNO.d.cts} +4 -3
- package/dist/{faker-C-Iuk_R1.d.mts → faker-DHh7xs4u.d.mts} +4 -3
- package/dist/faker.d.cts +1 -1
- package/dist/faker.d.mts +1 -1
- package/dist/helpers.cjs +48 -2
- package/dist/helpers.cjs.map +1 -0
- package/dist/helpers.d.cts +2 -1
- package/dist/helpers.d.mts +2 -1
- package/dist/helpers.mjs +47 -2
- package/dist/helpers.mjs.map +1 -0
- package/dist/kysely.cjs +66 -3
- package/dist/kysely.cjs.map +1 -0
- package/dist/kysely.d.cts +5 -4
- package/dist/kysely.d.mts +9 -8
- package/dist/kysely.mjs +68 -5
- package/dist/kysely.mjs.map +1 -0
- package/dist/logger.cjs +23 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/logger.d.cts +11 -0
- package/dist/logger.d.mts +11 -0
- package/dist/logger.mjs +22 -0
- package/dist/logger.mjs.map +1 -0
- package/dist/objection.cjs +81 -3
- package/dist/objection.cjs.map +1 -0
- package/dist/objection.d.cts +5 -4
- package/dist/objection.d.mts +9 -8
- package/dist/objection.mjs +83 -5
- package/dist/objection.mjs.map +1 -0
- package/dist/os/directory.cjs +3 -0
- package/dist/os/directory.d.cts +2 -0
- package/dist/os/directory.d.mts +2 -0
- package/dist/os/directory.mjs +3 -0
- package/dist/os/index.cjs +3 -0
- package/dist/os/index.d.cts +2 -0
- package/dist/os/index.d.mts +2 -0
- package/dist/os/index.mjs +3 -0
- package/dist/timer.cjs +9 -0
- package/dist/timer.cjs.map +1 -0
- package/dist/timer.d.cts +5 -0
- package/dist/timer.d.mts +5 -0
- package/dist/timer.mjs +8 -0
- package/dist/timer.mjs.map +1 -0
- package/package.json +25 -3
- package/src/VitestKyselyTransactionIsolator.ts +2 -2
- package/src/VitestObjectionTransactionIsolator.ts +1 -3
- package/src/aws.ts +131 -0
- package/src/logger.ts +18 -0
- package/src/os/directory.ts +21 -0
- package/src/os/index.ts +1 -0
- package/src/timer.ts +3 -0
- package/dist/__tests__/Factory.spec.cjs +0 -139
- package/dist/__tests__/Factory.spec.d.cts +0 -1
- package/dist/__tests__/Factory.spec.d.mts +0 -1
- package/dist/__tests__/Factory.spec.mjs +0 -138
- package/dist/__tests__/KyselyFactory.spec.cjs +0 -235
- package/dist/__tests__/KyselyFactory.spec.d.cts +0 -1
- package/dist/__tests__/KyselyFactory.spec.d.mts +0 -1
- package/dist/__tests__/KyselyFactory.spec.mjs +0 -234
- package/dist/__tests__/ObjectionFactory.spec.cjs +0 -340
- package/dist/__tests__/ObjectionFactory.spec.d.cts +0 -1
- package/dist/__tests__/ObjectionFactory.spec.d.mts +0 -1
- package/dist/__tests__/ObjectionFactory.spec.mjs +0 -339
- package/dist/__tests__/PostgresKyselyMigrator.spec.cjs +0 -397
- package/dist/__tests__/PostgresKyselyMigrator.spec.d.cts +0 -1
- package/dist/__tests__/PostgresKyselyMigrator.spec.d.mts +0 -1
- package/dist/__tests__/PostgresKyselyMigrator.spec.mjs +0 -396
- package/dist/__tests__/PostgresMigrator.spec.cjs +0 -256
- package/dist/__tests__/PostgresMigrator.spec.d.cts +0 -1
- package/dist/__tests__/PostgresMigrator.spec.d.mts +0 -1
- package/dist/__tests__/PostgresMigrator.spec.mjs +0 -255
- package/dist/__tests__/PostgresObjectionMigrator.spec.cjs +0 -432
- package/dist/__tests__/PostgresObjectionMigrator.spec.d.cts +0 -1
- package/dist/__tests__/PostgresObjectionMigrator.spec.d.mts +0 -1
- package/dist/__tests__/PostgresObjectionMigrator.spec.mjs +0 -431
- package/dist/__tests__/VitestObjectionTransactionIsolator.spec.cjs +0 -122
- package/dist/__tests__/VitestObjectionTransactionIsolator.spec.d.cts +0 -1
- package/dist/__tests__/VitestObjectionTransactionIsolator.spec.d.mts +0 -1
- package/dist/__tests__/VitestObjectionTransactionIsolator.spec.mjs +0 -121
- package/dist/__tests__/faker.spec.cjs +0 -115
- package/dist/__tests__/faker.spec.d.cts +0 -1
- package/dist/__tests__/faker.spec.d.mts +0 -1
- package/dist/__tests__/faker.spec.mjs +0 -114
- package/dist/__tests__/integration.spec.cjs +0 -282
- package/dist/__tests__/integration.spec.d.cts +0 -1
- package/dist/__tests__/integration.spec.d.mts +0 -1
- package/dist/__tests__/integration.spec.mjs +0 -281
- package/dist/helpers-B4TXg3Wp.mjs +0 -86
- package/dist/helpers-Bf0nXhbu.cjs +0 -116
- package/dist/helpers-BuPmgzyQ.mjs +0 -47
- package/dist/helpers-nEUtQ7eo.cjs +0 -53
- package/dist/kysely-BsDbvw3r.mjs +0 -67
- package/dist/kysely-CP1iJMvq.cjs +0 -72
- package/dist/objection-BEPk9h-g.mjs +0 -82
- package/dist/objection-Di7JSist.cjs +0 -87
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
const require_chunk = require('../chunk-CUT6urMc.cjs');
|
|
2
|
-
require('../Factory-WMhTNZ9S.cjs');
|
|
3
|
-
require('../faker-B14IEMIN.cjs');
|
|
4
|
-
const require_KyselyFactory = require('../KyselyFactory-Cf0o2YxO.cjs');
|
|
5
|
-
require('../PostgresMigrator-DFcNdCvD.cjs');
|
|
6
|
-
require('../PostgresKyselyMigrator-CfytARcA.cjs');
|
|
7
|
-
require('../VitestTransactionIsolator-BQ5FpLtC.cjs');
|
|
8
|
-
require('../VitestKyselyTransactionIsolator-Dqy3qNoJ.cjs');
|
|
9
|
-
const require_helpers = require('../helpers-nEUtQ7eo.cjs');
|
|
10
|
-
const require_kysely = require('../kysely-CP1iJMvq.cjs');
|
|
11
|
-
const require_helpers$1 = require('../helpers-Bf0nXhbu.cjs');
|
|
12
|
-
const pg = require_chunk.__toESM(require("pg"));
|
|
13
|
-
const vitest = require_chunk.__toESM(require("vitest"));
|
|
14
|
-
|
|
15
|
-
//#region src/__tests__/KyselyFactory.spec.ts
|
|
16
|
-
const db = () => require_helpers.createKyselyDb(require_helpers$1.TEST_DATABASE_CONFIG);
|
|
17
|
-
const itWithTransaction = require_kysely.wrapVitestKyselyTransaction(vitest.it, db, require_helpers$1.createTestTables);
|
|
18
|
-
const int8TypeId = 20;
|
|
19
|
-
pg.default.types.setTypeParser(int8TypeId, (val) => {
|
|
20
|
-
return parseInt(val, 10);
|
|
21
|
-
});
|
|
22
|
-
(0, vitest.describe)("KyselyFactory", () => {
|
|
23
|
-
(0, vitest.describe)("KyselyFactory.insert", () => {
|
|
24
|
-
itWithTransaction("should insert a record with defaults", async ({ trx }) => {
|
|
25
|
-
const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
26
|
-
name: "John Doe",
|
|
27
|
-
email: `user${Date.now()}@example.com`,
|
|
28
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
29
|
-
}));
|
|
30
|
-
const builders = { user: userBuilder };
|
|
31
|
-
const factory = new require_KyselyFactory.KyselyFactory(builders, {}, trx);
|
|
32
|
-
const user = await factory.insert("user");
|
|
33
|
-
(0, vitest.expect)(user).toBeDefined();
|
|
34
|
-
(0, vitest.expect)(user.id).toBeDefined();
|
|
35
|
-
(0, vitest.expect)(user.name).toBe("John Doe");
|
|
36
|
-
(0, vitest.expect)(user.email).toContain("user");
|
|
37
|
-
(0, vitest.expect)(user.email).toContain("@example.com");
|
|
38
|
-
(0, vitest.expect)(user.createdAt).toBeInstanceOf(Date);
|
|
39
|
-
});
|
|
40
|
-
itWithTransaction("should override defaults with provided attributes", async ({ trx }) => {
|
|
41
|
-
const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
42
|
-
name: "John Doe",
|
|
43
|
-
email: `user${Date.now()}@example.com`,
|
|
44
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
45
|
-
}));
|
|
46
|
-
const builders = { user: userBuilder };
|
|
47
|
-
const factory = new require_KyselyFactory.KyselyFactory(builders, {}, trx);
|
|
48
|
-
const customEmail = "custom@test.com";
|
|
49
|
-
const customName = "Jane Smith";
|
|
50
|
-
const user = await factory.insert("user", {
|
|
51
|
-
email: customEmail,
|
|
52
|
-
name: customName
|
|
53
|
-
});
|
|
54
|
-
(0, vitest.expect)(user.name).toBe(customName);
|
|
55
|
-
(0, vitest.expect)(user.email).toBe(customEmail);
|
|
56
|
-
});
|
|
57
|
-
itWithTransaction("should handle relations", async ({ trx }) => {
|
|
58
|
-
const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
59
|
-
name: "John Doe",
|
|
60
|
-
email: `user${Date.now()}@example.com`,
|
|
61
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
62
|
-
}));
|
|
63
|
-
const postBuilder = require_KyselyFactory.KyselyFactory.createBuilder("posts", async (attrs, factory$1) => {
|
|
64
|
-
if (!attrs.userId) {
|
|
65
|
-
const user = await factory$1.insert("user");
|
|
66
|
-
return {
|
|
67
|
-
title: "Default Post",
|
|
68
|
-
content: "Default content",
|
|
69
|
-
userId: user.id,
|
|
70
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
return {
|
|
74
|
-
title: "Default Post",
|
|
75
|
-
content: "Default content",
|
|
76
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
77
|
-
};
|
|
78
|
-
});
|
|
79
|
-
const builders = {
|
|
80
|
-
user: userBuilder,
|
|
81
|
-
post: postBuilder
|
|
82
|
-
};
|
|
83
|
-
const factory = new require_KyselyFactory.KyselyFactory(builders, {}, trx);
|
|
84
|
-
const post = await factory.insert("post", { title: "Test Post" });
|
|
85
|
-
(0, vitest.expect)(post).toBeDefined();
|
|
86
|
-
(0, vitest.expect)(post.title).toBe("Test Post");
|
|
87
|
-
(0, vitest.expect)(post.userId).toBeDefined();
|
|
88
|
-
(0, vitest.expect)(typeof post.userId).toBe("number");
|
|
89
|
-
});
|
|
90
|
-
itWithTransaction("should throw error for non-existent builder", async ({ trx }) => {
|
|
91
|
-
const factory = new require_KyselyFactory.KyselyFactory({}, {}, trx);
|
|
92
|
-
await (0, vitest.expect)(factory.insert("nonExistent")).rejects.toThrow("Factory \"nonExistent\" does not exist");
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
(0, vitest.describe)("KyselyFactory.insertMany", () => {
|
|
96
|
-
itWithTransaction("should insert multiple records with same attributes", async ({ trx }) => {
|
|
97
|
-
const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
98
|
-
name: "John Doe",
|
|
99
|
-
email: `user${Date.now()}-${Math.random()}@example.com`,
|
|
100
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
101
|
-
}));
|
|
102
|
-
const builders = { user: userBuilder };
|
|
103
|
-
const factory = new require_KyselyFactory.KyselyFactory(builders, {}, trx);
|
|
104
|
-
const users = await factory.insertMany(3, "user");
|
|
105
|
-
(0, vitest.expect)(users).toHaveLength(3);
|
|
106
|
-
users.forEach((user, index) => {
|
|
107
|
-
(0, vitest.expect)(user.id).toBeDefined();
|
|
108
|
-
(0, vitest.expect)(user.name).toBe("John Doe");
|
|
109
|
-
(0, vitest.expect)(user.email).toContain("@example.com");
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
itWithTransaction("should insert multiple records with dynamic attributes", async ({ trx }) => {
|
|
113
|
-
const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
114
|
-
email: `user${Date.now()}-${Math.random()}@example.com`,
|
|
115
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
116
|
-
}));
|
|
117
|
-
const builders = { user: userBuilder };
|
|
118
|
-
const factory = new require_KyselyFactory.KyselyFactory(builders, {}, trx);
|
|
119
|
-
const users = await factory.insertMany(3, "user", (idx) => ({ name: `User ${idx}` }));
|
|
120
|
-
(0, vitest.expect)(users).toHaveLength(3);
|
|
121
|
-
users.forEach((user, index) => {
|
|
122
|
-
(0, vitest.expect)(user.name).toBe(`User ${index}`);
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
itWithTransaction("should throw error for non-existent builder", async ({ trx }) => {
|
|
126
|
-
const factory = new require_KyselyFactory.KyselyFactory({}, {}, trx);
|
|
127
|
-
await (0, vitest.expect)(factory.insertMany(2, "nonExistent")).rejects.toThrow("Builder \"nonExistent\" is not registered");
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
(0, vitest.describe)("KyselyFactory.createBuilder", () => {
|
|
131
|
-
itWithTransaction("should work with async defaults", async ({ trx }) => {
|
|
132
|
-
let counter = 0;
|
|
133
|
-
const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder("users", async (attrs) => {
|
|
134
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
135
|
-
counter++;
|
|
136
|
-
return {
|
|
137
|
-
name: `Async User ${counter}`,
|
|
138
|
-
email: `user${counter}@example.com`,
|
|
139
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
140
|
-
};
|
|
141
|
-
});
|
|
142
|
-
const builders = { user: userBuilder };
|
|
143
|
-
const factory = new require_KyselyFactory.KyselyFactory(builders, {}, trx);
|
|
144
|
-
const user1 = await factory.insert("user");
|
|
145
|
-
const user2 = await factory.insert("user");
|
|
146
|
-
(0, vitest.expect)(user1.name).toBe("Async User 1");
|
|
147
|
-
(0, vitest.expect)(user2.name).toBe("Async User 2");
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
(0, vitest.describe)("KyselyFactory.seed", () => {
|
|
151
|
-
itWithTransaction("should execute seed functions", async ({ trx }) => {
|
|
152
|
-
const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
153
|
-
name: "John Doe",
|
|
154
|
-
email: `user${Date.now()}@example.com`,
|
|
155
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
156
|
-
}));
|
|
157
|
-
const builders = { user: userBuilder };
|
|
158
|
-
const seeds = { createAdminUser: require_KyselyFactory.KyselyFactory.createSeed(async (attrs, factory$1, db$1) => {
|
|
159
|
-
return await factory$1.insert("user", {
|
|
160
|
-
name: attrs.name || "Admin User",
|
|
161
|
-
email: "admin@example.com"
|
|
162
|
-
});
|
|
163
|
-
}) };
|
|
164
|
-
const factory = new require_KyselyFactory.KyselyFactory(builders, seeds, trx);
|
|
165
|
-
const adminUser = await factory.seed("createAdminUser");
|
|
166
|
-
(0, vitest.expect)(adminUser).toBeDefined();
|
|
167
|
-
(0, vitest.expect)(adminUser.name).toBe("Admin User");
|
|
168
|
-
(0, vitest.expect)(adminUser.email).toBe("admin@example.com");
|
|
169
|
-
});
|
|
170
|
-
itWithTransaction("should pass attributes to seed functions", async ({ trx }) => {
|
|
171
|
-
const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
172
|
-
name: "John Doe",
|
|
173
|
-
email: `user${Date.now()}@example.com`,
|
|
174
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
175
|
-
}));
|
|
176
|
-
const builders = { user: userBuilder };
|
|
177
|
-
const seeds = { createCustomUser: require_KyselyFactory.KyselyFactory.createSeed(async (attrs, factory$1, db$1) => {
|
|
178
|
-
return await factory$1.insert("user", attrs);
|
|
179
|
-
}) };
|
|
180
|
-
const factory = new require_KyselyFactory.KyselyFactory(builders, seeds, trx);
|
|
181
|
-
const customUser = await factory.seed("createCustomUser", {
|
|
182
|
-
name: "Custom User",
|
|
183
|
-
email: "custom@test.com"
|
|
184
|
-
});
|
|
185
|
-
(0, vitest.expect)(customUser.name).toBe("Custom User");
|
|
186
|
-
(0, vitest.expect)(customUser.email).toBe("custom@test.com");
|
|
187
|
-
});
|
|
188
|
-
itWithTransaction("should throw error for non-existent seed", async ({ trx }) => {
|
|
189
|
-
const factory = new require_KyselyFactory.KyselyFactory({}, {}, trx);
|
|
190
|
-
(0, vitest.expect)(() => factory.seed("nonExistent")).toThrow("Seed \"nonExistent\" is not registered");
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
(0, vitest.describe)("Factory integration", () => {
|
|
194
|
-
itWithTransaction("should work with controlled transactions", async ({ trx }) => {
|
|
195
|
-
const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
196
|
-
name: "John Doe",
|
|
197
|
-
email: `user${Date.now()}@example.com`,
|
|
198
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
199
|
-
}));
|
|
200
|
-
const builders = { user: userBuilder };
|
|
201
|
-
const factory = new require_KyselyFactory.KyselyFactory(builders, {}, trx);
|
|
202
|
-
const user = await factory.insert("user");
|
|
203
|
-
const foundUser = await trx.selectFrom("users").selectAll().where("id", "=", user.id).executeTakeFirst();
|
|
204
|
-
(0, vitest.expect)(foundUser).toBeDefined();
|
|
205
|
-
(0, vitest.expect)(foundUser?.id).toBe(user.id);
|
|
206
|
-
});
|
|
207
|
-
itWithTransaction("should work with factory passed to defaults", async ({ trx }) => {
|
|
208
|
-
const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
209
|
-
name: "John Doe",
|
|
210
|
-
email: `user${Date.now()}@example.com`,
|
|
211
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
212
|
-
}));
|
|
213
|
-
const postBuilder = require_KyselyFactory.KyselyFactory.createBuilder("posts", async (attrs, factory$1) => {
|
|
214
|
-
const user = await factory$1.insert("user");
|
|
215
|
-
return {
|
|
216
|
-
title: "Default Post",
|
|
217
|
-
content: "Default content",
|
|
218
|
-
userId: user.id,
|
|
219
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
220
|
-
};
|
|
221
|
-
});
|
|
222
|
-
const builders = {
|
|
223
|
-
user: userBuilder,
|
|
224
|
-
post: postBuilder
|
|
225
|
-
};
|
|
226
|
-
const factory = new require_KyselyFactory.KyselyFactory(builders, {}, trx);
|
|
227
|
-
const post = await factory.insert("post");
|
|
228
|
-
(0, vitest.expect)(post.userId).toBeDefined();
|
|
229
|
-
const relatedUser = await trx.selectFrom("users").selectAll().where("id", "=", post.userId).executeTakeFirst();
|
|
230
|
-
(0, vitest.expect)(relatedUser).toBeDefined();
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
//#endregion
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
import "../Factory-z2m01hMj.mjs";
|
|
2
|
-
import "../faker-BGKYFoCT.mjs";
|
|
3
|
-
import { KyselyFactory } from "../KyselyFactory-BcYkC0t2.mjs";
|
|
4
|
-
import "../PostgresMigrator-DxPC_gGu.mjs";
|
|
5
|
-
import "../PostgresKyselyMigrator-Bdhl251C.mjs";
|
|
6
|
-
import "../VitestTransactionIsolator-CskiiJbW.mjs";
|
|
7
|
-
import "../VitestKyselyTransactionIsolator-Dq4Oeh-Y.mjs";
|
|
8
|
-
import { createKyselyDb } from "../helpers-BuPmgzyQ.mjs";
|
|
9
|
-
import { wrapVitestKyselyTransaction } from "../kysely-BsDbvw3r.mjs";
|
|
10
|
-
import { TEST_DATABASE_CONFIG, createTestTables } from "../helpers-B4TXg3Wp.mjs";
|
|
11
|
-
import pg from "pg";
|
|
12
|
-
import { describe, expect, it } from "vitest";
|
|
13
|
-
|
|
14
|
-
//#region src/__tests__/KyselyFactory.spec.ts
|
|
15
|
-
const db = () => createKyselyDb(TEST_DATABASE_CONFIG);
|
|
16
|
-
const itWithTransaction = wrapVitestKyselyTransaction(it, db, createTestTables);
|
|
17
|
-
const int8TypeId = 20;
|
|
18
|
-
pg.types.setTypeParser(int8TypeId, (val) => {
|
|
19
|
-
return parseInt(val, 10);
|
|
20
|
-
});
|
|
21
|
-
describe("KyselyFactory", () => {
|
|
22
|
-
describe("KyselyFactory.insert", () => {
|
|
23
|
-
itWithTransaction("should insert a record with defaults", async ({ trx }) => {
|
|
24
|
-
const userBuilder = KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
25
|
-
name: "John Doe",
|
|
26
|
-
email: `user${Date.now()}@example.com`,
|
|
27
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
28
|
-
}));
|
|
29
|
-
const builders = { user: userBuilder };
|
|
30
|
-
const factory = new KyselyFactory(builders, {}, trx);
|
|
31
|
-
const user = await factory.insert("user");
|
|
32
|
-
expect(user).toBeDefined();
|
|
33
|
-
expect(user.id).toBeDefined();
|
|
34
|
-
expect(user.name).toBe("John Doe");
|
|
35
|
-
expect(user.email).toContain("user");
|
|
36
|
-
expect(user.email).toContain("@example.com");
|
|
37
|
-
expect(user.createdAt).toBeInstanceOf(Date);
|
|
38
|
-
});
|
|
39
|
-
itWithTransaction("should override defaults with provided attributes", async ({ trx }) => {
|
|
40
|
-
const userBuilder = KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
41
|
-
name: "John Doe",
|
|
42
|
-
email: `user${Date.now()}@example.com`,
|
|
43
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
44
|
-
}));
|
|
45
|
-
const builders = { user: userBuilder };
|
|
46
|
-
const factory = new KyselyFactory(builders, {}, trx);
|
|
47
|
-
const customEmail = "custom@test.com";
|
|
48
|
-
const customName = "Jane Smith";
|
|
49
|
-
const user = await factory.insert("user", {
|
|
50
|
-
email: customEmail,
|
|
51
|
-
name: customName
|
|
52
|
-
});
|
|
53
|
-
expect(user.name).toBe(customName);
|
|
54
|
-
expect(user.email).toBe(customEmail);
|
|
55
|
-
});
|
|
56
|
-
itWithTransaction("should handle relations", async ({ trx }) => {
|
|
57
|
-
const userBuilder = KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
58
|
-
name: "John Doe",
|
|
59
|
-
email: `user${Date.now()}@example.com`,
|
|
60
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
61
|
-
}));
|
|
62
|
-
const postBuilder = KyselyFactory.createBuilder("posts", async (attrs, factory$1) => {
|
|
63
|
-
if (!attrs.userId) {
|
|
64
|
-
const user = await factory$1.insert("user");
|
|
65
|
-
return {
|
|
66
|
-
title: "Default Post",
|
|
67
|
-
content: "Default content",
|
|
68
|
-
userId: user.id,
|
|
69
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
return {
|
|
73
|
-
title: "Default Post",
|
|
74
|
-
content: "Default content",
|
|
75
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
76
|
-
};
|
|
77
|
-
});
|
|
78
|
-
const builders = {
|
|
79
|
-
user: userBuilder,
|
|
80
|
-
post: postBuilder
|
|
81
|
-
};
|
|
82
|
-
const factory = new KyselyFactory(builders, {}, trx);
|
|
83
|
-
const post = await factory.insert("post", { title: "Test Post" });
|
|
84
|
-
expect(post).toBeDefined();
|
|
85
|
-
expect(post.title).toBe("Test Post");
|
|
86
|
-
expect(post.userId).toBeDefined();
|
|
87
|
-
expect(typeof post.userId).toBe("number");
|
|
88
|
-
});
|
|
89
|
-
itWithTransaction("should throw error for non-existent builder", async ({ trx }) => {
|
|
90
|
-
const factory = new KyselyFactory({}, {}, trx);
|
|
91
|
-
await expect(factory.insert("nonExistent")).rejects.toThrow("Factory \"nonExistent\" does not exist");
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
describe("KyselyFactory.insertMany", () => {
|
|
95
|
-
itWithTransaction("should insert multiple records with same attributes", async ({ trx }) => {
|
|
96
|
-
const userBuilder = KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
97
|
-
name: "John Doe",
|
|
98
|
-
email: `user${Date.now()}-${Math.random()}@example.com`,
|
|
99
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
100
|
-
}));
|
|
101
|
-
const builders = { user: userBuilder };
|
|
102
|
-
const factory = new KyselyFactory(builders, {}, trx);
|
|
103
|
-
const users = await factory.insertMany(3, "user");
|
|
104
|
-
expect(users).toHaveLength(3);
|
|
105
|
-
users.forEach((user, index) => {
|
|
106
|
-
expect(user.id).toBeDefined();
|
|
107
|
-
expect(user.name).toBe("John Doe");
|
|
108
|
-
expect(user.email).toContain("@example.com");
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
itWithTransaction("should insert multiple records with dynamic attributes", async ({ trx }) => {
|
|
112
|
-
const userBuilder = KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
113
|
-
email: `user${Date.now()}-${Math.random()}@example.com`,
|
|
114
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
115
|
-
}));
|
|
116
|
-
const builders = { user: userBuilder };
|
|
117
|
-
const factory = new KyselyFactory(builders, {}, trx);
|
|
118
|
-
const users = await factory.insertMany(3, "user", (idx) => ({ name: `User ${idx}` }));
|
|
119
|
-
expect(users).toHaveLength(3);
|
|
120
|
-
users.forEach((user, index) => {
|
|
121
|
-
expect(user.name).toBe(`User ${index}`);
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
itWithTransaction("should throw error for non-existent builder", async ({ trx }) => {
|
|
125
|
-
const factory = new KyselyFactory({}, {}, trx);
|
|
126
|
-
await expect(factory.insertMany(2, "nonExistent")).rejects.toThrow("Builder \"nonExistent\" is not registered");
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
describe("KyselyFactory.createBuilder", () => {
|
|
130
|
-
itWithTransaction("should work with async defaults", async ({ trx }) => {
|
|
131
|
-
let counter = 0;
|
|
132
|
-
const userBuilder = KyselyFactory.createBuilder("users", async (attrs) => {
|
|
133
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
134
|
-
counter++;
|
|
135
|
-
return {
|
|
136
|
-
name: `Async User ${counter}`,
|
|
137
|
-
email: `user${counter}@example.com`,
|
|
138
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
139
|
-
};
|
|
140
|
-
});
|
|
141
|
-
const builders = { user: userBuilder };
|
|
142
|
-
const factory = new KyselyFactory(builders, {}, trx);
|
|
143
|
-
const user1 = await factory.insert("user");
|
|
144
|
-
const user2 = await factory.insert("user");
|
|
145
|
-
expect(user1.name).toBe("Async User 1");
|
|
146
|
-
expect(user2.name).toBe("Async User 2");
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
describe("KyselyFactory.seed", () => {
|
|
150
|
-
itWithTransaction("should execute seed functions", async ({ trx }) => {
|
|
151
|
-
const userBuilder = KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
152
|
-
name: "John Doe",
|
|
153
|
-
email: `user${Date.now()}@example.com`,
|
|
154
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
155
|
-
}));
|
|
156
|
-
const builders = { user: userBuilder };
|
|
157
|
-
const seeds = { createAdminUser: KyselyFactory.createSeed(async (attrs, factory$1, db$1) => {
|
|
158
|
-
return await factory$1.insert("user", {
|
|
159
|
-
name: attrs.name || "Admin User",
|
|
160
|
-
email: "admin@example.com"
|
|
161
|
-
});
|
|
162
|
-
}) };
|
|
163
|
-
const factory = new KyselyFactory(builders, seeds, trx);
|
|
164
|
-
const adminUser = await factory.seed("createAdminUser");
|
|
165
|
-
expect(adminUser).toBeDefined();
|
|
166
|
-
expect(adminUser.name).toBe("Admin User");
|
|
167
|
-
expect(adminUser.email).toBe("admin@example.com");
|
|
168
|
-
});
|
|
169
|
-
itWithTransaction("should pass attributes to seed functions", async ({ trx }) => {
|
|
170
|
-
const userBuilder = KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
171
|
-
name: "John Doe",
|
|
172
|
-
email: `user${Date.now()}@example.com`,
|
|
173
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
174
|
-
}));
|
|
175
|
-
const builders = { user: userBuilder };
|
|
176
|
-
const seeds = { createCustomUser: KyselyFactory.createSeed(async (attrs, factory$1, db$1) => {
|
|
177
|
-
return await factory$1.insert("user", attrs);
|
|
178
|
-
}) };
|
|
179
|
-
const factory = new KyselyFactory(builders, seeds, trx);
|
|
180
|
-
const customUser = await factory.seed("createCustomUser", {
|
|
181
|
-
name: "Custom User",
|
|
182
|
-
email: "custom@test.com"
|
|
183
|
-
});
|
|
184
|
-
expect(customUser.name).toBe("Custom User");
|
|
185
|
-
expect(customUser.email).toBe("custom@test.com");
|
|
186
|
-
});
|
|
187
|
-
itWithTransaction("should throw error for non-existent seed", async ({ trx }) => {
|
|
188
|
-
const factory = new KyselyFactory({}, {}, trx);
|
|
189
|
-
expect(() => factory.seed("nonExistent")).toThrow("Seed \"nonExistent\" is not registered");
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
describe("Factory integration", () => {
|
|
193
|
-
itWithTransaction("should work with controlled transactions", async ({ trx }) => {
|
|
194
|
-
const userBuilder = KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
195
|
-
name: "John Doe",
|
|
196
|
-
email: `user${Date.now()}@example.com`,
|
|
197
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
198
|
-
}));
|
|
199
|
-
const builders = { user: userBuilder };
|
|
200
|
-
const factory = new KyselyFactory(builders, {}, trx);
|
|
201
|
-
const user = await factory.insert("user");
|
|
202
|
-
const foundUser = await trx.selectFrom("users").selectAll().where("id", "=", user.id).executeTakeFirst();
|
|
203
|
-
expect(foundUser).toBeDefined();
|
|
204
|
-
expect(foundUser?.id).toBe(user.id);
|
|
205
|
-
});
|
|
206
|
-
itWithTransaction("should work with factory passed to defaults", async ({ trx }) => {
|
|
207
|
-
const userBuilder = KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
208
|
-
name: "John Doe",
|
|
209
|
-
email: `user${Date.now()}@example.com`,
|
|
210
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
211
|
-
}));
|
|
212
|
-
const postBuilder = KyselyFactory.createBuilder("posts", async (attrs, factory$1) => {
|
|
213
|
-
const user = await factory$1.insert("user");
|
|
214
|
-
return {
|
|
215
|
-
title: "Default Post",
|
|
216
|
-
content: "Default content",
|
|
217
|
-
userId: user.id,
|
|
218
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
219
|
-
};
|
|
220
|
-
});
|
|
221
|
-
const builders = {
|
|
222
|
-
user: userBuilder,
|
|
223
|
-
post: postBuilder
|
|
224
|
-
};
|
|
225
|
-
const factory = new KyselyFactory(builders, {}, trx);
|
|
226
|
-
const post = await factory.insert("post");
|
|
227
|
-
expect(post.userId).toBeDefined();
|
|
228
|
-
const relatedUser = await trx.selectFrom("users").selectAll().where("id", "=", post.userId).executeTakeFirst();
|
|
229
|
-
expect(relatedUser).toBeDefined();
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
//#endregion
|