@geekmidas/testkit 0.0.14 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/dist/{Factory-D7P3bKKb.d.mts → Factory-BZ8uMoXl.d.cts} +3 -2
  2. package/dist/{Factory-pNV7ZQ7-.d.cts → Factory-Cmr3s3-s.d.mts} +3 -2
  3. package/dist/Factory-WMhTNZ9S.cjs +2 -1
  4. package/dist/Factory-WMhTNZ9S.cjs.map +1 -0
  5. package/dist/Factory-z2m01hMj.mjs +2 -1
  6. package/dist/Factory-z2m01hMj.mjs.map +1 -0
  7. package/dist/Factory.d.cts +2 -2
  8. package/dist/Factory.d.mts +2 -2
  9. package/dist/KyselyFactory-BcYkC0t2.mjs +2 -1
  10. package/dist/KyselyFactory-BcYkC0t2.mjs.map +1 -0
  11. package/dist/KyselyFactory-Cf0o2YxO.cjs +2 -1
  12. package/dist/KyselyFactory-Cf0o2YxO.cjs.map +1 -0
  13. package/dist/{KyselyFactory-72P98y5I.d.mts → KyselyFactory-Cx3sezwH.d.mts} +4 -3
  14. package/dist/{KyselyFactory-DLBrYWxU.d.cts → KyselyFactory-DRQ83r0o.d.cts} +4 -3
  15. package/dist/KyselyFactory.d.cts +3 -3
  16. package/dist/KyselyFactory.d.mts +3 -3
  17. package/dist/ObjectionFactory-8hebmnai.mjs +2 -1
  18. package/dist/ObjectionFactory-8hebmnai.mjs.map +1 -0
  19. package/dist/{ObjectionFactory-B40NQWSe.d.mts → ObjectionFactory-C-59Hjwj.d.mts} +4 -3
  20. package/dist/{ObjectionFactory-D3l1VuyX.d.cts → ObjectionFactory-C4X78k0B.d.cts} +4 -3
  21. package/dist/ObjectionFactory-CDriunkS.cjs +2 -1
  22. package/dist/ObjectionFactory-CDriunkS.cjs.map +1 -0
  23. package/dist/ObjectionFactory.d.cts +3 -3
  24. package/dist/ObjectionFactory.d.mts +3 -3
  25. package/dist/{PostgresKyselyMigrator-_6yHZigp.d.mts → PostgresKyselyMigrator-CIx3AFSR.d.mts} +3 -2
  26. package/dist/PostgresKyselyMigrator-CQ3aUoy_.d.cts +2 -1
  27. package/dist/PostgresKyselyMigrator-CfytARcA.cjs +2 -1
  28. package/dist/PostgresKyselyMigrator-CfytARcA.cjs.map +1 -0
  29. package/dist/{PostgresKyselyMigrator-Bdhl251C.mjs → PostgresKyselyMigrator-upT-hmrz.mjs} +3 -2
  30. package/dist/PostgresKyselyMigrator-upT-hmrz.mjs.map +1 -0
  31. package/dist/PostgresKyselyMigrator.d.mts +2 -2
  32. package/dist/PostgresKyselyMigrator.mjs +2 -2
  33. package/dist/PostgresMigrator-D5UkK1_K.d.cts +2 -1
  34. package/dist/PostgresMigrator-DFcNdCvD.cjs +2 -1
  35. package/dist/PostgresMigrator-DFcNdCvD.cjs.map +1 -0
  36. package/dist/{PostgresMigrator-BlvuQl7d.d.mts → PostgresMigrator-DQaRxoaY.d.mts} +2 -1
  37. package/dist/{PostgresMigrator-DxPC_gGu.mjs → PostgresMigrator-DbuJGAVy.mjs} +4 -3
  38. package/dist/PostgresMigrator-DbuJGAVy.mjs.map +1 -0
  39. package/dist/PostgresMigrator.d.mts +1 -1
  40. package/dist/PostgresMigrator.mjs +1 -1
  41. package/dist/PostgresObjectionMigrator-BG6ymgnt.cjs +2 -1
  42. package/dist/PostgresObjectionMigrator-BG6ymgnt.cjs.map +1 -0
  43. package/dist/PostgresObjectionMigrator-CZHHcCOv.d.cts +2 -1
  44. package/dist/{PostgresObjectionMigrator-G4h5FLvU.mjs → PostgresObjectionMigrator-DPj2pOpX.mjs} +3 -2
  45. package/dist/PostgresObjectionMigrator-DPj2pOpX.mjs.map +1 -0
  46. package/dist/{PostgresObjectionMigrator-C69n7vzr.d.mts → PostgresObjectionMigrator-D_hCcrQu.d.mts} +3 -2
  47. package/dist/PostgresObjectionMigrator.d.mts +2 -2
  48. package/dist/PostgresObjectionMigrator.mjs +2 -2
  49. package/dist/{VitestKyselyTransactionIsolator-Dq4Oeh-Y.mjs → VitestKyselyTransactionIsolator-BxjlD1YM.mjs} +3 -4
  50. package/dist/VitestKyselyTransactionIsolator-BxjlD1YM.mjs.map +1 -0
  51. package/dist/{VitestKyselyTransactionIsolator-CnxpE9cH.d.mts → VitestKyselyTransactionIsolator-COCVfvfr.d.mts} +3 -2
  52. package/dist/{VitestKyselyTransactionIsolator-Dqy3qNoJ.cjs → VitestKyselyTransactionIsolator-Cst3vFjb.cjs} +3 -4
  53. package/dist/VitestKyselyTransactionIsolator-Cst3vFjb.cjs.map +1 -0
  54. package/dist/VitestKyselyTransactionIsolator-DYUYVEh9.d.cts +2 -1
  55. package/dist/VitestKyselyTransactionIsolator.cjs +1 -1
  56. package/dist/VitestKyselyTransactionIsolator.d.mts +2 -2
  57. package/dist/VitestKyselyTransactionIsolator.mjs +1 -1
  58. package/dist/{VitestObjectionTransactionIsolator-DVtJG2F3.mjs → VitestObjectionTransactionIsolator-BU-jXEhz.mjs} +3 -4
  59. package/dist/VitestObjectionTransactionIsolator-BU-jXEhz.mjs.map +1 -0
  60. package/dist/VitestObjectionTransactionIsolator-CJ4ds5Qv.d.cts +2 -1
  61. package/dist/{VitestObjectionTransactionIsolator-LP4B0cqW.cjs → VitestObjectionTransactionIsolator-DzeF4UAq.cjs} +3 -4
  62. package/dist/VitestObjectionTransactionIsolator-DzeF4UAq.cjs.map +1 -0
  63. package/dist/{VitestObjectionTransactionIsolator-DIM79dCq.d.mts → VitestObjectionTransactionIsolator-b973r9O1.d.mts} +3 -2
  64. package/dist/VitestObjectionTransactionIsolator.cjs +1 -1
  65. package/dist/VitestObjectionTransactionIsolator.d.mts +2 -2
  66. package/dist/VitestObjectionTransactionIsolator.mjs +1 -1
  67. package/dist/VitestTransactionIsolator-BQ5FpLtC.cjs +2 -1
  68. package/dist/VitestTransactionIsolator-BQ5FpLtC.cjs.map +1 -0
  69. package/dist/{VitestTransactionIsolator-zdyiS_SY.d.mts → VitestTransactionIsolator-CsfJBxcb.d.mts} +2 -1
  70. package/dist/VitestTransactionIsolator-CskiiJbW.mjs +2 -1
  71. package/dist/VitestTransactionIsolator-CskiiJbW.mjs.map +1 -0
  72. package/dist/VitestTransactionIsolator-DdLNODZg.d.cts +2 -1
  73. package/dist/VitestTransactionIsolator.d.mts +1 -1
  74. package/dist/aws.cjs +126 -0
  75. package/dist/aws.cjs.map +1 -0
  76. package/dist/aws.d.cts +22 -0
  77. package/dist/aws.d.mts +22 -0
  78. package/dist/aws.mjs +123 -0
  79. package/dist/aws.mjs.map +1 -0
  80. package/dist/directory-B-Ozljzk.mjs +22 -0
  81. package/dist/directory-B-Ozljzk.mjs.map +1 -0
  82. package/dist/directory-B4oYx02C.d.mts +12 -0
  83. package/dist/directory-BUcnztHI.d.cts +12 -0
  84. package/dist/directory-BVC8g7cX.cjs +28 -0
  85. package/dist/directory-BVC8g7cX.cjs.map +1 -0
  86. package/dist/faker-B14IEMIN.cjs +2 -1
  87. package/dist/faker-B14IEMIN.cjs.map +1 -0
  88. package/dist/faker-BGKYFoCT.mjs +2 -1
  89. package/dist/faker-BGKYFoCT.mjs.map +1 -0
  90. package/dist/{faker-BSH1EMtg.d.cts → faker-Cg76aFNO.d.cts} +4 -3
  91. package/dist/{faker-C-Iuk_R1.d.mts → faker-DHh7xs4u.d.mts} +4 -3
  92. package/dist/faker.d.cts +1 -1
  93. package/dist/faker.d.mts +1 -1
  94. package/dist/helpers.cjs +48 -2
  95. package/dist/helpers.cjs.map +1 -0
  96. package/dist/helpers.d.cts +2 -1
  97. package/dist/helpers.d.mts +2 -1
  98. package/dist/helpers.mjs +47 -2
  99. package/dist/helpers.mjs.map +1 -0
  100. package/dist/kysely.cjs +66 -3
  101. package/dist/kysely.cjs.map +1 -0
  102. package/dist/kysely.d.cts +5 -4
  103. package/dist/kysely.d.mts +9 -8
  104. package/dist/kysely.mjs +68 -5
  105. package/dist/kysely.mjs.map +1 -0
  106. package/dist/logger.cjs +23 -0
  107. package/dist/logger.cjs.map +1 -0
  108. package/dist/logger.d.cts +11 -0
  109. package/dist/logger.d.mts +11 -0
  110. package/dist/logger.mjs +22 -0
  111. package/dist/logger.mjs.map +1 -0
  112. package/dist/objection.cjs +81 -3
  113. package/dist/objection.cjs.map +1 -0
  114. package/dist/objection.d.cts +5 -4
  115. package/dist/objection.d.mts +9 -8
  116. package/dist/objection.mjs +83 -5
  117. package/dist/objection.mjs.map +1 -0
  118. package/dist/os/directory.cjs +3 -0
  119. package/dist/os/directory.d.cts +2 -0
  120. package/dist/os/directory.d.mts +2 -0
  121. package/dist/os/directory.mjs +3 -0
  122. package/dist/os/index.cjs +3 -0
  123. package/dist/os/index.d.cts +2 -0
  124. package/dist/os/index.d.mts +2 -0
  125. package/dist/os/index.mjs +3 -0
  126. package/dist/timer.cjs +9 -0
  127. package/dist/timer.cjs.map +1 -0
  128. package/dist/timer.d.cts +5 -0
  129. package/dist/timer.d.mts +5 -0
  130. package/dist/timer.mjs +8 -0
  131. package/dist/timer.mjs.map +1 -0
  132. package/package.json +25 -3
  133. package/src/VitestKyselyTransactionIsolator.ts +2 -2
  134. package/src/VitestObjectionTransactionIsolator.ts +1 -3
  135. package/src/aws.ts +131 -0
  136. package/src/logger.ts +18 -0
  137. package/src/os/directory.ts +21 -0
  138. package/src/os/index.ts +1 -0
  139. package/src/timer.ts +3 -0
  140. package/dist/__tests__/Factory.spec.cjs +0 -139
  141. package/dist/__tests__/Factory.spec.d.cts +0 -1
  142. package/dist/__tests__/Factory.spec.d.mts +0 -1
  143. package/dist/__tests__/Factory.spec.mjs +0 -138
  144. package/dist/__tests__/KyselyFactory.spec.cjs +0 -235
  145. package/dist/__tests__/KyselyFactory.spec.d.cts +0 -1
  146. package/dist/__tests__/KyselyFactory.spec.d.mts +0 -1
  147. package/dist/__tests__/KyselyFactory.spec.mjs +0 -234
  148. package/dist/__tests__/ObjectionFactory.spec.cjs +0 -340
  149. package/dist/__tests__/ObjectionFactory.spec.d.cts +0 -1
  150. package/dist/__tests__/ObjectionFactory.spec.d.mts +0 -1
  151. package/dist/__tests__/ObjectionFactory.spec.mjs +0 -339
  152. package/dist/__tests__/PostgresKyselyMigrator.spec.cjs +0 -397
  153. package/dist/__tests__/PostgresKyselyMigrator.spec.d.cts +0 -1
  154. package/dist/__tests__/PostgresKyselyMigrator.spec.d.mts +0 -1
  155. package/dist/__tests__/PostgresKyselyMigrator.spec.mjs +0 -396
  156. package/dist/__tests__/PostgresMigrator.spec.cjs +0 -256
  157. package/dist/__tests__/PostgresMigrator.spec.d.cts +0 -1
  158. package/dist/__tests__/PostgresMigrator.spec.d.mts +0 -1
  159. package/dist/__tests__/PostgresMigrator.spec.mjs +0 -255
  160. package/dist/__tests__/PostgresObjectionMigrator.spec.cjs +0 -432
  161. package/dist/__tests__/PostgresObjectionMigrator.spec.d.cts +0 -1
  162. package/dist/__tests__/PostgresObjectionMigrator.spec.d.mts +0 -1
  163. package/dist/__tests__/PostgresObjectionMigrator.spec.mjs +0 -431
  164. package/dist/__tests__/VitestObjectionTransactionIsolator.spec.cjs +0 -122
  165. package/dist/__tests__/VitestObjectionTransactionIsolator.spec.d.cts +0 -1
  166. package/dist/__tests__/VitestObjectionTransactionIsolator.spec.d.mts +0 -1
  167. package/dist/__tests__/VitestObjectionTransactionIsolator.spec.mjs +0 -121
  168. package/dist/__tests__/faker.spec.cjs +0 -115
  169. package/dist/__tests__/faker.spec.d.cts +0 -1
  170. package/dist/__tests__/faker.spec.d.mts +0 -1
  171. package/dist/__tests__/faker.spec.mjs +0 -114
  172. package/dist/__tests__/integration.spec.cjs +0 -282
  173. package/dist/__tests__/integration.spec.d.cts +0 -1
  174. package/dist/__tests__/integration.spec.d.mts +0 -1
  175. package/dist/__tests__/integration.spec.mjs +0 -281
  176. package/dist/helpers-B4TXg3Wp.mjs +0 -86
  177. package/dist/helpers-Bf0nXhbu.cjs +0 -116
  178. package/dist/helpers-BuPmgzyQ.mjs +0 -47
  179. package/dist/helpers-nEUtQ7eo.cjs +0 -53
  180. package/dist/kysely-BsDbvw3r.mjs +0 -67
  181. package/dist/kysely-CP1iJMvq.cjs +0 -72
  182. package/dist/objection-BEPk9h-g.mjs +0 -82
  183. package/dist/objection-Di7JSist.cjs +0 -87
package/src/aws.ts ADDED
@@ -0,0 +1,131 @@
1
+ import type {
2
+ APIGatewayProxyEvent,
3
+ APIGatewayProxyEventV2,
4
+ Context,
5
+ } from 'aws-lambda';
6
+ import { vi } from 'vitest';
7
+
8
+ /**
9
+ * Shared test utilities for AWS Lambda adapter testing
10
+ */
11
+
12
+ /**
13
+ * Creates a mock AWS Lambda Context for testing
14
+ */
15
+ export function createMockContext(): Context {
16
+ return {
17
+ awsRequestId: 'test-request-id',
18
+ callbackWaitsForEmptyEventLoop: false,
19
+ functionName: 'test-function',
20
+ functionVersion: '1',
21
+ invokedFunctionArn:
22
+ 'arn:aws:lambda:us-east-1:123456789012:function:test-function',
23
+ memoryLimitInMB: '128',
24
+ logGroupName: '/aws/lambda/test-function',
25
+ logStreamName: '2024/01/01/[$LATEST]abcdef123456',
26
+ getRemainingTimeInMillis: () => 5000,
27
+ done: vi.fn(),
28
+ fail: vi.fn(),
29
+ succeed: vi.fn(),
30
+ };
31
+ }
32
+
33
+ /**
34
+ * Creates a mock AWS API Gateway V1 (REST API) event for testing
35
+ */
36
+ export function createMockV1Event(
37
+ overrides: Partial<APIGatewayProxyEvent> = {},
38
+ ): APIGatewayProxyEvent {
39
+ return {
40
+ body: null,
41
+ headers: {
42
+ 'content-type': 'application/json',
43
+ 'user-agent': 'test-agent',
44
+ host: 'test.example.com',
45
+ },
46
+ multiValueHeaders: {},
47
+ httpMethod: 'GET',
48
+ isBase64Encoded: false,
49
+ path: '/test',
50
+ pathParameters: null,
51
+ queryStringParameters: null,
52
+ multiValueQueryStringParameters: null,
53
+ stageVariables: null,
54
+ requestContext: {
55
+ accountId: '123456789012',
56
+ apiId: 'api-id',
57
+ authorizer: null,
58
+ protocol: 'HTTP/1.1',
59
+ httpMethod: 'GET',
60
+ path: '/test',
61
+ stage: 'test',
62
+ requestId: 'request-id',
63
+ requestTimeEpoch: 1704067200000,
64
+ resourceId: 'resource-id',
65
+ resourcePath: '/test',
66
+ identity: {
67
+ accessKey: null,
68
+ accountId: null,
69
+ apiKey: null,
70
+ apiKeyId: null,
71
+ caller: null,
72
+ cognitoAuthenticationProvider: null,
73
+ cognitoAuthenticationType: null,
74
+ cognitoIdentityId: null,
75
+ cognitoIdentityPoolId: null,
76
+ principalOrgId: null,
77
+ sourceIp: '127.0.0.1',
78
+ user: null,
79
+ userAgent: 'test-agent',
80
+ userArn: null,
81
+ clientCert: null,
82
+ },
83
+ },
84
+ resource: '/test',
85
+ ...overrides,
86
+ };
87
+ }
88
+
89
+ /**
90
+ * Creates a mock AWS API Gateway V2 (HTTP API) event for testing
91
+ */
92
+ export function createMockV2Event(
93
+ overrides: Partial<APIGatewayProxyEventV2> = {},
94
+ ): APIGatewayProxyEventV2 {
95
+ return {
96
+ version: '2.0',
97
+ routeKey: 'GET /test',
98
+ rawPath: '/test',
99
+ rawQueryString: '',
100
+ headers: {
101
+ 'content-type': 'application/json',
102
+ 'user-agent': 'test-agent',
103
+ host: 'test.example.com',
104
+ },
105
+ requestContext: {
106
+ accountId: '123456789012',
107
+ apiId: 'api-id',
108
+ domainName: 'test.example.com',
109
+ domainPrefix: 'api',
110
+ requestId: 'request-id',
111
+ routeKey: 'GET /test',
112
+ stage: 'test',
113
+ time: '01/Jan/2024:00:00:00 +0000',
114
+ timeEpoch: 1704067200000,
115
+ http: {
116
+ method: 'GET',
117
+ path: '/test',
118
+ protocol: 'HTTP/1.1',
119
+ sourceIp: '127.0.0.1',
120
+ userAgent: 'test-agent',
121
+ },
122
+ },
123
+ body: undefined,
124
+ pathParameters: undefined,
125
+ isBase64Encoded: false,
126
+ stageVariables: undefined,
127
+ queryStringParameters: undefined,
128
+ cookies: undefined,
129
+ ...overrides,
130
+ };
131
+ }
package/src/logger.ts ADDED
@@ -0,0 +1,18 @@
1
+ import type { Logger } from '@geekmidas/logger';
2
+ import { vi } from 'vitest';
3
+
4
+ /**
5
+ * Creates a mock Logger for testing
6
+ */
7
+ export function createMockLogger(): Logger {
8
+ const logger: Logger = {
9
+ debug: vi.fn(),
10
+ info: vi.fn(),
11
+ warn: vi.fn(),
12
+ error: vi.fn(),
13
+ fatal: vi.fn(),
14
+ trace: vi.fn(),
15
+ child: vi.fn(() => logger),
16
+ };
17
+ return logger;
18
+ }
@@ -0,0 +1,21 @@
1
+ import crypto from 'node:crypto';
2
+ import fs from 'node:fs/promises';
3
+ import os from 'node:os';
4
+ import path from 'node:path';
5
+ import { it } from 'vitest';
6
+
7
+ export const itWithDir = it.extend<DirectoryFixtures>({
8
+ // This fixture automatically provides a transaction to each test
9
+ dir: async ({}, use) => {
10
+ const tempDir = os.tmpdir();
11
+ const directoryName = crypto.randomUUID().replace(/-/g, '').toUpperCase();
12
+ const dir = path.join(tempDir, directoryName);
13
+ await fs.mkdir(dir, { recursive: true });
14
+ await use(dir);
15
+ await fs.rm(dir, { recursive: true, force: true });
16
+ },
17
+ });
18
+
19
+ export interface DirectoryFixtures {
20
+ dir: string;
21
+ }
@@ -0,0 +1 @@
1
+ export { itWithDir } from './directory';
package/src/timer.ts ADDED
@@ -0,0 +1,3 @@
1
+ export function waitFor(ms: number) {
2
+ return new Promise((resolve) => setTimeout(resolve, ms));
3
+ }
@@ -1,139 +0,0 @@
1
- const require_chunk = require('../chunk-CUT6urMc.cjs');
2
- const require_Factory = require('../Factory-WMhTNZ9S.cjs');
3
- const vitest = require_chunk.__toESM(require("vitest"));
4
-
5
- //#region src/__tests__/Factory.spec.ts
6
- var TestFactory = class extends require_Factory.Factory {
7
- async insert(builderName, attrs) {
8
- return Promise.resolve({
9
- id: 1,
10
- ...attrs
11
- });
12
- }
13
- async insertMany(count, builderName, attrs) {
14
- const results = [];
15
- for (let i = 0; i < count; i++) {
16
- const newAttrs = typeof attrs === "function" ? attrs(i) : attrs;
17
- results.push(await this.insert(builderName, newAttrs));
18
- }
19
- return results;
20
- }
21
- seed(seedName, attrs) {
22
- return Promise.resolve({
23
- seedResult: true,
24
- ...attrs
25
- });
26
- }
27
- };
28
- (0, vitest.describe)("Factory", () => {
29
- (0, vitest.describe)("abstract class functionality", () => {
30
- (0, vitest.it)("should be instantiable through concrete implementation", () => {
31
- const factory = new TestFactory();
32
- (0, vitest.expect)(factory).toBeInstanceOf(require_Factory.Factory);
33
- (0, vitest.expect)(factory).toBeInstanceOf(TestFactory);
34
- });
35
- (0, vitest.it)("should have abstract methods defined", () => {
36
- const factory = new TestFactory();
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
- });
41
- });
42
- (0, vitest.describe)("createSeed static method", () => {
43
- (0, vitest.it)("should return the seed function unchanged", () => {
44
- const seedFn = async (attrs, factory, db) => {
45
- return {
46
- id: 1,
47
- name: "test"
48
- };
49
- };
50
- const result = require_Factory.Factory.createSeed(seedFn);
51
- (0, vitest.expect)(result).toBe(seedFn);
52
- (0, vitest.expect)(typeof result).toBe("function");
53
- });
54
- (0, vitest.it)("should work with different seed function signatures", () => {
55
- const simpleSeed = () => Promise.resolve({ simple: true });
56
- const complexSeed = async (attrs, factory, db) => {
57
- return {
58
- name: attrs.name,
59
- created: true
60
- };
61
- };
62
- const result1 = require_Factory.Factory.createSeed(simpleSeed);
63
- const result2 = require_Factory.Factory.createSeed(complexSeed);
64
- (0, vitest.expect)(result1).toBe(simpleSeed);
65
- (0, vitest.expect)(result2).toBe(complexSeed);
66
- });
67
- });
68
- (0, vitest.describe)("concrete implementation behavior", () => {
69
- let factory;
70
- (0, vitest.beforeEach)(() => {
71
- factory = new TestFactory();
72
- });
73
- (0, vitest.it)("should implement insert method", async () => {
74
- const result = await factory.insert("testBuilder", { name: "test" });
75
- (0, vitest.expect)(result).toEqual({
76
- id: 1,
77
- name: "test"
78
- });
79
- });
80
- (0, vitest.it)("should implement insertMany method", async () => {
81
- const results = await factory.insertMany(3, "testBuilder", { name: "test" });
82
- (0, vitest.expect)(results).toHaveLength(3);
83
- (0, vitest.expect)(results[0]).toEqual({
84
- id: 1,
85
- name: "test"
86
- });
87
- });
88
- (0, vitest.it)("should implement insertMany with function attributes", async () => {
89
- const results = await factory.insertMany(2, "testBuilder", (idx) => ({ name: `test${idx}` }));
90
- (0, vitest.expect)(results).toHaveLength(2);
91
- (0, vitest.expect)(results[0]).toEqual({
92
- id: 1,
93
- name: "test0"
94
- });
95
- (0, vitest.expect)(results[1]).toEqual({
96
- id: 1,
97
- name: "test1"
98
- });
99
- });
100
- (0, vitest.it)("should implement seed method", async () => {
101
- const result = await factory.seed("testSeed", { custom: "value" });
102
- (0, vitest.expect)(result).toEqual({
103
- seedResult: true,
104
- custom: "value"
105
- });
106
- });
107
- });
108
- (0, vitest.describe)("type definitions", () => {
109
- (0, vitest.it)("should properly type MixedFactoryBuilder", () => {
110
- const syncBuilder = (attrs, factory, db) => ({ sync: true });
111
- const asyncBuilder = async (attrs, factory, db) => ({ async: true });
112
- (0, vitest.expect)(typeof syncBuilder).toBe("function");
113
- (0, vitest.expect)(typeof asyncBuilder).toBe("function");
114
- });
115
- (0, vitest.it)("should properly type FactorySeed", () => {
116
- const seed = async (attrs, factory, db) => ({ seeded: true });
117
- (0, vitest.expect)(typeof seed).toBe("function");
118
- });
119
- });
120
- });
121
- (0, vitest.describe)("Factory types", () => {
122
- (0, vitest.it)("should export MixedFactoryBuilder type", () => {
123
- const builder = (attrs, factory, db) => {
124
- return {
125
- id: 1,
126
- name: attrs.name
127
- };
128
- };
129
- (0, vitest.expect)(typeof builder).toBe("function");
130
- });
131
- (0, vitest.it)("should export FactorySeed type", () => {
132
- const seed = async (attrs, factory, db) => {
133
- return { created: attrs.count };
134
- };
135
- (0, vitest.expect)(typeof seed).toBe("function");
136
- });
137
- });
138
-
139
- //#endregion
@@ -1 +0,0 @@
1
- export { };
@@ -1 +0,0 @@
1
- export { };
@@ -1,138 +0,0 @@
1
- import { Factory } from "../Factory-z2m01hMj.mjs";
2
- import { beforeEach, describe, expect, it } from "vitest";
3
-
4
- //#region src/__tests__/Factory.spec.ts
5
- var TestFactory = class extends Factory {
6
- async insert(builderName, attrs) {
7
- return Promise.resolve({
8
- id: 1,
9
- ...attrs
10
- });
11
- }
12
- async insertMany(count, builderName, attrs) {
13
- const results = [];
14
- for (let i = 0; i < count; i++) {
15
- const newAttrs = typeof attrs === "function" ? attrs(i) : attrs;
16
- results.push(await this.insert(builderName, newAttrs));
17
- }
18
- return results;
19
- }
20
- seed(seedName, attrs) {
21
- return Promise.resolve({
22
- seedResult: true,
23
- ...attrs
24
- });
25
- }
26
- };
27
- describe("Factory", () => {
28
- describe("abstract class functionality", () => {
29
- it("should be instantiable through concrete implementation", () => {
30
- const factory = new TestFactory();
31
- expect(factory).toBeInstanceOf(Factory);
32
- expect(factory).toBeInstanceOf(TestFactory);
33
- });
34
- it("should have abstract methods defined", () => {
35
- const factory = new TestFactory();
36
- expect(typeof factory.insert).toBe("function");
37
- expect(typeof factory.insertMany).toBe("function");
38
- expect(typeof factory.seed).toBe("function");
39
- });
40
- });
41
- describe("createSeed static method", () => {
42
- it("should return the seed function unchanged", () => {
43
- const seedFn = async (attrs, factory, db) => {
44
- return {
45
- id: 1,
46
- name: "test"
47
- };
48
- };
49
- const result = Factory.createSeed(seedFn);
50
- expect(result).toBe(seedFn);
51
- expect(typeof result).toBe("function");
52
- });
53
- it("should work with different seed function signatures", () => {
54
- const simpleSeed = () => Promise.resolve({ simple: true });
55
- const complexSeed = async (attrs, factory, db) => {
56
- return {
57
- name: attrs.name,
58
- created: true
59
- };
60
- };
61
- const result1 = Factory.createSeed(simpleSeed);
62
- const result2 = Factory.createSeed(complexSeed);
63
- expect(result1).toBe(simpleSeed);
64
- expect(result2).toBe(complexSeed);
65
- });
66
- });
67
- describe("concrete implementation behavior", () => {
68
- let factory;
69
- beforeEach(() => {
70
- factory = new TestFactory();
71
- });
72
- it("should implement insert method", async () => {
73
- const result = await factory.insert("testBuilder", { name: "test" });
74
- expect(result).toEqual({
75
- id: 1,
76
- name: "test"
77
- });
78
- });
79
- it("should implement insertMany method", async () => {
80
- const results = await factory.insertMany(3, "testBuilder", { name: "test" });
81
- expect(results).toHaveLength(3);
82
- expect(results[0]).toEqual({
83
- id: 1,
84
- name: "test"
85
- });
86
- });
87
- it("should implement insertMany with function attributes", async () => {
88
- const results = await factory.insertMany(2, "testBuilder", (idx) => ({ name: `test${idx}` }));
89
- expect(results).toHaveLength(2);
90
- expect(results[0]).toEqual({
91
- id: 1,
92
- name: "test0"
93
- });
94
- expect(results[1]).toEqual({
95
- id: 1,
96
- name: "test1"
97
- });
98
- });
99
- it("should implement seed method", async () => {
100
- const result = await factory.seed("testSeed", { custom: "value" });
101
- expect(result).toEqual({
102
- seedResult: true,
103
- custom: "value"
104
- });
105
- });
106
- });
107
- describe("type definitions", () => {
108
- it("should properly type MixedFactoryBuilder", () => {
109
- const syncBuilder = (attrs, factory, db) => ({ sync: true });
110
- const asyncBuilder = async (attrs, factory, db) => ({ async: true });
111
- expect(typeof syncBuilder).toBe("function");
112
- expect(typeof asyncBuilder).toBe("function");
113
- });
114
- it("should properly type FactorySeed", () => {
115
- const seed = async (attrs, factory, db) => ({ seeded: true });
116
- expect(typeof seed).toBe("function");
117
- });
118
- });
119
- });
120
- describe("Factory types", () => {
121
- it("should export MixedFactoryBuilder type", () => {
122
- const builder = (attrs, factory, db) => {
123
- return {
124
- id: 1,
125
- name: attrs.name
126
- };
127
- };
128
- expect(typeof builder).toBe("function");
129
- });
130
- it("should export FactorySeed type", () => {
131
- const seed = async (attrs, factory, db) => {
132
- return { created: attrs.count };
133
- };
134
- expect(typeof seed).toBe("function");
135
- });
136
- });
137
-
138
- //#endregion