@geekmidas/testkit 0.0.12 → 0.0.13
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/README.md +1 -1
- package/dist/{Factory-Bm44VKa-.d.cts → Factory-D7P3bKKb.d.mts} +2 -2
- package/dist/{Factory-tjCDNgUK.d.mts → Factory-pNV7ZQ7-.d.cts} +2 -2
- package/dist/Factory.d.cts +2 -2
- package/dist/Factory.d.mts +2 -2
- package/dist/{KyselyFactory-C3Bc3p4L.mjs → KyselyFactory-BcYkC0t2.mjs} +1 -1
- package/dist/{KyselyFactory-BoPDDitt.d.cts → KyselyFactory-BrWADI77.d.mts} +3 -3
- package/dist/{KyselyFactory-CXtfmMfK.cjs → KyselyFactory-Cf0o2YxO.cjs} +1 -1
- package/dist/{KyselyFactory-D82j74t9.d.mts → KyselyFactory-DM2dnUXU.d.cts} +3 -3
- package/dist/KyselyFactory.cjs +1 -1
- package/dist/KyselyFactory.d.cts +3 -3
- package/dist/KyselyFactory.d.mts +3 -3
- package/dist/KyselyFactory.mjs +1 -1
- package/dist/{ObjectionFactory-qIICOph3.mjs → ObjectionFactory-8hebmnai.mjs} +20 -4
- package/dist/{ObjectionFactory-BWMTXsxH.d.cts → ObjectionFactory-B40NQWSe.d.mts} +2 -2
- package/dist/{ObjectionFactory-DxIxJagq.cjs → ObjectionFactory-CDriunkS.cjs} +20 -4
- package/dist/{ObjectionFactory-CEG5qUrm.d.mts → ObjectionFactory-D3l1VuyX.d.cts} +2 -2
- package/dist/ObjectionFactory.cjs +1 -1
- package/dist/ObjectionFactory.d.cts +3 -3
- package/dist/ObjectionFactory.d.mts +3 -3
- package/dist/ObjectionFactory.mjs +1 -1
- package/dist/__tests__/KyselyFactory.spec.cjs +2 -2
- package/dist/__tests__/KyselyFactory.spec.mjs +2 -2
- package/dist/__tests__/ObjectionFactory.spec.cjs +288 -450
- package/dist/__tests__/ObjectionFactory.spec.mjs +289 -451
- package/dist/__tests__/PostgresKyselyMigrator.spec.cjs +397 -0
- package/dist/__tests__/PostgresKyselyMigrator.spec.d.cts +1 -0
- package/dist/__tests__/PostgresKyselyMigrator.spec.d.mts +1 -0
- package/dist/__tests__/PostgresKyselyMigrator.spec.mjs +396 -0
- package/dist/__tests__/PostgresMigrator.spec.cjs +1 -1
- package/dist/__tests__/PostgresMigrator.spec.mjs +1 -1
- package/dist/__tests__/PostgresObjectionMigrator.spec.cjs +1 -1
- package/dist/__tests__/PostgresObjectionMigrator.spec.mjs +1 -1
- package/dist/__tests__/VitestObjectionTransactionIsolator.spec.cjs +3 -11
- package/dist/__tests__/VitestObjectionTransactionIsolator.spec.mjs +3 -11
- package/dist/__tests__/integration.spec.cjs +2 -2
- package/dist/__tests__/integration.spec.mjs +2 -2
- package/dist/{faker-km9UhOS6.d.cts → faker-BSH1EMtg.d.cts} +2 -2
- package/dist/{faker-ChuHaYMR.d.mts → faker-C-Iuk_R1.d.mts} +2 -2
- package/dist/faker.d.cts +1 -1
- package/dist/faker.d.mts +1 -1
- package/dist/{helpers-BEmjyUVE.mjs → helpers-B4TXg3Wp.mjs} +11 -36
- package/dist/{helpers-CNMBePuj.cjs → helpers-Bf0nXhbu.cjs} +10 -41
- package/dist/kysely.cjs +1 -1
- package/dist/kysely.d.cts +3 -3
- package/dist/kysely.d.mts +3 -3
- package/dist/kysely.mjs +1 -1
- package/dist/objection.cjs +1 -1
- package/dist/objection.d.cts +3 -3
- package/dist/objection.d.mts +3 -3
- package/dist/objection.mjs +1 -1
- package/package.json +2 -2
- package/src/Factory.ts +4 -1
- package/src/KyselyFactory.ts +6 -2
- package/src/ObjectionFactory.ts +31 -4
- package/src/__tests__/ObjectionFactory.spec.ts +423 -542
- package/src/__tests__/PostgresKyselyMigrator.spec.ts +690 -0
- package/src/__tests__/VitestObjectionTransactionIsolator.spec.ts +0 -8
- package/test/helpers.ts +13 -21
- package/dist/example.cjs +0 -22
- package/dist/example.d.cts +0 -26
- package/dist/example.d.mts +0 -26
- package/dist/example.mjs +0 -22
- package/src/example.ts +0 -45
|
@@ -12,8 +12,6 @@ class User extends Model {
|
|
|
12
12
|
|
|
13
13
|
id!: number;
|
|
14
14
|
name!: string;
|
|
15
|
-
email!: string;
|
|
16
|
-
role?: string;
|
|
17
15
|
createdAt!: Date;
|
|
18
16
|
updatedAt?: Date;
|
|
19
17
|
|
|
@@ -110,9 +108,6 @@ class Comment extends Model {
|
|
|
110
108
|
// Create database connection
|
|
111
109
|
const knex = createKnexDb();
|
|
112
110
|
|
|
113
|
-
// Bind models to Knex instance
|
|
114
|
-
Model.knex(knex);
|
|
115
|
-
|
|
116
111
|
// Create wrapped test with transaction isolation
|
|
117
112
|
const it = wrapVitestObjectionTransaction(base, knex, async (trx) => {
|
|
118
113
|
// Create tables in the transaction
|
|
@@ -125,8 +120,6 @@ describe('VitestObjectionTransactionIsolator', () => {
|
|
|
125
120
|
// Create a user within the transaction
|
|
126
121
|
const user = await User.query(trx).insert({
|
|
127
122
|
name: 'Test User',
|
|
128
|
-
email: 'test@example.com',
|
|
129
|
-
role: 'user',
|
|
130
123
|
});
|
|
131
124
|
|
|
132
125
|
expect(user).toBeDefined();
|
|
@@ -136,7 +129,6 @@ describe('VitestObjectionTransactionIsolator', () => {
|
|
|
136
129
|
// Verify user exists in transaction
|
|
137
130
|
const foundUser = await User.query(trx).findById(user.id);
|
|
138
131
|
expect(foundUser).toBeDefined();
|
|
139
|
-
expect(foundUser?.email).toBe(user.email);
|
|
140
132
|
|
|
141
133
|
// Data will be rolled back after this test
|
|
142
134
|
});
|
package/test/helpers.ts
CHANGED
|
@@ -165,49 +165,41 @@ export async function createTestTables(
|
|
|
165
165
|
export async function createTestTablesKnex(
|
|
166
166
|
trx: Knex.Transaction,
|
|
167
167
|
): Promise<void> {
|
|
168
|
-
// Create users table
|
|
169
|
-
await trx.
|
|
170
|
-
|
|
168
|
+
// Create simple users table for testing factory
|
|
169
|
+
await trx.raw(`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`);
|
|
170
|
+
await trx.schema.createTableIfNotExists('users', (table) => {
|
|
171
|
+
table.uuid('id').primary().defaultTo(trx.raw('uuid_generate_v4()'));
|
|
171
172
|
table.string('name').notNullable();
|
|
172
|
-
table.string('email').notNullable().unique();
|
|
173
|
-
table.string('role').defaultTo('user');
|
|
174
|
-
table.timestamp('created_at').defaultTo(trx.fn.now()).notNullable();
|
|
175
|
-
table.timestamp('updated_at').defaultTo(trx.fn.now()).notNullable();
|
|
176
173
|
});
|
|
177
174
|
|
|
178
|
-
// Create posts table
|
|
179
|
-
await trx.schema.
|
|
180
|
-
table.
|
|
175
|
+
// Create simple posts table for testing factory
|
|
176
|
+
await trx.schema.createTableIfNotExists('posts', (table) => {
|
|
177
|
+
table.uuid('id').primary().defaultTo(trx.raw('uuid_generate_v4()'));
|
|
181
178
|
table.string('title').notNullable();
|
|
182
|
-
table.text('content').notNullable();
|
|
183
179
|
table
|
|
184
|
-
.
|
|
180
|
+
.uuid('user_id')
|
|
185
181
|
.notNullable()
|
|
186
182
|
.references('id')
|
|
187
183
|
.inTable('users')
|
|
188
184
|
.onDelete('cascade');
|
|
189
|
-
table.boolean('published').defaultTo(false);
|
|
190
|
-
table.timestamp('created_at').defaultTo(trx.fn.now()).notNullable();
|
|
191
|
-
table.timestamp('updated_at').defaultTo(trx.fn.now()).notNullable();
|
|
192
185
|
});
|
|
193
186
|
|
|
194
|
-
// Create comments table
|
|
195
|
-
await trx.schema.
|
|
196
|
-
table.
|
|
187
|
+
// Create simple comments table for testing factory
|
|
188
|
+
await trx.schema.createTableIfNotExists('comments', (table) => {
|
|
189
|
+
table.uuid('id').primary().defaultTo(trx.raw('uuid_generate_v4()'));
|
|
197
190
|
table.text('content').notNullable();
|
|
198
191
|
table
|
|
199
|
-
.
|
|
192
|
+
.uuid('post_id')
|
|
200
193
|
.notNullable()
|
|
201
194
|
.references('id')
|
|
202
195
|
.inTable('posts')
|
|
203
196
|
.onDelete('cascade');
|
|
204
197
|
table
|
|
205
|
-
.
|
|
198
|
+
.uuid('user_id')
|
|
206
199
|
.notNullable()
|
|
207
200
|
.references('id')
|
|
208
201
|
.inTable('users')
|
|
209
202
|
.onDelete('cascade');
|
|
210
|
-
table.timestamp('created_at').defaultTo(trx.fn.now()).notNullable();
|
|
211
203
|
});
|
|
212
204
|
}
|
|
213
205
|
|
package/dist/example.cjs
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
require('./Factory-WMhTNZ9S.cjs');
|
|
2
|
-
require('./faker-B14IEMIN.cjs');
|
|
3
|
-
const require_KyselyFactory = require('./KyselyFactory-CXtfmMfK.cjs');
|
|
4
|
-
|
|
5
|
-
//#region src/example.ts
|
|
6
|
-
const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder({
|
|
7
|
-
table: "users",
|
|
8
|
-
defaults: async (attrs) => ({
|
|
9
|
-
name: "John Doe",
|
|
10
|
-
email: `user${Date.now()}@example.com`,
|
|
11
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
12
|
-
})
|
|
13
|
-
});
|
|
14
|
-
const builders = { user: userBuilder };
|
|
15
|
-
const factory = new require_KyselyFactory.KyselyFactory(builders, {}, {});
|
|
16
|
-
factory.insert("user", {
|
|
17
|
-
name: "Jane Doe",
|
|
18
|
-
email: `user${Date.now()}@example.com`,
|
|
19
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
//#endregion
|
package/dist/example.d.cts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { FakerFactory } from "./faker-km9UhOS6.cjs";
|
|
2
|
-
import * as kysely0 from "kysely";
|
|
3
|
-
|
|
4
|
-
//#region src/example.d.ts
|
|
5
|
-
interface Database {
|
|
6
|
-
users: {
|
|
7
|
-
id: number;
|
|
8
|
-
name: string;
|
|
9
|
-
email: string;
|
|
10
|
-
createdAt: Date;
|
|
11
|
-
};
|
|
12
|
-
posts: {
|
|
13
|
-
id: number;
|
|
14
|
-
title: string;
|
|
15
|
-
content: string;
|
|
16
|
-
userId: number;
|
|
17
|
-
createdAt: Date;
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
declare const builders: {
|
|
21
|
-
user: (attrs: Partial<kysely0.Insertable<DB[TableName]>>, factory: any, db: kysely0.Kysely<Database>, faker: FakerFactory) => Promise<kysely0.Selectable<DB[TableName]>>;
|
|
22
|
-
};
|
|
23
|
-
type Builders = typeof builders;
|
|
24
|
-
type Seeds = Record<string, any>;
|
|
25
|
-
//#endregion
|
|
26
|
-
export { Builders, Seeds };
|
package/dist/example.d.mts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { FakerFactory } from "./faker-ChuHaYMR.mjs";
|
|
2
|
-
import * as kysely0 from "kysely";
|
|
3
|
-
|
|
4
|
-
//#region src/example.d.ts
|
|
5
|
-
interface Database {
|
|
6
|
-
users: {
|
|
7
|
-
id: number;
|
|
8
|
-
name: string;
|
|
9
|
-
email: string;
|
|
10
|
-
createdAt: Date;
|
|
11
|
-
};
|
|
12
|
-
posts: {
|
|
13
|
-
id: number;
|
|
14
|
-
title: string;
|
|
15
|
-
content: string;
|
|
16
|
-
userId: number;
|
|
17
|
-
createdAt: Date;
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
declare const builders: {
|
|
21
|
-
user: (attrs: Partial<kysely0.Insertable<DB[TableName]>>, factory: any, db: kysely0.Kysely<Database>, faker: FakerFactory) => Promise<kysely0.Selectable<DB[TableName]>>;
|
|
22
|
-
};
|
|
23
|
-
type Builders = typeof builders;
|
|
24
|
-
type Seeds = Record<string, any>;
|
|
25
|
-
//#endregion
|
|
26
|
-
export { Builders, Seeds };
|
package/dist/example.mjs
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import "./Factory-z2m01hMj.mjs";
|
|
2
|
-
import "./faker-BGKYFoCT.mjs";
|
|
3
|
-
import { KyselyFactory } from "./KyselyFactory-C3Bc3p4L.mjs";
|
|
4
|
-
|
|
5
|
-
//#region src/example.ts
|
|
6
|
-
const userBuilder = KyselyFactory.createBuilder({
|
|
7
|
-
table: "users",
|
|
8
|
-
defaults: async (attrs) => ({
|
|
9
|
-
name: "John Doe",
|
|
10
|
-
email: `user${Date.now()}@example.com`,
|
|
11
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
12
|
-
})
|
|
13
|
-
});
|
|
14
|
-
const builders = { user: userBuilder };
|
|
15
|
-
const factory = new KyselyFactory(builders, {}, {});
|
|
16
|
-
factory.insert("user", {
|
|
17
|
-
name: "Jane Doe",
|
|
18
|
-
email: `user${Date.now()}@example.com`,
|
|
19
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
//#endregion
|
package/src/example.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { KyselyFactory } from './KyselyFactory';
|
|
2
|
-
|
|
3
|
-
interface Database {
|
|
4
|
-
users: {
|
|
5
|
-
id: number;
|
|
6
|
-
name: string;
|
|
7
|
-
email: string;
|
|
8
|
-
createdAt: Date;
|
|
9
|
-
};
|
|
10
|
-
posts: {
|
|
11
|
-
id: number;
|
|
12
|
-
title: string;
|
|
13
|
-
content: string;
|
|
14
|
-
userId: number;
|
|
15
|
-
createdAt: Date;
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const userBuilder = KyselyFactory.createBuilder<Database, 'users'>({
|
|
20
|
-
table: 'users',
|
|
21
|
-
defaults: async (attrs) => ({
|
|
22
|
-
name: 'John Doe',
|
|
23
|
-
email: `user${Date.now()}@example.com`,
|
|
24
|
-
createdAt: new Date(),
|
|
25
|
-
}),
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
const builders = {
|
|
29
|
-
user: userBuilder,
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export type Builders = typeof builders;
|
|
33
|
-
export type Seeds = Record<string, any>;
|
|
34
|
-
|
|
35
|
-
const factory = new KyselyFactory<Database, Builders, Seeds>(
|
|
36
|
-
builders,
|
|
37
|
-
{},
|
|
38
|
-
{} as any,
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
factory.insert('user', {
|
|
42
|
-
name: 'Jane Doe',
|
|
43
|
-
email: `user${Date.now()}@example.com`,
|
|
44
|
-
createdAt: new Date(),
|
|
45
|
-
});
|