@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.
- package/dist/{Factory-D7P3bKKb.d.mts → Factory-BZ8uMoXl.d.cts} +3 -2
- package/dist/{Factory-pNV7ZQ7-.d.cts → Factory-Cmr3s3-s.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-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-72P98y5I.d.mts → KyselyFactory-Cx3sezwH.d.mts} +4 -3
- 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-C-59Hjwj.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-Dq4Oeh-Y.mjs → VitestKyselyTransactionIsolator-BxjlD1YM.mjs} +3 -4
- package/dist/VitestKyselyTransactionIsolator-BxjlD1YM.mjs.map +1 -0
- package/dist/{VitestKyselyTransactionIsolator-CnxpE9cH.d.mts → VitestKyselyTransactionIsolator-COCVfvfr.d.mts} +3 -2
- package/dist/{VitestKyselyTransactionIsolator-Dqy3qNoJ.cjs → VitestKyselyTransactionIsolator-Cst3vFjb.cjs} +3 -4
- package/dist/VitestKyselyTransactionIsolator-Cst3vFjb.cjs.map +1 -0
- package/dist/VitestKyselyTransactionIsolator-DYUYVEh9.d.cts +2 -1
- package/dist/VitestKyselyTransactionIsolator.cjs +1 -1
- package/dist/VitestKyselyTransactionIsolator.d.mts +2 -2
- package/dist/VitestKyselyTransactionIsolator.mjs +1 -1
- package/dist/{VitestObjectionTransactionIsolator-DVtJG2F3.mjs → VitestObjectionTransactionIsolator-BU-jXEhz.mjs} +3 -4
- package/dist/VitestObjectionTransactionIsolator-BU-jXEhz.mjs.map +1 -0
- package/dist/VitestObjectionTransactionIsolator-CJ4ds5Qv.d.cts +2 -1
- package/dist/{VitestObjectionTransactionIsolator-LP4B0cqW.cjs → VitestObjectionTransactionIsolator-DzeF4UAq.cjs} +3 -4
- package/dist/VitestObjectionTransactionIsolator-DzeF4UAq.cjs.map +1 -0
- package/dist/{VitestObjectionTransactionIsolator-DIM79dCq.d.mts → VitestObjectionTransactionIsolator-b973r9O1.d.mts} +3 -2
- package/dist/VitestObjectionTransactionIsolator.cjs +1 -1
- package/dist/VitestObjectionTransactionIsolator.d.mts +2 -2
- package/dist/VitestObjectionTransactionIsolator.mjs +1 -1
- 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/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-BSH1EMtg.d.cts → faker-Cg76aFNO.d.cts} +4 -3
- package/dist/{faker-C-Iuk_R1.d.mts → faker-DHh7xs4u.d.mts} +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 +66 -3
- 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 +68 -5
- 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 +81 -3
- 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 +83 -5
- 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 +25 -3
- package/src/VitestKyselyTransactionIsolator.ts +2 -2
- package/src/VitestObjectionTransactionIsolator.ts +1 -3
- package/src/aws.ts +131 -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-BsDbvw3r.mjs +0 -67
- package/dist/kysely-CP1iJMvq.cjs +0 -72
- package/dist/objection-BEPk9h-g.mjs +0 -82
- 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
|
+
}
|
package/src/os/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { itWithDir } from './directory';
|
package/src/timer.ts
ADDED
|
@@ -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
|