@geekmidas/testkit 0.0.4 → 0.0.6
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-D-qpeVKO.mjs} +1 -1
- package/dist/{VitestKyselyTransactionIsolator-Dh2AgJDd.cjs → VitestKyselyTransactionIsolator-jF6Ohyu_.cjs} +1 -1
- package/dist/VitestKyselyTransactionIsolator.cjs +2 -3
- package/dist/VitestKyselyTransactionIsolator.mjs +2 -3
- package/dist/{VitestTransactionIsolator-zK5NJ7DQ.cjs → VitestTransactionIsolator-BK9UsrKt.cjs} +4 -2
- package/dist/{VitestTransactionIsolator-pLwsDo_A.mjs → VitestTransactionIsolator-e-R3p_X8.mjs} +4 -3
- 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 +80 -80
- package/dist/__tests__/KyselyFactory.spec.mjs +74 -74
- 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 +44 -41
- package/dist/__tests__/integration.spec.mjs +45 -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-C2NH7xcz.cjs → helpers-B2CfbaTC.cjs} +1 -1
- package/dist/helpers-DN4sJO4i.mjs +13 -0
- package/dist/helpers-DOtYCEvZ.cjs +19 -0
- package/dist/helpers.cjs +2 -6
- package/dist/helpers.mjs +2 -5
- package/dist/kysely-C1-aHdnU.mjs +11 -0
- package/dist/kysely-DL3C2eM4.cjs +16 -0
- package/dist/kysely.cjs +8 -15
- package/dist/kysely.mjs +8 -15
- package/dist/objection.mjs +2 -2
- package/package.json +2 -1
- package/src/VitestTransactionIsolator.ts +4 -2
- package/src/__tests__/KyselyFactory.spec.ts +4 -6
- package/src/__tests__/integration.spec.ts +8 -3
- package/src/helpers.ts +1 -18
- package/src/kysely.ts +3 -1
- package/dist/dist-BM2KvLG1.mjs +0 -5618
- package/dist/dist-DE3gAxQI.cjs +0 -5736
- package/dist/helpers-BnARb5Ap.mjs +0 -19
- package/dist/helpers-C_RZk04R.cjs +0 -31
- 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-Rf5F71r9.mjs} +0 -0
package/dist/Factory.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Factory } from "./Factory-
|
|
2
|
-
import { faker } from "./faker-
|
|
1
|
+
import { Factory } from "./Factory-DlzMkMzb.mjs";
|
|
2
|
+
import { faker } from "./faker-BwaXA_RF.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/KyselyFactory.ts
|
|
5
5
|
var KyselyFactory = class extends Factory {
|
package/dist/KyselyFactory.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
require('./Factory-DREHoms3.cjs');
|
|
2
|
-
require('./faker-
|
|
3
|
-
const require_KyselyFactory = require('./KyselyFactory-
|
|
2
|
+
require('./faker-caz-8zt8.cjs');
|
|
3
|
+
const require_KyselyFactory = require('./KyselyFactory-BX7Kv2uP.cjs');
|
|
4
4
|
|
|
5
5
|
exports.KyselyFactory = require_KyselyFactory.KyselyFactory;
|
package/dist/KyselyFactory.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "./Factory-
|
|
2
|
-
import "./faker-
|
|
3
|
-
import { KyselyFactory } from "./KyselyFactory-
|
|
1
|
+
import "./Factory-DlzMkMzb.mjs";
|
|
2
|
+
import "./faker-BwaXA_RF.mjs";
|
|
3
|
+
import { KyselyFactory } from "./KyselyFactory-pOMOFQWE.mjs";
|
|
4
4
|
|
|
5
5
|
export { KyselyFactory };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const require_chunk = require('./chunk-
|
|
2
|
-
const require_PostgresMigrator = require('./PostgresMigrator-
|
|
1
|
+
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
+
const require_PostgresMigrator = require('./PostgresMigrator-Bz-tnjB6.cjs');
|
|
3
3
|
const kysely = require_chunk.__toESM(require("kysely"));
|
|
4
4
|
|
|
5
5
|
//#region src/PostgresKyselyMigrator.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require('./PostgresMigrator-
|
|
2
|
-
const require_PostgresKyselyMigrator = require('./PostgresKyselyMigrator-
|
|
1
|
+
require('./PostgresMigrator-Bz-tnjB6.cjs');
|
|
2
|
+
const require_PostgresKyselyMigrator = require('./PostgresKyselyMigrator-JTY2LfwD.cjs');
|
|
3
3
|
|
|
4
4
|
exports.PostgresKyselyMigrator = require_PostgresKyselyMigrator.PostgresKyselyMigrator;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./PostgresMigrator-
|
|
2
|
-
import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-
|
|
1
|
+
import "./PostgresMigrator-CEoRKTdq.mjs";
|
|
2
|
+
import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-D8fm35-s.mjs";
|
|
3
3
|
|
|
4
4
|
export { PostgresKyselyMigrator };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-
|
|
1
|
+
import { VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-e-R3p_X8.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/VitestKyselyTransactionIsolator.ts
|
|
4
4
|
var VitestKyselyTransactionIsolator = class extends VitestPostgresTransactionIsolator {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-
|
|
1
|
+
const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-BK9UsrKt.cjs');
|
|
2
2
|
|
|
3
3
|
//#region src/VitestKyselyTransactionIsolator.ts
|
|
4
4
|
var VitestKyselyTransactionIsolator = class extends require_VitestTransactionIsolator.VitestPostgresTransactionIsolator {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
require('./
|
|
2
|
-
require('./
|
|
3
|
-
const require_VitestKyselyTransactionIsolator = require('./VitestKyselyTransactionIsolator-Dh2AgJDd.cjs');
|
|
1
|
+
require('./VitestTransactionIsolator-BK9UsrKt.cjs');
|
|
2
|
+
const require_VitestKyselyTransactionIsolator = require('./VitestKyselyTransactionIsolator-jF6Ohyu_.cjs');
|
|
4
3
|
|
|
5
4
|
exports.VitestKyselyTransactionIsolator = require_VitestKyselyTransactionIsolator.VitestKyselyTransactionIsolator;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import "./
|
|
3
|
-
import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-DXjWQtDN.mjs";
|
|
1
|
+
import "./VitestTransactionIsolator-e-R3p_X8.mjs";
|
|
2
|
+
import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-D-qpeVKO.mjs";
|
|
4
3
|
|
|
5
4
|
export { VitestKyselyTransactionIsolator };
|
package/dist/{VitestTransactionIsolator-zK5NJ7DQ.cjs → VitestTransactionIsolator-BK9UsrKt.cjs}
RENAMED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
const require_dist = require('./dist-DE3gAxQI.cjs');
|
|
2
1
|
|
|
3
2
|
//#region src/VitestTransactionIsolator.ts
|
|
4
3
|
let IsolationLevel = /* @__PURE__ */ function(IsolationLevel$1) {
|
|
@@ -9,8 +8,11 @@ let IsolationLevel = /* @__PURE__ */ function(IsolationLevel$1) {
|
|
|
9
8
|
return IsolationLevel$1;
|
|
10
9
|
}({});
|
|
11
10
|
var VitestPostgresTransactionIsolator = class {
|
|
11
|
+
constructor(api) {
|
|
12
|
+
this.api = api;
|
|
13
|
+
}
|
|
12
14
|
wrapVitestWithTransaction(conn, setup, level = IsolationLevel.REPEATABLE_READ) {
|
|
13
|
-
return
|
|
15
|
+
return this.api.extend({ trx: async ({}, use) => {
|
|
14
16
|
class TestRollback extends Error {
|
|
15
17
|
constructor() {
|
|
16
18
|
super("Test rollback");
|
package/dist/{VitestTransactionIsolator-pLwsDo_A.mjs → VitestTransactionIsolator-e-R3p_X8.mjs}
RENAMED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { test } from "./dist-BM2KvLG1.mjs";
|
|
2
|
-
|
|
3
1
|
//#region src/VitestTransactionIsolator.ts
|
|
4
2
|
let IsolationLevel = /* @__PURE__ */ function(IsolationLevel$1) {
|
|
5
3
|
IsolationLevel$1["READ_UNCOMMITTED"] = "READ UNCOMMITTED";
|
|
@@ -9,8 +7,11 @@ let IsolationLevel = /* @__PURE__ */ function(IsolationLevel$1) {
|
|
|
9
7
|
return IsolationLevel$1;
|
|
10
8
|
}({});
|
|
11
9
|
var VitestPostgresTransactionIsolator = class {
|
|
10
|
+
constructor(api) {
|
|
11
|
+
this.api = api;
|
|
12
|
+
}
|
|
12
13
|
wrapVitestWithTransaction(conn, setup, level = IsolationLevel.REPEATABLE_READ) {
|
|
13
|
-
return
|
|
14
|
+
return this.api.extend({ trx: async ({}, use) => {
|
|
14
15
|
class TestRollback extends Error {
|
|
15
16
|
constructor() {
|
|
16
17
|
super("Test rollback");
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
require('./
|
|
2
|
-
const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-zK5NJ7DQ.cjs');
|
|
1
|
+
const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-BK9UsrKt.cjs');
|
|
3
2
|
|
|
4
3
|
exports.IsolationLevel = require_VitestTransactionIsolator.IsolationLevel;
|
|
5
4
|
exports.VitestPostgresTransactionIsolator = require_VitestTransactionIsolator.VitestPostgresTransactionIsolator;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import { IsolationLevel, VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-pLwsDo_A.mjs";
|
|
1
|
+
import { IsolationLevel, VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-e-R3p_X8.mjs";
|
|
3
2
|
|
|
4
3
|
export { IsolationLevel, VitestPostgresTransactionIsolator };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
const require_chunk = require('../chunk-CUT6urMc.cjs');
|
|
1
2
|
const require_Factory = require('../Factory-DREHoms3.cjs');
|
|
2
|
-
const
|
|
3
|
-
const require_vi_bdSIJ99Y = require('../vi.bdSIJ99Y-CFuzUeY6.cjs');
|
|
3
|
+
const vitest = require_chunk.__toESM(require("vitest"));
|
|
4
4
|
|
|
5
5
|
//#region src/__tests__/Factory.spec.ts
|
|
6
6
|
var TestFactory = class extends require_Factory.Factory {
|
|
@@ -25,22 +25,22 @@ var TestFactory = class extends require_Factory.Factory {
|
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
(0, vitest.describe)("Factory", () => {
|
|
29
|
+
(0, vitest.describe)("abstract class functionality", () => {
|
|
30
|
+
(0, vitest.it)("should be instantiable through concrete implementation", () => {
|
|
31
31
|
const factory = new TestFactory();
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
(0, vitest.expect)(factory).toBeInstanceOf(require_Factory.Factory);
|
|
33
|
+
(0, vitest.expect)(factory).toBeInstanceOf(TestFactory);
|
|
34
34
|
});
|
|
35
|
-
|
|
35
|
+
(0, vitest.it)("should have abstract methods defined", () => {
|
|
36
36
|
const factory = new TestFactory();
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
(0, vitest.expect)(typeof factory.insert).toBe("function");
|
|
38
|
+
(0, vitest.expect)(typeof factory.insertMany).toBe("function");
|
|
39
|
+
(0, vitest.expect)(typeof factory.seed).toBe("function");
|
|
40
40
|
});
|
|
41
41
|
});
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
(0, vitest.describe)("createSeed static method", () => {
|
|
43
|
+
(0, vitest.it)("should return the seed function unchanged", () => {
|
|
44
44
|
const seedFn = async (attrs, factory, db) => {
|
|
45
45
|
return {
|
|
46
46
|
id: 1,
|
|
@@ -48,10 +48,10 @@ require_dist.describe("Factory", () => {
|
|
|
48
48
|
};
|
|
49
49
|
};
|
|
50
50
|
const result = require_Factory.Factory.createSeed(seedFn);
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
(0, vitest.expect)(result).toBe(seedFn);
|
|
52
|
+
(0, vitest.expect)(typeof result).toBe("function");
|
|
53
53
|
});
|
|
54
|
-
|
|
54
|
+
(0, vitest.it)("should work with different seed function signatures", () => {
|
|
55
55
|
const simpleSeed = () => Promise.resolve({ simple: true });
|
|
56
56
|
const complexSeed = async (attrs, factory, db) => {
|
|
57
57
|
return {
|
|
@@ -61,78 +61,78 @@ require_dist.describe("Factory", () => {
|
|
|
61
61
|
};
|
|
62
62
|
const result1 = require_Factory.Factory.createSeed(simpleSeed);
|
|
63
63
|
const result2 = require_Factory.Factory.createSeed(complexSeed);
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
(0, vitest.expect)(result1).toBe(simpleSeed);
|
|
65
|
+
(0, vitest.expect)(result2).toBe(complexSeed);
|
|
66
66
|
});
|
|
67
67
|
});
|
|
68
|
-
|
|
68
|
+
(0, vitest.describe)("concrete implementation behavior", () => {
|
|
69
69
|
let factory;
|
|
70
|
-
|
|
70
|
+
(0, vitest.beforeEach)(() => {
|
|
71
71
|
factory = new TestFactory();
|
|
72
72
|
});
|
|
73
|
-
|
|
73
|
+
(0, vitest.it)("should implement insert method", async () => {
|
|
74
74
|
const result = await factory.insert("testBuilder", { name: "test" });
|
|
75
|
-
|
|
75
|
+
(0, vitest.expect)(result).toEqual({
|
|
76
76
|
id: 1,
|
|
77
77
|
name: "test"
|
|
78
78
|
});
|
|
79
79
|
});
|
|
80
|
-
|
|
80
|
+
(0, vitest.it)("should implement insertMany method", async () => {
|
|
81
81
|
const results = await factory.insertMany(3, "testBuilder", { name: "test" });
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
(0, vitest.expect)(results).toHaveLength(3);
|
|
83
|
+
(0, vitest.expect)(results[0]).toEqual({
|
|
84
84
|
id: 1,
|
|
85
85
|
name: "test"
|
|
86
86
|
});
|
|
87
87
|
});
|
|
88
|
-
|
|
88
|
+
(0, vitest.it)("should implement insertMany with function attributes", async () => {
|
|
89
89
|
const results = await factory.insertMany(2, "testBuilder", (idx) => ({ name: `test${idx}` }));
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
(0, vitest.expect)(results).toHaveLength(2);
|
|
91
|
+
(0, vitest.expect)(results[0]).toEqual({
|
|
92
92
|
id: 1,
|
|
93
93
|
name: "test0"
|
|
94
94
|
});
|
|
95
|
-
|
|
95
|
+
(0, vitest.expect)(results[1]).toEqual({
|
|
96
96
|
id: 1,
|
|
97
97
|
name: "test1"
|
|
98
98
|
});
|
|
99
99
|
});
|
|
100
|
-
|
|
100
|
+
(0, vitest.it)("should implement seed method", async () => {
|
|
101
101
|
const result = await factory.seed("testSeed", { custom: "value" });
|
|
102
|
-
|
|
102
|
+
(0, vitest.expect)(result).toEqual({
|
|
103
103
|
seedResult: true,
|
|
104
104
|
custom: "value"
|
|
105
105
|
});
|
|
106
106
|
});
|
|
107
107
|
});
|
|
108
|
-
|
|
109
|
-
|
|
108
|
+
(0, vitest.describe)("type definitions", () => {
|
|
109
|
+
(0, vitest.it)("should properly type MixedFactoryBuilder", () => {
|
|
110
110
|
const syncBuilder = (attrs, factory, db) => ({ sync: true });
|
|
111
111
|
const asyncBuilder = async (attrs, factory, db) => ({ async: true });
|
|
112
|
-
|
|
113
|
-
|
|
112
|
+
(0, vitest.expect)(typeof syncBuilder).toBe("function");
|
|
113
|
+
(0, vitest.expect)(typeof asyncBuilder).toBe("function");
|
|
114
114
|
});
|
|
115
|
-
|
|
115
|
+
(0, vitest.it)("should properly type FactorySeed", () => {
|
|
116
116
|
const seed = async (attrs, factory, db) => ({ seeded: true });
|
|
117
|
-
|
|
117
|
+
(0, vitest.expect)(typeof seed).toBe("function");
|
|
118
118
|
});
|
|
119
119
|
});
|
|
120
120
|
});
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
(0, vitest.describe)("Factory types", () => {
|
|
122
|
+
(0, vitest.it)("should export MixedFactoryBuilder type", () => {
|
|
123
123
|
const builder = (attrs, factory, db) => {
|
|
124
124
|
return {
|
|
125
125
|
id: 1,
|
|
126
126
|
name: attrs.name
|
|
127
127
|
};
|
|
128
128
|
};
|
|
129
|
-
|
|
129
|
+
(0, vitest.expect)(typeof builder).toBe("function");
|
|
130
130
|
});
|
|
131
|
-
|
|
131
|
+
(0, vitest.it)("should export FactorySeed type", () => {
|
|
132
132
|
const seed = async (attrs, factory, db) => {
|
|
133
133
|
return { created: attrs.count };
|
|
134
134
|
};
|
|
135
|
-
|
|
135
|
+
(0, vitest.expect)(typeof seed).toBe("function");
|
|
136
136
|
});
|
|
137
137
|
});
|
|
138
138
|
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { globalExpect } from "../vi.bdSIJ99Y-BgRxGeO2.mjs";
|
|
1
|
+
import { Factory } from "../Factory-DlzMkMzb.mjs";
|
|
2
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
4
3
|
|
|
5
4
|
//#region src/__tests__/Factory.spec.ts
|
|
6
5
|
var TestFactory = class extends Factory {
|
|
@@ -29,14 +28,14 @@ describe("Factory", () => {
|
|
|
29
28
|
describe("abstract class functionality", () => {
|
|
30
29
|
it("should be instantiable through concrete implementation", () => {
|
|
31
30
|
const factory = new TestFactory();
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
expect(factory).toBeInstanceOf(Factory);
|
|
32
|
+
expect(factory).toBeInstanceOf(TestFactory);
|
|
34
33
|
});
|
|
35
34
|
it("should have abstract methods defined", () => {
|
|
36
35
|
const factory = new TestFactory();
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
expect(typeof factory.insert).toBe("function");
|
|
37
|
+
expect(typeof factory.insertMany).toBe("function");
|
|
38
|
+
expect(typeof factory.seed).toBe("function");
|
|
40
39
|
});
|
|
41
40
|
});
|
|
42
41
|
describe("createSeed static method", () => {
|
|
@@ -48,8 +47,8 @@ describe("Factory", () => {
|
|
|
48
47
|
};
|
|
49
48
|
};
|
|
50
49
|
const result = Factory.createSeed(seedFn);
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
expect(result).toBe(seedFn);
|
|
51
|
+
expect(typeof result).toBe("function");
|
|
53
52
|
});
|
|
54
53
|
it("should work with different seed function signatures", () => {
|
|
55
54
|
const simpleSeed = () => Promise.resolve({ simple: true });
|
|
@@ -61,8 +60,8 @@ describe("Factory", () => {
|
|
|
61
60
|
};
|
|
62
61
|
const result1 = Factory.createSeed(simpleSeed);
|
|
63
62
|
const result2 = Factory.createSeed(complexSeed);
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
expect(result1).toBe(simpleSeed);
|
|
64
|
+
expect(result2).toBe(complexSeed);
|
|
66
65
|
});
|
|
67
66
|
});
|
|
68
67
|
describe("concrete implementation behavior", () => {
|
|
@@ -72,34 +71,34 @@ describe("Factory", () => {
|
|
|
72
71
|
});
|
|
73
72
|
it("should implement insert method", async () => {
|
|
74
73
|
const result = await factory.insert("testBuilder", { name: "test" });
|
|
75
|
-
|
|
74
|
+
expect(result).toEqual({
|
|
76
75
|
id: 1,
|
|
77
76
|
name: "test"
|
|
78
77
|
});
|
|
79
78
|
});
|
|
80
79
|
it("should implement insertMany method", async () => {
|
|
81
80
|
const results = await factory.insertMany(3, "testBuilder", { name: "test" });
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
expect(results).toHaveLength(3);
|
|
82
|
+
expect(results[0]).toEqual({
|
|
84
83
|
id: 1,
|
|
85
84
|
name: "test"
|
|
86
85
|
});
|
|
87
86
|
});
|
|
88
87
|
it("should implement insertMany with function attributes", async () => {
|
|
89
88
|
const results = await factory.insertMany(2, "testBuilder", (idx) => ({ name: `test${idx}` }));
|
|
90
|
-
|
|
91
|
-
|
|
89
|
+
expect(results).toHaveLength(2);
|
|
90
|
+
expect(results[0]).toEqual({
|
|
92
91
|
id: 1,
|
|
93
92
|
name: "test0"
|
|
94
93
|
});
|
|
95
|
-
|
|
94
|
+
expect(results[1]).toEqual({
|
|
96
95
|
id: 1,
|
|
97
96
|
name: "test1"
|
|
98
97
|
});
|
|
99
98
|
});
|
|
100
99
|
it("should implement seed method", async () => {
|
|
101
100
|
const result = await factory.seed("testSeed", { custom: "value" });
|
|
102
|
-
|
|
101
|
+
expect(result).toEqual({
|
|
103
102
|
seedResult: true,
|
|
104
103
|
custom: "value"
|
|
105
104
|
});
|
|
@@ -109,12 +108,12 @@ describe("Factory", () => {
|
|
|
109
108
|
it("should properly type MixedFactoryBuilder", () => {
|
|
110
109
|
const syncBuilder = (attrs, factory, db) => ({ sync: true });
|
|
111
110
|
const asyncBuilder = async (attrs, factory, db) => ({ async: true });
|
|
112
|
-
|
|
113
|
-
|
|
111
|
+
expect(typeof syncBuilder).toBe("function");
|
|
112
|
+
expect(typeof asyncBuilder).toBe("function");
|
|
114
113
|
});
|
|
115
114
|
it("should properly type FactorySeed", () => {
|
|
116
115
|
const seed = async (attrs, factory, db) => ({ seeded: true });
|
|
117
|
-
|
|
116
|
+
expect(typeof seed).toBe("function");
|
|
118
117
|
});
|
|
119
118
|
});
|
|
120
119
|
});
|
|
@@ -126,13 +125,13 @@ describe("Factory types", () => {
|
|
|
126
125
|
name: attrs.name
|
|
127
126
|
};
|
|
128
127
|
};
|
|
129
|
-
|
|
128
|
+
expect(typeof builder).toBe("function");
|
|
130
129
|
});
|
|
131
130
|
it("should export FactorySeed type", () => {
|
|
132
131
|
const seed = async (attrs, factory, db) => {
|
|
133
132
|
return { created: attrs.count };
|
|
134
133
|
};
|
|
135
|
-
|
|
134
|
+
expect(typeof seed).toBe("function");
|
|
136
135
|
});
|
|
137
136
|
});
|
|
138
137
|
|