@geekmidas/testkit 0.3.1 → 0.6.0
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-BFVnMMCC.mjs.map +1 -1
- package/dist/Factory-BhjUOBWN.cjs.map +1 -1
- package/dist/{Factory-BK06XuDA.d.cts → Factory-Bx0AJXZB.d.cts} +3 -2
- package/dist/Factory-Bx0AJXZB.d.cts.map +1 -0
- package/dist/{Factory-BcGJjLc8.d.mts → Factory-SFupxRC2.d.mts} +2 -1
- package/dist/Factory-SFupxRC2.d.mts.map +1 -0
- package/dist/Factory.d.cts +2 -2
- package/dist/Factory.d.mts +1 -1
- package/dist/KyselyFactory-BFqVIn_0.cjs.map +1 -1
- package/dist/KyselyFactory-DMswpwji.mjs.map +1 -1
- package/dist/{KyselyFactory-Bu9ssWZP.d.cts → KyselyFactory-KLeKH43i.d.cts} +4 -3
- package/dist/KyselyFactory-KLeKH43i.d.cts.map +1 -0
- package/dist/{KyselyFactory-Cj-EultY.d.mts → KyselyFactory-vAxYodck.d.mts} +3 -2
- package/dist/KyselyFactory-vAxYodck.d.mts.map +1 -0
- package/dist/KyselyFactory.d.cts +3 -3
- package/dist/KyselyFactory.d.mts +2 -2
- package/dist/{ObjectionFactory-DL4qkuF1.d.mts → ObjectionFactory-BWjB49-i.d.mts} +3 -2
- package/dist/ObjectionFactory-BWjB49-i.d.mts.map +1 -0
- package/dist/ObjectionFactory-BeFBYcan.cjs.map +1 -1
- package/dist/ObjectionFactory-QCJ7u0Ql.mjs.map +1 -1
- package/dist/{ObjectionFactory-tKWZOiYO.d.cts → ObjectionFactory-aMGvAKt9.d.cts} +4 -3
- package/dist/ObjectionFactory-aMGvAKt9.d.cts.map +1 -0
- package/dist/ObjectionFactory.d.cts +3 -3
- package/dist/ObjectionFactory.d.mts +2 -2
- package/dist/{PostgresKyselyMigrator-upT-hmrz.mjs → PostgresKyselyMigrator-6sE1KOni.mjs} +2 -2
- package/dist/PostgresKyselyMigrator-6sE1KOni.mjs.map +1 -0
- package/dist/{PostgresKyselyMigrator-CIx3AFSR.d.mts → PostgresKyselyMigrator-CBltSOq5.d.cts} +3 -2
- package/dist/PostgresKyselyMigrator-CBltSOq5.d.cts.map +1 -0
- package/dist/{PostgresKyselyMigrator-CfytARcA.cjs → PostgresKyselyMigrator-D6IbPq8t.cjs} +2 -2
- package/dist/PostgresKyselyMigrator-D6IbPq8t.cjs.map +1 -0
- package/dist/{PostgresKyselyMigrator-CQ3aUoy_.d.cts → PostgresKyselyMigrator-DrVWncqd.d.mts} +3 -2
- package/dist/PostgresKyselyMigrator-DrVWncqd.d.mts.map +1 -0
- package/dist/PostgresKyselyMigrator.cjs +2 -2
- package/dist/PostgresKyselyMigrator.d.cts +2 -2
- package/dist/PostgresKyselyMigrator.d.mts +2 -2
- package/dist/PostgresKyselyMigrator.mjs +2 -2
- package/dist/{PostgresMigrator-DbuJGAVy.mjs → PostgresMigrator-BjjenqSd.mjs} +2 -2
- package/dist/PostgresMigrator-BjjenqSd.mjs.map +1 -0
- package/dist/{PostgresMigrator-D5UkK1_K.d.cts → PostgresMigrator-Bres0U6E.d.cts} +2 -1
- package/dist/PostgresMigrator-Bres0U6E.d.cts.map +1 -0
- package/dist/{PostgresMigrator-DFcNdCvD.cjs → PostgresMigrator-D6dQn0x2.cjs} +2 -2
- package/dist/PostgresMigrator-D6dQn0x2.cjs.map +1 -0
- package/dist/{PostgresMigrator-DQaRxoaY.d.mts → PostgresMigrator-S-YYosAC.d.mts} +2 -1
- package/dist/PostgresMigrator-S-YYosAC.d.mts.map +1 -0
- package/dist/PostgresMigrator.cjs +1 -1
- package/dist/PostgresMigrator.d.cts +1 -1
- package/dist/PostgresMigrator.d.mts +1 -1
- package/dist/PostgresMigrator.mjs +1 -1
- package/dist/{PostgresObjectionMigrator-CZHHcCOv.d.cts → PostgresObjectionMigrator-CPfBAP7r.d.cts} +3 -2
- package/dist/PostgresObjectionMigrator-CPfBAP7r.d.cts.map +1 -0
- package/dist/{PostgresObjectionMigrator-BG6ymgnt.cjs → PostgresObjectionMigrator-DK8ODIHQ.cjs} +2 -2
- package/dist/PostgresObjectionMigrator-DK8ODIHQ.cjs.map +1 -0
- package/dist/{PostgresObjectionMigrator-D_hCcrQu.d.mts → PostgresObjectionMigrator-DVEqB5tp.d.mts} +3 -2
- package/dist/PostgresObjectionMigrator-DVEqB5tp.d.mts.map +1 -0
- package/dist/{PostgresObjectionMigrator-DPj2pOpX.mjs → PostgresObjectionMigrator-D_QxXbIN.mjs} +2 -2
- package/dist/PostgresObjectionMigrator-D_QxXbIN.mjs.map +1 -0
- package/dist/PostgresObjectionMigrator.cjs +2 -2
- package/dist/PostgresObjectionMigrator.d.cts +2 -2
- package/dist/PostgresObjectionMigrator.d.mts +2 -2
- package/dist/PostgresObjectionMigrator.mjs +2 -2
- package/dist/{VitestKyselyTransactionIsolator-D3EZZhjZ.d.cts → VitestKyselyTransactionIsolator-CduJlHoT.d.cts} +4 -3
- package/dist/VitestKyselyTransactionIsolator-CduJlHoT.d.cts.map +1 -0
- package/dist/{VitestKyselyTransactionIsolator-Dxlp1u0f.d.mts → VitestKyselyTransactionIsolator-Cswnnj0k.d.mts} +4 -3
- package/dist/VitestKyselyTransactionIsolator-Cswnnj0k.d.mts.map +1 -0
- package/dist/{VitestKyselyTransactionIsolator-EvDLk5zg.cjs → VitestKyselyTransactionIsolator-D7RRXOBa.cjs} +2 -2
- package/dist/VitestKyselyTransactionIsolator-D7RRXOBa.cjs.map +1 -0
- package/dist/{VitestKyselyTransactionIsolator-CNURW8y6.mjs → VitestKyselyTransactionIsolator-DceyIqr4.mjs} +2 -2
- package/dist/VitestKyselyTransactionIsolator-DceyIqr4.mjs.map +1 -0
- package/dist/VitestKyselyTransactionIsolator.cjs +1 -1
- package/dist/VitestKyselyTransactionIsolator.d.cts +2 -2
- package/dist/VitestKyselyTransactionIsolator.d.mts +2 -2
- package/dist/VitestKyselyTransactionIsolator.mjs +1 -1
- package/dist/{VitestObjectionTransactionIsolator-1TpsPqfG.d.cts → VitestObjectionTransactionIsolator-BXoR6xdG.d.cts} +4 -3
- package/dist/VitestObjectionTransactionIsolator-BXoR6xdG.d.cts.map +1 -0
- package/dist/{VitestObjectionTransactionIsolator-CM5KTAFA.cjs → VitestObjectionTransactionIsolator-CdLRrzNf.cjs} +2 -2
- package/dist/VitestObjectionTransactionIsolator-CdLRrzNf.cjs.map +1 -0
- package/dist/{VitestObjectionTransactionIsolator-jQFaCz0u.mjs → VitestObjectionTransactionIsolator-OF2osYY5.mjs} +2 -2
- package/dist/VitestObjectionTransactionIsolator-OF2osYY5.mjs.map +1 -0
- package/dist/{VitestObjectionTransactionIsolator-i9jIgU8Q.d.mts → VitestObjectionTransactionIsolator-x6hY5j4u.d.mts} +4 -3
- package/dist/VitestObjectionTransactionIsolator-x6hY5j4u.d.mts.map +1 -0
- package/dist/VitestObjectionTransactionIsolator.cjs +1 -1
- package/dist/VitestObjectionTransactionIsolator.d.cts +2 -2
- package/dist/VitestObjectionTransactionIsolator.d.mts +2 -2
- package/dist/VitestObjectionTransactionIsolator.mjs +1 -1
- package/dist/{VitestTransactionIsolator-BvR19bYn.d.mts → VitestTransactionIsolator-BNWJqh9f.d.mts} +3 -2
- package/dist/VitestTransactionIsolator-BNWJqh9f.d.mts.map +1 -0
- package/dist/VitestTransactionIsolator-CMfJXZP8.cjs.map +1 -1
- package/dist/{VitestTransactionIsolator-CwQaxZLP.d.cts → VitestTransactionIsolator-CSroc7Df.d.cts} +3 -2
- package/dist/VitestTransactionIsolator-CSroc7Df.d.cts.map +1 -0
- package/dist/VitestTransactionIsolator-DQ7tLqgV.mjs.map +1 -1
- package/dist/VitestTransactionIsolator.d.cts +1 -1
- package/dist/VitestTransactionIsolator.d.mts +1 -1
- package/dist/aws.cjs.map +1 -1
- package/dist/aws.d.cts +2 -0
- package/dist/aws.d.cts.map +1 -0
- package/dist/aws.d.mts +2 -0
- package/dist/aws.d.mts.map +1 -0
- package/dist/aws.mjs.map +1 -1
- package/dist/benchmark.cjs.map +1 -1
- package/dist/benchmark.d.cts +1 -0
- package/dist/benchmark.d.cts.map +1 -0
- package/dist/benchmark.d.mts +1 -0
- package/dist/benchmark.d.mts.map +1 -0
- package/dist/benchmark.mjs.map +1 -1
- package/dist/better-auth.cjs +29 -30
- package/dist/better-auth.cjs.map +1 -1
- package/dist/better-auth.d.cts +2 -2
- package/dist/better-auth.d.cts.map +1 -0
- package/dist/better-auth.d.mts.map +1 -0
- package/dist/better-auth.mjs +29 -30
- package/dist/better-auth.mjs.map +1 -1
- package/dist/directory-B-Ozljzk.mjs.map +1 -1
- package/dist/directory-BVC8g7cX.cjs.map +1 -1
- package/dist/{directory-DlkPEzL4.d.cts → directory-CVrfTq1I.d.mts} +2 -1
- package/dist/directory-CVrfTq1I.d.mts.map +1 -0
- package/dist/directory-Cys9g76X.d.cts +13 -0
- package/dist/directory-Cys9g76X.d.cts.map +1 -0
- package/dist/faker-B14IEMIN.cjs.map +1 -1
- package/dist/faker-BGKYFoCT.mjs.map +1 -1
- package/dist/{faker-Cg76aFNO.d.cts → faker-BSH1EMtg.d.cts} +3 -3
- package/dist/faker-BSH1EMtg.d.cts.map +1 -0
- package/dist/faker-DHh7xs4u.d.mts.map +1 -0
- package/dist/faker.d.cts +1 -1
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.d.cts +1 -0
- package/dist/helpers.d.cts.map +1 -0
- package/dist/helpers.d.mts +1 -0
- package/dist/helpers.d.mts.map +1 -0
- package/dist/helpers.mjs.map +1 -1
- package/dist/kysely.cjs +3 -3
- package/dist/kysely.cjs.map +1 -1
- package/dist/kysely.d.cts +8 -7
- package/dist/kysely.d.cts.map +1 -0
- package/dist/kysely.d.mts +7 -6
- package/dist/kysely.d.mts.map +1 -0
- package/dist/kysely.mjs +3 -3
- package/dist/kysely.mjs.map +1 -1
- package/dist/logger.cjs.map +1 -1
- package/dist/logger.d.cts +1 -0
- package/dist/logger.d.cts.map +1 -0
- package/dist/logger.d.mts +1 -0
- package/dist/logger.d.mts.map +1 -0
- package/dist/logger.mjs.map +1 -1
- package/dist/objection.cjs +3 -3
- package/dist/objection.cjs.map +1 -1
- package/dist/objection.d.cts +8 -7
- package/dist/objection.d.cts.map +1 -0
- package/dist/objection.d.mts +7 -6
- package/dist/objection.d.mts.map +1 -0
- package/dist/objection.mjs +3 -3
- package/dist/objection.mjs.map +1 -1
- package/dist/os/directory.d.cts +1 -1
- package/dist/os/directory.d.mts +1 -1
- package/dist/os/index.d.cts +1 -1
- package/dist/os/index.d.mts +1 -1
- package/dist/timer.cjs.map +1 -1
- package/dist/timer.d.cts +2 -0
- package/dist/timer.d.cts.map +1 -0
- package/dist/timer.d.mts +2 -0
- package/dist/timer.d.mts.map +1 -0
- package/dist/timer.mjs.map +1 -1
- package/package.json +39 -5
- package/src/Factory.ts +72 -72
- package/src/KyselyFactory.ts +330 -330
- package/src/ObjectionFactory.ts +354 -355
- package/src/PostgresKyselyMigrator.ts +37 -37
- package/src/PostgresMigrator.ts +107 -107
- package/src/PostgresObjectionMigrator.ts +91 -91
- package/src/VitestKyselyTransactionIsolator.ts +27 -27
- package/src/VitestObjectionTransactionIsolator.ts +39 -39
- package/src/VitestTransactionIsolator.ts +196 -195
- package/src/__tests__/Factory.spec.ts +163 -155
- package/src/__tests__/KyselyFactory.spec.ts +443 -439
- package/src/__tests__/ObjectionFactory.spec.ts +563 -557
- package/src/__tests__/PostgresKyselyMigrator.spec.ts +641 -641
- package/src/__tests__/PostgresMigrator.spec.ts +341 -341
- package/src/__tests__/PostgresObjectionMigrator.spec.ts +578 -578
- package/src/__tests__/VitestObjectionTransactionIsolator.spec.ts +114 -114
- package/src/__tests__/benchmark.spec.ts +140 -0
- package/src/__tests__/better-auth.spec.ts +15 -15
- package/src/__tests__/faker.spec.ts +226 -137
- package/src/__tests__/integration.spec.ts +597 -597
- package/src/__tests__/utilities.spec.ts +211 -0
- package/src/aws.ts +104 -104
- package/src/benchmark.ts +12 -12
- package/src/better-auth.ts +286 -301
- package/src/faker.ts +153 -153
- package/src/helpers.ts +6 -6
- package/src/kysely.ts +33 -33
- package/src/logger.ts +10 -10
- package/src/objection.ts +31 -31
- package/src/os/directory.ts +11 -10
- package/src/timer.ts +1 -1
- package/test/globalSetup.ts +45 -45
- package/test/helpers.ts +189 -189
- package/test/migrations/1749664623372_user.ts +13 -13
- package/tsconfig.json +9 -0
- package/vitest.config.ts +4 -4
- package/dist/PostgresKyselyMigrator-CfytARcA.cjs.map +0 -1
- package/dist/PostgresKyselyMigrator-upT-hmrz.mjs.map +0 -1
- package/dist/PostgresMigrator-DFcNdCvD.cjs.map +0 -1
- package/dist/PostgresMigrator-DbuJGAVy.mjs.map +0 -1
- package/dist/PostgresObjectionMigrator-BG6ymgnt.cjs.map +0 -1
- package/dist/PostgresObjectionMigrator-DPj2pOpX.mjs.map +0 -1
- package/dist/VitestKyselyTransactionIsolator-CNURW8y6.mjs.map +0 -1
- package/dist/VitestKyselyTransactionIsolator-EvDLk5zg.cjs.map +0 -1
- package/dist/VitestObjectionTransactionIsolator-CM5KTAFA.cjs.map +0 -1
- package/dist/VitestObjectionTransactionIsolator-jQFaCz0u.mjs.map +0 -1
- package/dist/directory-BPf1LgNX.d.mts +0 -12
|
@@ -2,141 +2,230 @@ import { beforeEach, describe, expect, it } from 'vitest';
|
|
|
2
2
|
import { faker } from '../faker';
|
|
3
3
|
|
|
4
4
|
describe('faker', () => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
5
|
+
describe('sequence', () => {
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
faker.resetAllSequences();
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it('should start from 1 for a new sequence', () => {
|
|
11
|
+
expect(faker.sequence()).toBe(1);
|
|
12
|
+
expect(faker.sequence('custom')).toBe(1);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('should increment on each call', () => {
|
|
16
|
+
expect(faker.sequence()).toBe(1);
|
|
17
|
+
expect(faker.sequence()).toBe(2);
|
|
18
|
+
expect(faker.sequence()).toBe(3);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('should maintain separate counters for different names', () => {
|
|
22
|
+
expect(faker.sequence('users')).toBe(1);
|
|
23
|
+
expect(faker.sequence('posts')).toBe(1);
|
|
24
|
+
expect(faker.sequence('users')).toBe(2);
|
|
25
|
+
expect(faker.sequence('posts')).toBe(2);
|
|
26
|
+
expect(faker.sequence('users')).toBe(3);
|
|
27
|
+
expect(faker.sequence('posts')).toBe(3);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should handle concurrent-like sequential calls', () => {
|
|
31
|
+
const results: number[] = [];
|
|
32
|
+
for (let i = 0; i < 100; i++) {
|
|
33
|
+
results.push(faker.sequence('concurrent'));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Check that all values are unique and sequential
|
|
37
|
+
expect(results).toEqual(Array.from({ length: 100 }, (_, i) => i + 1));
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
describe('resetSequence', () => {
|
|
42
|
+
beforeEach(() => {
|
|
43
|
+
faker.resetAllSequences();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('should reset a specific sequence to 0', () => {
|
|
47
|
+
faker.sequence('test');
|
|
48
|
+
faker.sequence('test');
|
|
49
|
+
expect(faker.sequence('test')).toBe(3);
|
|
50
|
+
|
|
51
|
+
faker.resetSequence('test');
|
|
52
|
+
expect(faker.sequence('test')).toBe(1);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('should reset a specific sequence to a custom value', () => {
|
|
56
|
+
faker.sequence('test');
|
|
57
|
+
faker.resetSequence('test', 10);
|
|
58
|
+
expect(faker.sequence('test')).toBe(11);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('should create a new sequence if it does not exist', () => {
|
|
62
|
+
faker.resetSequence('new', 5);
|
|
63
|
+
expect(faker.sequence('new')).toBe(6);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('should not affect other sequences', () => {
|
|
67
|
+
faker.sequence('test1');
|
|
68
|
+
faker.sequence('test1');
|
|
69
|
+
faker.sequence('test2');
|
|
70
|
+
|
|
71
|
+
faker.resetSequence('test1');
|
|
72
|
+
|
|
73
|
+
expect(faker.sequence('test1')).toBe(1);
|
|
74
|
+
expect(faker.sequence('test2')).toBe(2);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe('resetAllSequences', () => {
|
|
79
|
+
it('should reset all sequences', () => {
|
|
80
|
+
faker.sequence('test1');
|
|
81
|
+
faker.sequence('test1');
|
|
82
|
+
faker.sequence('test2');
|
|
83
|
+
faker.sequence('test2');
|
|
84
|
+
faker.sequence('test2');
|
|
85
|
+
|
|
86
|
+
faker.resetAllSequences();
|
|
87
|
+
|
|
88
|
+
expect(faker.sequence('test1')).toBe(1);
|
|
89
|
+
expect(faker.sequence('test2')).toBe(1);
|
|
90
|
+
expect(faker.sequence()).toBe(1);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe('identifier', () => {
|
|
95
|
+
beforeEach(() => {
|
|
96
|
+
faker.resetAllSequences();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('should include sequence number in identifier', () => {
|
|
100
|
+
const id1 = faker.identifier();
|
|
101
|
+
const id2 = faker.identifier();
|
|
102
|
+
|
|
103
|
+
// Both should be different because of the sequence
|
|
104
|
+
expect(id1).not.toBe(id2);
|
|
105
|
+
|
|
106
|
+
// Should end with sequence numbers
|
|
107
|
+
expect(id1).toMatch(/1$/);
|
|
108
|
+
expect(id2).toMatch(/2$/);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('should use custom suffix when provided', () => {
|
|
112
|
+
const id = faker.identifier('customSuffix');
|
|
113
|
+
expect(id).toMatch(/\.customSuffix$/);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
describe('timestamps', () => {
|
|
118
|
+
it('should return createdAt and updatedAt dates', () => {
|
|
119
|
+
const { createdAt, updatedAt } = faker.timestamps();
|
|
120
|
+
|
|
121
|
+
expect(createdAt).toBeInstanceOf(Date);
|
|
122
|
+
expect(updatedAt).toBeInstanceOf(Date);
|
|
123
|
+
expect(createdAt.getTime()).toBeLessThanOrEqual(updatedAt.getTime());
|
|
124
|
+
expect(updatedAt.getTime()).toBeLessThanOrEqual(Date.now());
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('should have milliseconds set to 0', () => {
|
|
128
|
+
const { createdAt, updatedAt } = faker.timestamps();
|
|
129
|
+
|
|
130
|
+
expect(createdAt.getMilliseconds()).toBe(0);
|
|
131
|
+
expect(updatedAt.getMilliseconds()).toBe(0);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
describe('price', () => {
|
|
136
|
+
it('should return a number', () => {
|
|
137
|
+
const result = faker.price();
|
|
138
|
+
expect(typeof result).toBe('number');
|
|
139
|
+
expect(result).toBeGreaterThan(0);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
describe('coordinates', () => {
|
|
144
|
+
const center = { lat: 40.7128, lng: -74.006 }; // New York City
|
|
145
|
+
|
|
146
|
+
describe('within', () => {
|
|
147
|
+
it('should generate a coordinate within the given radius', () => {
|
|
148
|
+
const radius = 1000; // 1km
|
|
149
|
+
const result = faker.coordinates.within(center, radius);
|
|
150
|
+
|
|
151
|
+
expect(result).toHaveProperty('lat');
|
|
152
|
+
expect(result).toHaveProperty('lng');
|
|
153
|
+
expect(typeof result.lat).toBe('number');
|
|
154
|
+
expect(typeof result.lng).toBe('number');
|
|
155
|
+
|
|
156
|
+
// Calculate distance using Haversine formula
|
|
157
|
+
const R = 6378137; // Earth's radius in meters
|
|
158
|
+
const dLat = ((result.lat - center.lat) * Math.PI) / 180;
|
|
159
|
+
const dLng = ((result.lng - center.lng) * Math.PI) / 180;
|
|
160
|
+
const a =
|
|
161
|
+
Math.sin(dLat / 2) * Math.sin(dLat / 2) +
|
|
162
|
+
Math.cos((center.lat * Math.PI) / 180) *
|
|
163
|
+
Math.cos((result.lat * Math.PI) / 180) *
|
|
164
|
+
Math.sin(dLng / 2) *
|
|
165
|
+
Math.sin(dLng / 2);
|
|
166
|
+
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
|
167
|
+
const distance = R * c;
|
|
168
|
+
|
|
169
|
+
expect(distance).toBeLessThanOrEqual(radius);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('should generate different coordinates on multiple calls', () => {
|
|
173
|
+
const radius = 1000;
|
|
174
|
+
const results = Array.from({ length: 10 }, () =>
|
|
175
|
+
faker.coordinates.within(center, radius),
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
// Not all results should be identical
|
|
179
|
+
const uniqueLats = new Set(results.map((r) => r.lat));
|
|
180
|
+
expect(uniqueLats.size).toBeGreaterThan(1);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
describe('outside', () => {
|
|
185
|
+
it('should generate a coordinate outside the minimum radius', () => {
|
|
186
|
+
const minRadius = 1000; // 1km
|
|
187
|
+
const maxRadius = 5000; // 5km
|
|
188
|
+
const result = faker.coordinates.outside(center, minRadius, maxRadius);
|
|
189
|
+
|
|
190
|
+
expect(result).toHaveProperty('lat');
|
|
191
|
+
expect(result).toHaveProperty('lng');
|
|
192
|
+
expect(typeof result.lat).toBe('number');
|
|
193
|
+
expect(typeof result.lng).toBe('number');
|
|
194
|
+
|
|
195
|
+
// Calculate distance using Haversine formula
|
|
196
|
+
const R = 6378137;
|
|
197
|
+
const dLat = ((result.lat - center.lat) * Math.PI) / 180;
|
|
198
|
+
const dLng = ((result.lng - center.lng) * Math.PI) / 180;
|
|
199
|
+
const a =
|
|
200
|
+
Math.sin(dLat / 2) * Math.sin(dLat / 2) +
|
|
201
|
+
Math.cos((center.lat * Math.PI) / 180) *
|
|
202
|
+
Math.cos((result.lat * Math.PI) / 180) *
|
|
203
|
+
Math.sin(dLng / 2) *
|
|
204
|
+
Math.sin(dLng / 2);
|
|
205
|
+
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
|
206
|
+
const distance = R * c;
|
|
207
|
+
|
|
208
|
+
expect(distance).toBeGreaterThanOrEqual(minRadius);
|
|
209
|
+
expect(distance).toBeLessThanOrEqual(maxRadius);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('should generate different coordinates on multiple calls', () => {
|
|
213
|
+
const results = Array.from({ length: 10 }, () =>
|
|
214
|
+
faker.coordinates.outside(center, 1000, 5000),
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
const uniqueLats = new Set(results.map((r) => r.lat));
|
|
218
|
+
expect(uniqueLats.size).toBeGreaterThan(1);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it('should normalize longitude to valid range', () => {
|
|
222
|
+
// Use a center near the antimeridian
|
|
223
|
+
const pacificCenter = { lat: 0, lng: 179 };
|
|
224
|
+
const result = faker.coordinates.outside(pacificCenter, 100000, 500000);
|
|
225
|
+
|
|
226
|
+
expect(result.lng).toBeGreaterThanOrEqual(-180);
|
|
227
|
+
expect(result.lng).toBeLessThanOrEqual(180);
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
});
|
|
142
231
|
});
|