@geekmidas/testkit 0.0.15 → 0.0.17
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-CRquB4vz.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-72P98y5I.d.mts → KyselyFactory-BDS_QqRT.d.mts} +4 -3
- 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-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-C3tHvX1d.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-BxjlD1YM.mjs +2 -1
- package/dist/VitestKyselyTransactionIsolator-BxjlD1YM.mjs.map +1 -0
- package/dist/{VitestKyselyTransactionIsolator-CnxpE9cH.d.mts → VitestKyselyTransactionIsolator-COCVfvfr.d.mts} +3 -2
- package/dist/VitestKyselyTransactionIsolator-Cst3vFjb.cjs +2 -1
- package/dist/VitestKyselyTransactionIsolator-Cst3vFjb.cjs.map +1 -0
- package/dist/VitestKyselyTransactionIsolator-DYUYVEh9.d.cts +2 -1
- package/dist/VitestKyselyTransactionIsolator.d.mts +2 -2
- package/dist/VitestObjectionTransactionIsolator-BU-jXEhz.mjs +2 -1
- package/dist/VitestObjectionTransactionIsolator-BU-jXEhz.mjs.map +1 -0
- package/dist/VitestObjectionTransactionIsolator-CJ4ds5Qv.d.cts +2 -1
- package/dist/VitestObjectionTransactionIsolator-DzeF4UAq.cjs +2 -1
- package/dist/VitestObjectionTransactionIsolator-DzeF4UAq.cjs.map +1 -0
- package/dist/{VitestObjectionTransactionIsolator-DIM79dCq.d.mts → VitestObjectionTransactionIsolator-b973r9O1.d.mts} +3 -2
- package/dist/VitestObjectionTransactionIsolator.d.mts +2 -2
- 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/better-auth.cjs +245 -0
- package/dist/better-auth.cjs.map +1 -0
- package/dist/better-auth.d.cts +17 -0
- package/dist/better-auth.d.mts +17 -0
- package/dist/better-auth.mjs +244 -0
- package/dist/better-auth.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-C-Iuk_R1.d.mts → faker-Br8MzXil.d.mts} +4 -3
- package/dist/{faker-BSH1EMtg.d.cts → faker-Cg76aFNO.d.cts} +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 +65 -2
- 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 +67 -4
- 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 +80 -2
- 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 +82 -4
- 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 +30 -2
- package/src/__tests__/better-auth.spec.ts +21 -0
- package/src/aws.ts +131 -0
- package/src/better-auth.ts +327 -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-C3h7kitU.mjs +0 -67
- package/dist/kysely-VU3MwvMD.cjs +0 -72
- package/dist/objection-BI7F86qf.mjs +0 -82
- package/dist/objection-BpLv_ZfC.cjs +0 -87
|
@@ -1,281 +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-BxjlD1YM.mjs";
|
|
8
|
-
import { createKyselyDb } from "../helpers-BuPmgzyQ.mjs";
|
|
9
|
-
import { wrapVitestKyselyTransaction } from "../kysely-C3h7kitU.mjs";
|
|
10
|
-
import { TEST_DATABASE_CONFIG, createTestTables } from "../helpers-B4TXg3Wp.mjs";
|
|
11
|
-
import { beforeAll, describe, expect, it } from "vitest";
|
|
12
|
-
|
|
13
|
-
//#region src/__tests__/integration.spec.ts
|
|
14
|
-
const db = () => createKyselyDb(TEST_DATABASE_CONFIG);
|
|
15
|
-
const it$1 = wrapVitestKyselyTransaction(it, db, createTestTables);
|
|
16
|
-
describe("Testkit Integration Tests", () => {
|
|
17
|
-
beforeAll(async () => {});
|
|
18
|
-
describe("Complex Factory Scenarios", () => {
|
|
19
|
-
it$1("should handle complex multi-table data creation", async ({ trx }) => {
|
|
20
|
-
const userBuilder = KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
21
|
-
name: "John Doe",
|
|
22
|
-
email: `user${Date.now()}-${Math.random()}@example.com`,
|
|
23
|
-
role: "user",
|
|
24
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
25
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
26
|
-
}));
|
|
27
|
-
const postBuilder = KyselyFactory.createBuilder("posts", async (attrs, factory$1) => {
|
|
28
|
-
if (!attrs.userId) {
|
|
29
|
-
const user = await factory$1.insert("user");
|
|
30
|
-
return {
|
|
31
|
-
title: "Default Post Title",
|
|
32
|
-
content: "Default post content...",
|
|
33
|
-
userId: user.id,
|
|
34
|
-
published: false,
|
|
35
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
36
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
return {
|
|
40
|
-
title: "Default Post Title",
|
|
41
|
-
content: "Default post content...",
|
|
42
|
-
published: false,
|
|
43
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
44
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
45
|
-
};
|
|
46
|
-
});
|
|
47
|
-
const commentBuilder = KyselyFactory.createBuilder("comments", async (attrs, factory$1) => {
|
|
48
|
-
let postId = attrs.postId;
|
|
49
|
-
let userId = attrs.userId;
|
|
50
|
-
if (!postId) {
|
|
51
|
-
const post = await factory$1.insert("post");
|
|
52
|
-
postId = post.id;
|
|
53
|
-
}
|
|
54
|
-
if (!userId) {
|
|
55
|
-
const user = await factory$1.insert("user");
|
|
56
|
-
userId = user.id;
|
|
57
|
-
}
|
|
58
|
-
return {
|
|
59
|
-
content: "Default comment content",
|
|
60
|
-
postId,
|
|
61
|
-
userId,
|
|
62
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
63
|
-
};
|
|
64
|
-
});
|
|
65
|
-
const builders = {
|
|
66
|
-
user: userBuilder,
|
|
67
|
-
post: postBuilder,
|
|
68
|
-
comment: commentBuilder
|
|
69
|
-
};
|
|
70
|
-
const factory = new KyselyFactory(builders, {}, trx);
|
|
71
|
-
const author = await factory.insert("user", {
|
|
72
|
-
name: "Jane Author",
|
|
73
|
-
email: "jane@author.com",
|
|
74
|
-
role: "admin"
|
|
75
|
-
});
|
|
76
|
-
const posts = await factory.insertMany(3, "post", (idx) => ({
|
|
77
|
-
title: `Post ${idx + 1}`,
|
|
78
|
-
content: `Content for post ${idx + 1}`,
|
|
79
|
-
userId: author.id,
|
|
80
|
-
published: idx < 2
|
|
81
|
-
}));
|
|
82
|
-
const comments = await factory.insertMany(5, "comment", (idx) => ({
|
|
83
|
-
content: `Comment ${idx + 1} on first post`,
|
|
84
|
-
postId: posts[0].id
|
|
85
|
-
}));
|
|
86
|
-
expect(author.name).toBe("Jane Author");
|
|
87
|
-
expect(author.role).toBe("admin");
|
|
88
|
-
expect(posts).toHaveLength(3);
|
|
89
|
-
expect(posts[0].title).toBe("Post 1");
|
|
90
|
-
expect(posts[0].published).toBe(true);
|
|
91
|
-
expect(posts[2].published).toBe(false);
|
|
92
|
-
expect(comments).toHaveLength(5);
|
|
93
|
-
comments.forEach((comment, idx) => {
|
|
94
|
-
expect(comment.content).toBe(`Comment ${idx + 1} on first post`);
|
|
95
|
-
expect(comment.postId).toBe(posts[0].id);
|
|
96
|
-
});
|
|
97
|
-
const authorPosts = await trx.selectFrom("posts").selectAll().where("userId", "=", author.id).execute();
|
|
98
|
-
expect(authorPosts).toHaveLength(3);
|
|
99
|
-
const firstPostComments = await trx.selectFrom("comments").selectAll().where("postId", "=", posts[0].id).execute();
|
|
100
|
-
expect(firstPostComments).toHaveLength(5);
|
|
101
|
-
});
|
|
102
|
-
it$1("should handle seeds for complex scenarios", async ({ trx }) => {
|
|
103
|
-
const c = await trx.selectFrom("users").select(trx.fn.count("id").as("count")).executeTakeFirst();
|
|
104
|
-
const userBuilder = KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
105
|
-
name: "Default User",
|
|
106
|
-
email: `user${Date.now()}-${Math.random()}@example.com`,
|
|
107
|
-
role: "user",
|
|
108
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
109
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
110
|
-
}));
|
|
111
|
-
const postBuilder = KyselyFactory.createBuilder("posts", async (attrs, factory$1) => {
|
|
112
|
-
if (!attrs.userId) {
|
|
113
|
-
const user = await factory$1.insert("user");
|
|
114
|
-
return {
|
|
115
|
-
title: "Default Post",
|
|
116
|
-
content: "Default content",
|
|
117
|
-
userId: user.id,
|
|
118
|
-
published: false,
|
|
119
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
120
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
return {
|
|
124
|
-
title: "Default Post",
|
|
125
|
-
content: "Default content",
|
|
126
|
-
published: false,
|
|
127
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
128
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
129
|
-
};
|
|
130
|
-
});
|
|
131
|
-
const builders = {
|
|
132
|
-
user: userBuilder,
|
|
133
|
-
post: postBuilder
|
|
134
|
-
};
|
|
135
|
-
const seeds = {
|
|
136
|
-
blogWithAdminAndPosts: KyselyFactory.createSeed(async (attrs, factory$1, db$1) => {
|
|
137
|
-
const admin = await factory$1.insert("user", {
|
|
138
|
-
name: "Blog Admin",
|
|
139
|
-
email: "admin@blog.com",
|
|
140
|
-
role: "admin"
|
|
141
|
-
});
|
|
142
|
-
const postCount = attrs.postCount || 3;
|
|
143
|
-
const posts = await factory$1.insertMany(postCount, "post", (idx) => ({
|
|
144
|
-
title: `Admin Post ${idx + 1}`,
|
|
145
|
-
content: `Content for admin post ${idx + 1}`,
|
|
146
|
-
userId: admin.id,
|
|
147
|
-
published: true
|
|
148
|
-
}));
|
|
149
|
-
return {
|
|
150
|
-
admin,
|
|
151
|
-
posts,
|
|
152
|
-
summary: {
|
|
153
|
-
adminId: admin.id,
|
|
154
|
-
postIds: posts.map((p) => p.id),
|
|
155
|
-
totalPosts: posts.length
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
}),
|
|
159
|
-
usersWithPosts: KyselyFactory.createSeed(async (attrs, factory$1, db$1) => {
|
|
160
|
-
const userCount = attrs.userCount || 2;
|
|
161
|
-
const postsPerUser = attrs.postsPerUser || 2;
|
|
162
|
-
const results = [];
|
|
163
|
-
for (let i = 0; i < userCount; i++) {
|
|
164
|
-
const user = await factory$1.insert("user", {
|
|
165
|
-
name: `User ${i + 1}`,
|
|
166
|
-
email: `user${i + 1}@example.com`
|
|
167
|
-
});
|
|
168
|
-
const posts = await factory$1.insertMany(postsPerUser, "post", (postIdx) => ({
|
|
169
|
-
title: `User ${i + 1} Post ${postIdx + 1}`,
|
|
170
|
-
content: `Content from user ${i + 1}, post ${postIdx + 1}`,
|
|
171
|
-
userId: user.id,
|
|
172
|
-
published: postIdx === 0
|
|
173
|
-
}));
|
|
174
|
-
results.push({
|
|
175
|
-
user,
|
|
176
|
-
posts
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
return results;
|
|
180
|
-
})
|
|
181
|
-
};
|
|
182
|
-
const factory = new KyselyFactory(builders, seeds, trx);
|
|
183
|
-
const blogData = await factory.seed("blogWithAdminAndPosts", { postCount: 5 });
|
|
184
|
-
expect(blogData.admin.name).toBe("Blog Admin");
|
|
185
|
-
expect(blogData.admin.role).toBe("admin");
|
|
186
|
-
expect(blogData.posts).toHaveLength(5);
|
|
187
|
-
expect(blogData.summary.totalPosts).toBe(5);
|
|
188
|
-
const userData = await factory.seed("usersWithPosts", {
|
|
189
|
-
userCount: 3,
|
|
190
|
-
postsPerUser: 4
|
|
191
|
-
});
|
|
192
|
-
expect(userData).toHaveLength(3);
|
|
193
|
-
const totalUsers = await trx.selectFrom("users").select(trx.fn.count("id").as("count")).executeTakeFirst();
|
|
194
|
-
const totalPosts = await trx.selectFrom("posts").select(trx.fn.count("id").as("count")).executeTakeFirst();
|
|
195
|
-
expect(Number(totalUsers?.count)).toBe(4);
|
|
196
|
-
expect(Number(totalPosts?.count)).toBe(17);
|
|
197
|
-
});
|
|
198
|
-
it$1("should handle transaction isolation properly", async ({ trx }) => {
|
|
199
|
-
const userBuilder = KyselyFactory.createBuilder("users", async (attrs, factory, db$1, faker) => ({
|
|
200
|
-
name: "Test User",
|
|
201
|
-
email: faker.internet.email(),
|
|
202
|
-
role: "user",
|
|
203
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
204
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
205
|
-
}));
|
|
206
|
-
const builders = { user: userBuilder };
|
|
207
|
-
const factory1 = new KyselyFactory(builders, {}, trx);
|
|
208
|
-
const user = await factory1.insert("user", {
|
|
209
|
-
name: "Transaction User",
|
|
210
|
-
email: "transaction@test.com"
|
|
211
|
-
});
|
|
212
|
-
const userInTrx = await trx.selectFrom("users").selectAll().where("id", "=", user.id).executeTakeFirst();
|
|
213
|
-
expect(userInTrx).toBeDefined();
|
|
214
|
-
expect(userInTrx?.name).toBe("Transaction User");
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
describe("Performance and Edge Cases", () => {
|
|
218
|
-
it$1("should handle creating many records efficiently", async ({ trx }) => {
|
|
219
|
-
const userBuilder = KyselyFactory.createBuilder("users", async (attrs, factory$1, db$1, faker) => ({
|
|
220
|
-
name: `User ${Math.random()}`,
|
|
221
|
-
email: faker.internet.email().toLowerCase(),
|
|
222
|
-
role: "user",
|
|
223
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
224
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
225
|
-
}));
|
|
226
|
-
const builders = { user: userBuilder };
|
|
227
|
-
const factory = new KyselyFactory(builders, {}, trx);
|
|
228
|
-
const startTime = Date.now();
|
|
229
|
-
const users = await factory.insertMany(100, "user");
|
|
230
|
-
const endTime = Date.now();
|
|
231
|
-
const duration = endTime - startTime;
|
|
232
|
-
expect(users).toHaveLength(100);
|
|
233
|
-
expect(duration).toBeLessThan(5e3);
|
|
234
|
-
const emails = users.map((u) => u.email);
|
|
235
|
-
const uniqueEmails = new Set(emails);
|
|
236
|
-
expect(uniqueEmails.size).toBe(100);
|
|
237
|
-
});
|
|
238
|
-
it$1("should handle complex attribute generation", async ({ trx }) => {
|
|
239
|
-
const userBuilder = KyselyFactory.createBuilder("users", async (attrs, factory$1, db$1, faker) => {
|
|
240
|
-
return {
|
|
241
|
-
name: `Generated User ${attrs.id}`,
|
|
242
|
-
email: faker.internet.email().toLowerCase(),
|
|
243
|
-
role: "user"
|
|
244
|
-
};
|
|
245
|
-
});
|
|
246
|
-
const postBuilder = KyselyFactory.createBuilder("posts", async (attrs, factory$1) => {
|
|
247
|
-
let userId = attrs.userId;
|
|
248
|
-
if (!userId) {
|
|
249
|
-
const user = await factory$1.insert("user");
|
|
250
|
-
userId = user.id;
|
|
251
|
-
}
|
|
252
|
-
return {
|
|
253
|
-
title: `Auto-generated Post`,
|
|
254
|
-
content: `This is auto-generated content for post. Lorem ipsum dolor sit amet.`,
|
|
255
|
-
published: true,
|
|
256
|
-
userId,
|
|
257
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
258
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
259
|
-
};
|
|
260
|
-
});
|
|
261
|
-
const builders = {
|
|
262
|
-
user: userBuilder,
|
|
263
|
-
post: postBuilder
|
|
264
|
-
};
|
|
265
|
-
const factory = new KyselyFactory(builders, {}, trx);
|
|
266
|
-
const posts = await factory.insertMany(10, "post", (i) => ({ published: i % 2 === 0 }));
|
|
267
|
-
expect(posts).toHaveLength(10);
|
|
268
|
-
const users = await trx.selectFrom("users").selectAll().execute();
|
|
269
|
-
users.forEach((user) => {
|
|
270
|
-
expect(user.email).toBe(user.email.toLowerCase());
|
|
271
|
-
expect(user.name).not.toMatch(/^\s|\s$/);
|
|
272
|
-
});
|
|
273
|
-
const publishedPosts = posts.filter((p) => p.published);
|
|
274
|
-
const unpublishedPosts = posts.filter((p) => !p.published);
|
|
275
|
-
expect(publishedPosts).toHaveLength(5);
|
|
276
|
-
expect(unpublishedPosts).toHaveLength(5);
|
|
277
|
-
});
|
|
278
|
-
});
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
//#endregion
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { CamelCasePlugin, Kysely, PostgresDialect, sql } from "kysely";
|
|
2
|
-
import pg, { Client } from "pg";
|
|
3
|
-
import knex from "knex";
|
|
4
|
-
|
|
5
|
-
//#region test/globalSetup.ts
|
|
6
|
-
const TEST_DATABASE_NAME = "geekmidas_test";
|
|
7
|
-
const TEST_DATABASE_CONFIG = {
|
|
8
|
-
host: "localhost",
|
|
9
|
-
port: 5432,
|
|
10
|
-
user: "geekmidas",
|
|
11
|
-
password: "geekmidas",
|
|
12
|
-
database: TEST_DATABASE_NAME
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
//#endregion
|
|
16
|
-
//#region test/helpers.ts
|
|
17
|
-
/**
|
|
18
|
-
* Creates a Knex database instance for testing
|
|
19
|
-
*/
|
|
20
|
-
function createKnexDb() {
|
|
21
|
-
return knex({
|
|
22
|
-
client: "pg",
|
|
23
|
-
connection: TEST_DATABASE_CONFIG
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Creates test tables using Kysely
|
|
28
|
-
*/
|
|
29
|
-
async function createTestTables(db) {
|
|
30
|
-
await db.schema.createTable("users").addColumn("id", "bigserial", (col) => col.primaryKey()).addColumn("name", "varchar", (col) => col.notNull()).addColumn("email", "varchar", (col) => col.notNull().unique()).addColumn("role", "varchar", (col) => col.defaultTo("user")).addColumn("created_at", "timestamp", (col) => col.defaultTo(sql`now()`).notNull()).addColumn("updated_at", "timestamp", (col) => col.defaultTo(sql`now()`).notNull()).execute();
|
|
31
|
-
await db.schema.createTable("posts").addColumn("id", "bigserial", (col) => col.primaryKey()).addColumn("title", "varchar", (col) => col.notNull()).addColumn("content", "text", (col) => col.notNull()).addColumn("user_id", "bigint", (col) => col.notNull().references("users.id").onDelete("cascade")).addColumn("published", "boolean", (col) => col.defaultTo(false)).addColumn("created_at", "timestamp", (col) => col.defaultTo(sql`now()`).notNull()).addColumn("updated_at", "timestamp", (col) => col.defaultTo(sql`now()`).notNull()).execute();
|
|
32
|
-
await db.schema.createTable("comments").addColumn("id", "bigserial", (col) => col.primaryKey()).addColumn("content", "text", (col) => col.notNull()).addColumn("post_id", "bigint", (col) => col.notNull().references("posts.id").onDelete("cascade")).addColumn("user_id", "bigint", (col) => col.notNull().references("users.id").onDelete("cascade")).addColumn("created_at", "timestamp", (col) => col.defaultTo(sql`now()`).notNull()).execute();
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Creates test tables using Knex
|
|
36
|
-
*/
|
|
37
|
-
async function createTestTablesKnex(trx) {
|
|
38
|
-
await trx.raw(`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`);
|
|
39
|
-
await trx.schema.createTableIfNotExists("users", (table) => {
|
|
40
|
-
table.uuid("id").primary().defaultTo(trx.raw("uuid_generate_v4()"));
|
|
41
|
-
table.string("name").notNullable();
|
|
42
|
-
});
|
|
43
|
-
await trx.schema.createTableIfNotExists("posts", (table) => {
|
|
44
|
-
table.uuid("id").primary().defaultTo(trx.raw("uuid_generate_v4()"));
|
|
45
|
-
table.string("title").notNullable();
|
|
46
|
-
table.uuid("user_id").notNullable().references("id").inTable("users").onDelete("cascade");
|
|
47
|
-
});
|
|
48
|
-
await trx.schema.createTableIfNotExists("comments", (table) => {
|
|
49
|
-
table.uuid("id").primary().defaultTo(trx.raw("uuid_generate_v4()"));
|
|
50
|
-
table.text("content").notNullable();
|
|
51
|
-
table.uuid("post_id").notNullable().references("id").inTable("posts").onDelete("cascade");
|
|
52
|
-
table.uuid("user_id").notNullable().references("id").inTable("users").onDelete("cascade");
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Helper for PostgresMigrator tests - creates a separate test database
|
|
57
|
-
*/
|
|
58
|
-
async function createTestDatabase(dbName) {
|
|
59
|
-
const adminConfig = {
|
|
60
|
-
host: TEST_DATABASE_CONFIG.host,
|
|
61
|
-
port: TEST_DATABASE_CONFIG.port,
|
|
62
|
-
user: TEST_DATABASE_CONFIG.user,
|
|
63
|
-
password: TEST_DATABASE_CONFIG.password,
|
|
64
|
-
database: "postgres"
|
|
65
|
-
};
|
|
66
|
-
const client = new pg.Client(adminConfig);
|
|
67
|
-
try {
|
|
68
|
-
await client.connect();
|
|
69
|
-
await client.query(`DROP DATABASE IF EXISTS "${dbName}"`);
|
|
70
|
-
await client.query(`CREATE DATABASE "${dbName}"`);
|
|
71
|
-
} finally {
|
|
72
|
-
await client.end();
|
|
73
|
-
}
|
|
74
|
-
return async () => {
|
|
75
|
-
const cleanupClient = new pg.Client(adminConfig);
|
|
76
|
-
try {
|
|
77
|
-
await cleanupClient.connect();
|
|
78
|
-
await cleanupClient.query(`DROP DATABASE IF EXISTS "${dbName}"`);
|
|
79
|
-
} finally {
|
|
80
|
-
await cleanupClient.end();
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
//#endregion
|
|
86
|
-
export { TEST_DATABASE_CONFIG, createKnexDb, createTestDatabase, createTestTables, createTestTablesKnex };
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
-
const kysely = require_chunk.__toESM(require("kysely"));
|
|
3
|
-
const pg = require_chunk.__toESM(require("pg"));
|
|
4
|
-
const knex = require_chunk.__toESM(require("knex"));
|
|
5
|
-
|
|
6
|
-
//#region test/globalSetup.ts
|
|
7
|
-
const TEST_DATABASE_NAME = "geekmidas_test";
|
|
8
|
-
const TEST_DATABASE_CONFIG = {
|
|
9
|
-
host: "localhost",
|
|
10
|
-
port: 5432,
|
|
11
|
-
user: "geekmidas",
|
|
12
|
-
password: "geekmidas",
|
|
13
|
-
database: TEST_DATABASE_NAME
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
//#endregion
|
|
17
|
-
//#region test/helpers.ts
|
|
18
|
-
/**
|
|
19
|
-
* Creates a Knex database instance for testing
|
|
20
|
-
*/
|
|
21
|
-
function createKnexDb() {
|
|
22
|
-
return (0, knex.default)({
|
|
23
|
-
client: "pg",
|
|
24
|
-
connection: TEST_DATABASE_CONFIG
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Creates test tables using Kysely
|
|
29
|
-
*/
|
|
30
|
-
async function createTestTables(db) {
|
|
31
|
-
await db.schema.createTable("users").addColumn("id", "bigserial", (col) => col.primaryKey()).addColumn("name", "varchar", (col) => col.notNull()).addColumn("email", "varchar", (col) => col.notNull().unique()).addColumn("role", "varchar", (col) => col.defaultTo("user")).addColumn("created_at", "timestamp", (col) => col.defaultTo(kysely.sql`now()`).notNull()).addColumn("updated_at", "timestamp", (col) => col.defaultTo(kysely.sql`now()`).notNull()).execute();
|
|
32
|
-
await db.schema.createTable("posts").addColumn("id", "bigserial", (col) => col.primaryKey()).addColumn("title", "varchar", (col) => col.notNull()).addColumn("content", "text", (col) => col.notNull()).addColumn("user_id", "bigint", (col) => col.notNull().references("users.id").onDelete("cascade")).addColumn("published", "boolean", (col) => col.defaultTo(false)).addColumn("created_at", "timestamp", (col) => col.defaultTo(kysely.sql`now()`).notNull()).addColumn("updated_at", "timestamp", (col) => col.defaultTo(kysely.sql`now()`).notNull()).execute();
|
|
33
|
-
await db.schema.createTable("comments").addColumn("id", "bigserial", (col) => col.primaryKey()).addColumn("content", "text", (col) => col.notNull()).addColumn("post_id", "bigint", (col) => col.notNull().references("posts.id").onDelete("cascade")).addColumn("user_id", "bigint", (col) => col.notNull().references("users.id").onDelete("cascade")).addColumn("created_at", "timestamp", (col) => col.defaultTo(kysely.sql`now()`).notNull()).execute();
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Creates test tables using Knex
|
|
37
|
-
*/
|
|
38
|
-
async function createTestTablesKnex(trx) {
|
|
39
|
-
await trx.raw(`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`);
|
|
40
|
-
await trx.schema.createTableIfNotExists("users", (table) => {
|
|
41
|
-
table.uuid("id").primary().defaultTo(trx.raw("uuid_generate_v4()"));
|
|
42
|
-
table.string("name").notNullable();
|
|
43
|
-
});
|
|
44
|
-
await trx.schema.createTableIfNotExists("posts", (table) => {
|
|
45
|
-
table.uuid("id").primary().defaultTo(trx.raw("uuid_generate_v4()"));
|
|
46
|
-
table.string("title").notNullable();
|
|
47
|
-
table.uuid("user_id").notNullable().references("id").inTable("users").onDelete("cascade");
|
|
48
|
-
});
|
|
49
|
-
await trx.schema.createTableIfNotExists("comments", (table) => {
|
|
50
|
-
table.uuid("id").primary().defaultTo(trx.raw("uuid_generate_v4()"));
|
|
51
|
-
table.text("content").notNullable();
|
|
52
|
-
table.uuid("post_id").notNullable().references("id").inTable("posts").onDelete("cascade");
|
|
53
|
-
table.uuid("user_id").notNullable().references("id").inTable("users").onDelete("cascade");
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Helper for PostgresMigrator tests - creates a separate test database
|
|
58
|
-
*/
|
|
59
|
-
async function createTestDatabase(dbName) {
|
|
60
|
-
const adminConfig = {
|
|
61
|
-
host: TEST_DATABASE_CONFIG.host,
|
|
62
|
-
port: TEST_DATABASE_CONFIG.port,
|
|
63
|
-
user: TEST_DATABASE_CONFIG.user,
|
|
64
|
-
password: TEST_DATABASE_CONFIG.password,
|
|
65
|
-
database: "postgres"
|
|
66
|
-
};
|
|
67
|
-
const client = new pg.default.Client(adminConfig);
|
|
68
|
-
try {
|
|
69
|
-
await client.connect();
|
|
70
|
-
await client.query(`DROP DATABASE IF EXISTS "${dbName}"`);
|
|
71
|
-
await client.query(`CREATE DATABASE "${dbName}"`);
|
|
72
|
-
} finally {
|
|
73
|
-
await client.end();
|
|
74
|
-
}
|
|
75
|
-
return async () => {
|
|
76
|
-
const cleanupClient = new pg.default.Client(adminConfig);
|
|
77
|
-
try {
|
|
78
|
-
await cleanupClient.connect();
|
|
79
|
-
await cleanupClient.query(`DROP DATABASE IF EXISTS "${dbName}"`);
|
|
80
|
-
} finally {
|
|
81
|
-
await cleanupClient.end();
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
//#endregion
|
|
87
|
-
Object.defineProperty(exports, 'TEST_DATABASE_CONFIG', {
|
|
88
|
-
enumerable: true,
|
|
89
|
-
get: function () {
|
|
90
|
-
return TEST_DATABASE_CONFIG;
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
Object.defineProperty(exports, 'createKnexDb', {
|
|
94
|
-
enumerable: true,
|
|
95
|
-
get: function () {
|
|
96
|
-
return createKnexDb;
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
Object.defineProperty(exports, 'createTestDatabase', {
|
|
100
|
-
enumerable: true,
|
|
101
|
-
get: function () {
|
|
102
|
-
return createTestDatabase;
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
Object.defineProperty(exports, 'createTestTables', {
|
|
106
|
-
enumerable: true,
|
|
107
|
-
get: function () {
|
|
108
|
-
return createTestTables;
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
Object.defineProperty(exports, 'createTestTablesKnex', {
|
|
112
|
-
enumerable: true,
|
|
113
|
-
get: function () {
|
|
114
|
-
return createTestTablesKnex;
|
|
115
|
-
}
|
|
116
|
-
});
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { CamelCasePlugin, Kysely, PostgresDialect } from "kysely";
|
|
2
|
-
import pg from "pg";
|
|
3
|
-
|
|
4
|
-
//#region src/helpers.ts
|
|
5
|
-
/**
|
|
6
|
-
* Creates a Kysely database instance with PostgreSQL dialect and camelCase plugin.
|
|
7
|
-
* This is a convenience function for quickly setting up a Kysely connection for testing.
|
|
8
|
-
*
|
|
9
|
-
* @template Database - The database schema type
|
|
10
|
-
* @param config - PostgreSQL connection configuration (pg.Pool config)
|
|
11
|
-
* @returns A configured Kysely instance
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```typescript
|
|
15
|
-
* interface Database {
|
|
16
|
-
* users: UsersTable;
|
|
17
|
-
* posts: PostsTable;
|
|
18
|
-
* }
|
|
19
|
-
*
|
|
20
|
-
* // Create from connection string
|
|
21
|
-
* const db = createKyselyDb<Database>({
|
|
22
|
-
* connectionString: 'postgresql://user:pass@localhost:5432/testdb'
|
|
23
|
-
* });
|
|
24
|
-
*
|
|
25
|
-
* // Create with detailed config
|
|
26
|
-
* const db = createKyselyDb<Database>({
|
|
27
|
-
* host: 'localhost',
|
|
28
|
-
* port: 5432,
|
|
29
|
-
* database: 'testdb',
|
|
30
|
-
* user: 'testuser',
|
|
31
|
-
* password: 'testpass',
|
|
32
|
-
* max: 10 // connection pool size
|
|
33
|
-
* });
|
|
34
|
-
*
|
|
35
|
-
* // Use in tests
|
|
36
|
-
* const users = await db.selectFrom('users').selectAll().execute();
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
function createKyselyDb(config) {
|
|
40
|
-
return new Kysely({
|
|
41
|
-
dialect: new PostgresDialect({ pool: new pg.Pool(config) }),
|
|
42
|
-
plugins: [new CamelCasePlugin()]
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
//#endregion
|
|
47
|
-
export { createKyselyDb };
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
-
const kysely = require_chunk.__toESM(require("kysely"));
|
|
3
|
-
const pg = require_chunk.__toESM(require("pg"));
|
|
4
|
-
|
|
5
|
-
//#region src/helpers.ts
|
|
6
|
-
/**
|
|
7
|
-
* Creates a Kysely database instance with PostgreSQL dialect and camelCase plugin.
|
|
8
|
-
* This is a convenience function for quickly setting up a Kysely connection for testing.
|
|
9
|
-
*
|
|
10
|
-
* @template Database - The database schema type
|
|
11
|
-
* @param config - PostgreSQL connection configuration (pg.Pool config)
|
|
12
|
-
* @returns A configured Kysely instance
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* interface Database {
|
|
17
|
-
* users: UsersTable;
|
|
18
|
-
* posts: PostsTable;
|
|
19
|
-
* }
|
|
20
|
-
*
|
|
21
|
-
* // Create from connection string
|
|
22
|
-
* const db = createKyselyDb<Database>({
|
|
23
|
-
* connectionString: 'postgresql://user:pass@localhost:5432/testdb'
|
|
24
|
-
* });
|
|
25
|
-
*
|
|
26
|
-
* // Create with detailed config
|
|
27
|
-
* const db = createKyselyDb<Database>({
|
|
28
|
-
* host: 'localhost',
|
|
29
|
-
* port: 5432,
|
|
30
|
-
* database: 'testdb',
|
|
31
|
-
* user: 'testuser',
|
|
32
|
-
* password: 'testpass',
|
|
33
|
-
* max: 10 // connection pool size
|
|
34
|
-
* });
|
|
35
|
-
*
|
|
36
|
-
* // Use in tests
|
|
37
|
-
* const users = await db.selectFrom('users').selectAll().execute();
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
function createKyselyDb(config) {
|
|
41
|
-
return new kysely.Kysely({
|
|
42
|
-
dialect: new kysely.PostgresDialect({ pool: new pg.default.Pool(config) }),
|
|
43
|
-
plugins: [new kysely.CamelCasePlugin()]
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
//#endregion
|
|
48
|
-
Object.defineProperty(exports, 'createKyselyDb', {
|
|
49
|
-
enumerable: true,
|
|
50
|
-
get: function () {
|
|
51
|
-
return createKyselyDb;
|
|
52
|
-
}
|
|
53
|
-
});
|
package/dist/kysely-C3h7kitU.mjs
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { IsolationLevel } from "./VitestTransactionIsolator-CskiiJbW.mjs";
|
|
2
|
-
import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-BxjlD1YM.mjs";
|
|
3
|
-
|
|
4
|
-
//#region src/kysely.ts
|
|
5
|
-
/**
|
|
6
|
-
* Creates a wrapped Vitest test API with automatic transaction rollback for Kysely.
|
|
7
|
-
* Each test runs in an isolated database transaction that is rolled back after completion.
|
|
8
|
-
* This ensures tests don't affect each other's data and run faster than truncating tables.
|
|
9
|
-
*
|
|
10
|
-
* @template Database - The database schema type
|
|
11
|
-
* @param api - The Vitest test API (usually `test` from vitest)
|
|
12
|
-
* @param db - The Kysely database instance
|
|
13
|
-
* @param setup - Optional setup function to run before each test in the transaction
|
|
14
|
-
* @param level - Transaction isolation level (defaults to REPEATABLE_READ)
|
|
15
|
-
* @returns A wrapped test API that provides transaction isolation
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```typescript
|
|
19
|
-
* import { test } from 'vitest';
|
|
20
|
-
* import { wrapVitestKyselyTransaction } from '@geekmidas/testkit/kysely';
|
|
21
|
-
* import { db } from './database';
|
|
22
|
-
*
|
|
23
|
-
* // Create isolated test with automatic rollback
|
|
24
|
-
* const isolatedTest = wrapVitestKyselyTransaction(test, db);
|
|
25
|
-
*
|
|
26
|
-
* // Use in tests - each test gets its own transaction
|
|
27
|
-
* isolatedTest('should create user', async ({ trx }) => {
|
|
28
|
-
* const user = await trx
|
|
29
|
-
* .insertInto('users')
|
|
30
|
-
* .values({ name: 'Test User', email: 'test@example.com' })
|
|
31
|
-
* .returningAll()
|
|
32
|
-
* .executeTakeFirst();
|
|
33
|
-
*
|
|
34
|
-
* expect(user).toBeDefined();
|
|
35
|
-
* // User is automatically rolled back after test
|
|
36
|
-
* });
|
|
37
|
-
*
|
|
38
|
-
* // With setup function for common test data
|
|
39
|
-
* const testWithSetup = wrapVitestKyselyTransaction(
|
|
40
|
-
* test,
|
|
41
|
-
* db,
|
|
42
|
-
* async (trx) => {
|
|
43
|
-
* // Create common test data
|
|
44
|
-
* await trx.insertInto('settings')
|
|
45
|
-
* .values({ key: 'test_mode', value: 'true' })
|
|
46
|
-
* .execute();
|
|
47
|
-
* }
|
|
48
|
-
* );
|
|
49
|
-
*
|
|
50
|
-
* testWithSetup('should have test settings', async ({ trx }) => {
|
|
51
|
-
* const setting = await trx
|
|
52
|
-
* .selectFrom('settings')
|
|
53
|
-
* .where('key', '=', 'test_mode')
|
|
54
|
-
* .selectAll()
|
|
55
|
-
* .executeTakeFirst();
|
|
56
|
-
*
|
|
57
|
-
* expect(setting?.value).toBe('true');
|
|
58
|
-
* });
|
|
59
|
-
* ```
|
|
60
|
-
*/
|
|
61
|
-
function wrapVitestKyselyTransaction(api, connection, setup, level = IsolationLevel.REPEATABLE_READ) {
|
|
62
|
-
const wrapper = new VitestKyselyTransactionIsolator(api);
|
|
63
|
-
return wrapper.wrapVitestWithTransaction(connection, setup, level);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
//#endregion
|
|
67
|
-
export { wrapVitestKyselyTransaction };
|