@mbc-cqrs-serverless/core 1.1.0-beta.0 → 1.1.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/commands/command.event.handler.d.ts +1 -1
- package/dist/commands/command.event.handler.js +1 -1
- package/dist/commands/command.event.handler.js.map +1 -1
- package/dist/constants/tenant.js.map +1 -1
- package/dist/helpers/index.d.ts +1 -1
- package/dist/helpers/index.js +2 -2
- package/dist/helpers/index.js.map +1 -1
- package/dist/integration/utilities/aws-error-factory.d.ts +141 -0
- package/dist/integration/utilities/aws-error-factory.js +392 -0
- package/dist/integration/utilities/aws-error-factory.js.map +1 -0
- package/dist/integration/utilities/aws-mock-manager.d.ts +136 -0
- package/dist/integration/utilities/aws-mock-manager.js +336 -0
- package/dist/integration/utilities/aws-mock-manager.js.map +1 -0
- package/dist/integration/utilities/index.d.ts +22 -0
- package/dist/integration/utilities/index.js +99 -0
- package/dist/integration/utilities/index.js.map +1 -0
- package/dist/integration/utilities/test-assertions.d.ts +112 -0
- package/dist/integration/utilities/test-assertions.js +345 -0
- package/dist/integration/utilities/test-assertions.js.map +1 -0
- package/dist/integration/utilities/test-data-builders.d.ts +202 -0
- package/dist/integration/utilities/test-data-builders.js +320 -0
- package/dist/integration/utilities/test-data-builders.js.map +1 -0
- package/dist/interfaces/notification.interface.d.ts +13 -0
- package/dist/notifications/email.service.js +16 -4
- package/dist/notifications/email.service.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test Assertions
|
|
3
|
+
*
|
|
4
|
+
* Provides reusable assertion functions for AWS SDK error patterns
|
|
5
|
+
* and common test scenarios. These helpers ensure consistent
|
|
6
|
+
* validation across integration tests.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* import {
|
|
10
|
+
* assertIsRetriableError,
|
|
11
|
+
* assertIsThrottlingError,
|
|
12
|
+
* assertErrorMetadata
|
|
13
|
+
* } from './utilities/test-assertions'
|
|
14
|
+
*
|
|
15
|
+
* it('should be retriable', () => {
|
|
16
|
+
* assertIsRetriableError(error)
|
|
17
|
+
* })
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Asserts that an error is retriable based on AWS SDK v3 patterns
|
|
21
|
+
*/
|
|
22
|
+
export declare function assertIsRetriableError(error: unknown): void;
|
|
23
|
+
/**
|
|
24
|
+
* Asserts that an error is NOT retriable
|
|
25
|
+
*/
|
|
26
|
+
export declare function assertIsNotRetriableError(error: unknown): void;
|
|
27
|
+
/**
|
|
28
|
+
* Asserts that an error is a throttling error
|
|
29
|
+
*/
|
|
30
|
+
export declare function assertIsThrottlingError(error: unknown): void;
|
|
31
|
+
/**
|
|
32
|
+
* Asserts that an error is a network error
|
|
33
|
+
*/
|
|
34
|
+
export declare function assertIsNetworkError(error: unknown): void;
|
|
35
|
+
/**
|
|
36
|
+
* Asserts that an error is a timeout error
|
|
37
|
+
*/
|
|
38
|
+
export declare function assertIsTimeoutError(error: unknown): void;
|
|
39
|
+
/**
|
|
40
|
+
* Asserts that an error has the expected metadata
|
|
41
|
+
*/
|
|
42
|
+
export declare function assertErrorMetadata(error: unknown, expected: {
|
|
43
|
+
httpStatusCode?: number;
|
|
44
|
+
requestId?: string;
|
|
45
|
+
name?: string;
|
|
46
|
+
fault?: 'client' | 'server';
|
|
47
|
+
}): void;
|
|
48
|
+
/**
|
|
49
|
+
* Asserts that an error has a valid request ID
|
|
50
|
+
*/
|
|
51
|
+
export declare function assertHasRequestId(error: unknown): void;
|
|
52
|
+
/**
|
|
53
|
+
* Asserts that an error is a client fault (4xx)
|
|
54
|
+
*/
|
|
55
|
+
export declare function assertIsClientFault(error: unknown): void;
|
|
56
|
+
/**
|
|
57
|
+
* Asserts that an error is a server fault (5xx)
|
|
58
|
+
*/
|
|
59
|
+
export declare function assertIsServerFault(error: unknown): void;
|
|
60
|
+
/**
|
|
61
|
+
* Asserts that a response has the expected structure
|
|
62
|
+
*/
|
|
63
|
+
export declare function assertResponseStructure<T extends object>(response: unknown, expectedKeys: Array<keyof T>): void;
|
|
64
|
+
/**
|
|
65
|
+
* Asserts that a DynamoDB response has valid metadata
|
|
66
|
+
*/
|
|
67
|
+
export declare function assertDynamoDBResponseMetadata(response: unknown): void;
|
|
68
|
+
/**
|
|
69
|
+
* Asserts that an async function throws an error with the expected name
|
|
70
|
+
*/
|
|
71
|
+
export declare function assertThrowsErrorWithName(fn: () => Promise<unknown>, expectedName: string): Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Asserts that an async function throws an error matching a predicate
|
|
74
|
+
*/
|
|
75
|
+
export declare function assertThrowsErrorMatching(fn: () => Promise<unknown>, predicate: (error: unknown) => boolean, description?: string): Promise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* Asserts that an async operation completes within a time limit
|
|
78
|
+
*/
|
|
79
|
+
export declare function assertCompletesWithin<T>(fn: () => Promise<T>, timeoutMs: number): Promise<T>;
|
|
80
|
+
/**
|
|
81
|
+
* Asserts that an async operation takes at least a minimum time
|
|
82
|
+
* (useful for testing retry delays)
|
|
83
|
+
*/
|
|
84
|
+
export declare function assertTakesAtLeast<T>(fn: () => Promise<T>, minMs: number): Promise<T>;
|
|
85
|
+
/**
|
|
86
|
+
* Forces garbage collection if available (requires --expose-gc flag)
|
|
87
|
+
*/
|
|
88
|
+
export declare function forceGC(): void;
|
|
89
|
+
/**
|
|
90
|
+
* Gets current heap memory usage in bytes
|
|
91
|
+
*/
|
|
92
|
+
export declare function getHeapUsed(): number;
|
|
93
|
+
/**
|
|
94
|
+
* Asserts that memory increase is within acceptable limits
|
|
95
|
+
*/
|
|
96
|
+
export declare function assertMemoryIncreaseLessThan(initialMemory: number, maxIncreaseBytes: number): void;
|
|
97
|
+
/**
|
|
98
|
+
* Runs a function and asserts memory usage stays within limits
|
|
99
|
+
*/
|
|
100
|
+
export declare function assertNoMemoryLeak<T>(fn: () => Promise<T>, maxIncreaseBytes?: number): Promise<T>;
|
|
101
|
+
/**
|
|
102
|
+
* Asserts that an array has the expected length
|
|
103
|
+
*/
|
|
104
|
+
export declare function assertArrayLength<T>(array: T[], expectedLength: number): void;
|
|
105
|
+
/**
|
|
106
|
+
* Asserts that all items in an array match a predicate
|
|
107
|
+
*/
|
|
108
|
+
export declare function assertAllMatch<T>(array: T[], predicate: (item: T) => boolean, description?: string): void;
|
|
109
|
+
/**
|
|
110
|
+
* Asserts that an array contains unique items based on a key function
|
|
111
|
+
*/
|
|
112
|
+
export declare function assertUniqueBy<T, K>(array: T[], keyFn: (item: T) => K): void;
|
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Test Assertions
|
|
4
|
+
*
|
|
5
|
+
* Provides reusable assertion functions for AWS SDK error patterns
|
|
6
|
+
* and common test scenarios. These helpers ensure consistent
|
|
7
|
+
* validation across integration tests.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* import {
|
|
11
|
+
* assertIsRetriableError,
|
|
12
|
+
* assertIsThrottlingError,
|
|
13
|
+
* assertErrorMetadata
|
|
14
|
+
* } from './utilities/test-assertions'
|
|
15
|
+
*
|
|
16
|
+
* it('should be retriable', () => {
|
|
17
|
+
* assertIsRetriableError(error)
|
|
18
|
+
* })
|
|
19
|
+
*/
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.assertIsRetriableError = assertIsRetriableError;
|
|
22
|
+
exports.assertIsNotRetriableError = assertIsNotRetriableError;
|
|
23
|
+
exports.assertIsThrottlingError = assertIsThrottlingError;
|
|
24
|
+
exports.assertIsNetworkError = assertIsNetworkError;
|
|
25
|
+
exports.assertIsTimeoutError = assertIsTimeoutError;
|
|
26
|
+
exports.assertErrorMetadata = assertErrorMetadata;
|
|
27
|
+
exports.assertHasRequestId = assertHasRequestId;
|
|
28
|
+
exports.assertIsClientFault = assertIsClientFault;
|
|
29
|
+
exports.assertIsServerFault = assertIsServerFault;
|
|
30
|
+
exports.assertResponseStructure = assertResponseStructure;
|
|
31
|
+
exports.assertDynamoDBResponseMetadata = assertDynamoDBResponseMetadata;
|
|
32
|
+
exports.assertThrowsErrorWithName = assertThrowsErrorWithName;
|
|
33
|
+
exports.assertThrowsErrorMatching = assertThrowsErrorMatching;
|
|
34
|
+
exports.assertCompletesWithin = assertCompletesWithin;
|
|
35
|
+
exports.assertTakesAtLeast = assertTakesAtLeast;
|
|
36
|
+
exports.forceGC = forceGC;
|
|
37
|
+
exports.getHeapUsed = getHeapUsed;
|
|
38
|
+
exports.assertMemoryIncreaseLessThan = assertMemoryIncreaseLessThan;
|
|
39
|
+
exports.assertNoMemoryLeak = assertNoMemoryLeak;
|
|
40
|
+
exports.assertArrayLength = assertArrayLength;
|
|
41
|
+
exports.assertAllMatch = assertAllMatch;
|
|
42
|
+
exports.assertUniqueBy = assertUniqueBy;
|
|
43
|
+
// ============================================================================
|
|
44
|
+
// Error Type Assertions
|
|
45
|
+
// ============================================================================
|
|
46
|
+
/**
|
|
47
|
+
* Asserts that an error is retriable based on AWS SDK v3 patterns
|
|
48
|
+
*/
|
|
49
|
+
function assertIsRetriableError(error) {
|
|
50
|
+
const awsError = error;
|
|
51
|
+
const isRetriable = awsError.$retryable !== undefined ||
|
|
52
|
+
(awsError.$metadata?.httpStatusCode &&
|
|
53
|
+
awsError.$metadata.httpStatusCode >= 500) ||
|
|
54
|
+
awsError.$metadata?.httpStatusCode === 429 ||
|
|
55
|
+
[
|
|
56
|
+
'ProvisionedThroughputExceededException',
|
|
57
|
+
'ThrottlingException',
|
|
58
|
+
'InternalServerError',
|
|
59
|
+
'ServiceUnavailable',
|
|
60
|
+
'RequestLimitExceeded',
|
|
61
|
+
'SlowDown',
|
|
62
|
+
'TooManyRequestsException',
|
|
63
|
+
].includes(awsError.name);
|
|
64
|
+
if (!isRetriable) {
|
|
65
|
+
throw new Error(`Expected error to be retriable, but got: ${awsError.name} (status: ${awsError.$metadata?.httpStatusCode})`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Asserts that an error is NOT retriable
|
|
70
|
+
*/
|
|
71
|
+
function assertIsNotRetriableError(error) {
|
|
72
|
+
const awsError = error;
|
|
73
|
+
const nonRetriablePatterns = !awsError.$retryable &&
|
|
74
|
+
awsError.$metadata?.httpStatusCode !== undefined &&
|
|
75
|
+
awsError.$metadata.httpStatusCode < 500 &&
|
|
76
|
+
awsError.$metadata.httpStatusCode !== 429;
|
|
77
|
+
if (!nonRetriablePatterns) {
|
|
78
|
+
throw new Error(`Expected error to NOT be retriable, but got: ${awsError.name} (status: ${awsError.$metadata?.httpStatusCode}, $retryable: ${JSON.stringify(awsError.$retryable)})`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Asserts that an error is a throttling error
|
|
83
|
+
*/
|
|
84
|
+
function assertIsThrottlingError(error) {
|
|
85
|
+
const awsError = error;
|
|
86
|
+
if (awsError.$retryable?.throttling !== true) {
|
|
87
|
+
throw new Error(`Expected throttling error, but got: ${awsError.name} ($retryable: ${JSON.stringify(awsError.$retryable)})`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Asserts that an error is a network error
|
|
92
|
+
*/
|
|
93
|
+
function assertIsNetworkError(error) {
|
|
94
|
+
const err = error;
|
|
95
|
+
const networkErrorCodes = [
|
|
96
|
+
'ECONNRESET',
|
|
97
|
+
'ECONNREFUSED',
|
|
98
|
+
'ETIMEDOUT',
|
|
99
|
+
'ENETUNREACH',
|
|
100
|
+
'ENOTFOUND',
|
|
101
|
+
'EPIPE',
|
|
102
|
+
'EAI_AGAIN',
|
|
103
|
+
];
|
|
104
|
+
const isNetwork = (err.code && networkErrorCodes.includes(err.code)) ||
|
|
105
|
+
err.message.toLowerCase().includes('socket hang up') ||
|
|
106
|
+
err.message.toLowerCase().includes('network error') ||
|
|
107
|
+
err.message.toLowerCase().includes('connection reset') ||
|
|
108
|
+
err.message.toLowerCase().includes('connection refused');
|
|
109
|
+
if (!isNetwork) {
|
|
110
|
+
throw new Error(`Expected network error, but got: ${err.message} (code: ${err.code})`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Asserts that an error is a timeout error
|
|
115
|
+
*/
|
|
116
|
+
function assertIsTimeoutError(error) {
|
|
117
|
+
const err = error;
|
|
118
|
+
const isTimeout = err.code === 'ETIMEDOUT' ||
|
|
119
|
+
err.name === 'TimeoutError' ||
|
|
120
|
+
err.message.toLowerCase().includes('timeout') ||
|
|
121
|
+
err.message.toLowerCase().includes('timed out');
|
|
122
|
+
if (!isTimeout) {
|
|
123
|
+
throw new Error(`Expected timeout error, but got: ${err.message} (name: ${err.name}, code: ${err.code})`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
// ============================================================================
|
|
127
|
+
// Error Metadata Assertions
|
|
128
|
+
// ============================================================================
|
|
129
|
+
/**
|
|
130
|
+
* Asserts that an error has the expected metadata
|
|
131
|
+
*/
|
|
132
|
+
function assertErrorMetadata(error, expected) {
|
|
133
|
+
const awsError = error;
|
|
134
|
+
if (expected.httpStatusCode !== undefined) {
|
|
135
|
+
if (awsError.$metadata?.httpStatusCode !== expected.httpStatusCode) {
|
|
136
|
+
throw new Error(`Expected httpStatusCode ${expected.httpStatusCode}, but got ${awsError.$metadata?.httpStatusCode}`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (expected.requestId !== undefined) {
|
|
140
|
+
if (awsError.$metadata?.requestId !== expected.requestId) {
|
|
141
|
+
throw new Error(`Expected requestId ${expected.requestId}, but got ${awsError.$metadata?.requestId}`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (expected.name !== undefined) {
|
|
145
|
+
if (awsError.name !== expected.name) {
|
|
146
|
+
throw new Error(`Expected error name ${expected.name}, but got ${awsError.name}`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (expected.fault !== undefined) {
|
|
150
|
+
if (awsError.$fault !== expected.fault) {
|
|
151
|
+
throw new Error(`Expected fault ${expected.fault}, but got ${awsError.$fault}`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Asserts that an error has a valid request ID
|
|
157
|
+
*/
|
|
158
|
+
function assertHasRequestId(error) {
|
|
159
|
+
const awsError = error;
|
|
160
|
+
if (!awsError.$metadata?.requestId) {
|
|
161
|
+
throw new Error('Expected error to have a requestId in $metadata');
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Asserts that an error is a client fault (4xx)
|
|
166
|
+
*/
|
|
167
|
+
function assertIsClientFault(error) {
|
|
168
|
+
const awsError = error;
|
|
169
|
+
if (awsError.$fault !== 'client') {
|
|
170
|
+
throw new Error(`Expected client fault, but got ${awsError.$fault}`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Asserts that an error is a server fault (5xx)
|
|
175
|
+
*/
|
|
176
|
+
function assertIsServerFault(error) {
|
|
177
|
+
const awsError = error;
|
|
178
|
+
if (awsError.$fault !== 'server') {
|
|
179
|
+
throw new Error(`Expected server fault, but got ${awsError.$fault}`);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
// ============================================================================
|
|
183
|
+
// Response Assertions
|
|
184
|
+
// ============================================================================
|
|
185
|
+
/**
|
|
186
|
+
* Asserts that a response has the expected structure
|
|
187
|
+
*/
|
|
188
|
+
function assertResponseStructure(response, expectedKeys) {
|
|
189
|
+
if (typeof response !== 'object' || response === null) {
|
|
190
|
+
throw new Error(`Expected object response, but got ${typeof response}`);
|
|
191
|
+
}
|
|
192
|
+
const missingKeys = expectedKeys.filter((key) => !(key in response));
|
|
193
|
+
if (missingKeys.length > 0) {
|
|
194
|
+
throw new Error(`Response missing expected keys: ${missingKeys.join(', ')}. Got keys: ${Object.keys(response).join(', ')}`);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Asserts that a DynamoDB response has valid metadata
|
|
199
|
+
*/
|
|
200
|
+
function assertDynamoDBResponseMetadata(response) {
|
|
201
|
+
const resp = response;
|
|
202
|
+
if (!resp.$metadata) {
|
|
203
|
+
throw new Error('Expected $metadata in DynamoDB response');
|
|
204
|
+
}
|
|
205
|
+
if (resp.$metadata.httpStatusCode !== 200) {
|
|
206
|
+
throw new Error(`Expected httpStatusCode 200, but got ${resp.$metadata.httpStatusCode}`);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
// ============================================================================
|
|
210
|
+
// Async Assertions
|
|
211
|
+
// ============================================================================
|
|
212
|
+
/**
|
|
213
|
+
* Asserts that an async function throws an error with the expected name
|
|
214
|
+
*/
|
|
215
|
+
async function assertThrowsErrorWithName(fn, expectedName) {
|
|
216
|
+
try {
|
|
217
|
+
await fn();
|
|
218
|
+
throw new Error(`Expected function to throw ${expectedName}, but it did not throw`);
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
if (error.name !== expectedName) {
|
|
222
|
+
throw new Error(`Expected error name ${expectedName}, but got ${error.name}`);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Asserts that an async function throws an error matching a predicate
|
|
228
|
+
*/
|
|
229
|
+
async function assertThrowsErrorMatching(fn, predicate, description = 'custom predicate') {
|
|
230
|
+
try {
|
|
231
|
+
await fn();
|
|
232
|
+
throw new Error(`Expected function to throw error matching ${description}, but it did not throw`);
|
|
233
|
+
}
|
|
234
|
+
catch (error) {
|
|
235
|
+
if (!predicate(error)) {
|
|
236
|
+
throw new Error(`Error did not match ${description}: ${error.message}`);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
// ============================================================================
|
|
241
|
+
// Timing Assertions
|
|
242
|
+
// ============================================================================
|
|
243
|
+
/**
|
|
244
|
+
* Asserts that an async operation completes within a time limit
|
|
245
|
+
*/
|
|
246
|
+
async function assertCompletesWithin(fn, timeoutMs) {
|
|
247
|
+
const start = Date.now();
|
|
248
|
+
const result = await fn();
|
|
249
|
+
const duration = Date.now() - start;
|
|
250
|
+
if (duration > timeoutMs) {
|
|
251
|
+
throw new Error(`Expected operation to complete within ${timeoutMs}ms, but took ${duration}ms`);
|
|
252
|
+
}
|
|
253
|
+
return result;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Asserts that an async operation takes at least a minimum time
|
|
257
|
+
* (useful for testing retry delays)
|
|
258
|
+
*/
|
|
259
|
+
async function assertTakesAtLeast(fn, minMs) {
|
|
260
|
+
const start = Date.now();
|
|
261
|
+
const result = await fn();
|
|
262
|
+
const duration = Date.now() - start;
|
|
263
|
+
if (duration < minMs) {
|
|
264
|
+
throw new Error(`Expected operation to take at least ${minMs}ms, but took ${duration}ms`);
|
|
265
|
+
}
|
|
266
|
+
return result;
|
|
267
|
+
}
|
|
268
|
+
// ============================================================================
|
|
269
|
+
// Memory Assertions
|
|
270
|
+
// ============================================================================
|
|
271
|
+
/**
|
|
272
|
+
* Forces garbage collection if available (requires --expose-gc flag)
|
|
273
|
+
*/
|
|
274
|
+
function forceGC() {
|
|
275
|
+
if (global.gc) {
|
|
276
|
+
global.gc();
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Gets current heap memory usage in bytes
|
|
281
|
+
*/
|
|
282
|
+
function getHeapUsed() {
|
|
283
|
+
return process.memoryUsage().heapUsed;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Asserts that memory increase is within acceptable limits
|
|
287
|
+
*/
|
|
288
|
+
function assertMemoryIncreaseLessThan(initialMemory, maxIncreaseBytes) {
|
|
289
|
+
forceGC();
|
|
290
|
+
const currentMemory = getHeapUsed();
|
|
291
|
+
const increase = currentMemory - initialMemory;
|
|
292
|
+
if (increase > maxIncreaseBytes) {
|
|
293
|
+
const increaseMB = (increase / 1024 / 1024).toFixed(2);
|
|
294
|
+
const maxMB = (maxIncreaseBytes / 1024 / 1024).toFixed(2);
|
|
295
|
+
throw new Error(`Memory increased by ${increaseMB}MB, which exceeds limit of ${maxMB}MB`);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Runs a function and asserts memory usage stays within limits
|
|
300
|
+
*/
|
|
301
|
+
async function assertNoMemoryLeak(fn, maxIncreaseBytes = 50 * 1024 * 1024) {
|
|
302
|
+
forceGC();
|
|
303
|
+
const initialMemory = getHeapUsed();
|
|
304
|
+
const result = await fn();
|
|
305
|
+
assertMemoryIncreaseLessThan(initialMemory, maxIncreaseBytes);
|
|
306
|
+
return result;
|
|
307
|
+
}
|
|
308
|
+
// ============================================================================
|
|
309
|
+
// Array/Collection Assertions
|
|
310
|
+
// ============================================================================
|
|
311
|
+
/**
|
|
312
|
+
* Asserts that an array has the expected length
|
|
313
|
+
*/
|
|
314
|
+
function assertArrayLength(array, expectedLength) {
|
|
315
|
+
if (array.length !== expectedLength) {
|
|
316
|
+
throw new Error(`Expected array length ${expectedLength}, but got ${array.length}`);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Asserts that all items in an array match a predicate
|
|
321
|
+
*/
|
|
322
|
+
function assertAllMatch(array, predicate, description = 'predicate') {
|
|
323
|
+
const failingIndex = array.findIndex((item) => !predicate(item));
|
|
324
|
+
if (failingIndex !== -1) {
|
|
325
|
+
throw new Error(`Item at index ${failingIndex} did not match ${description}`);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Asserts that an array contains unique items based on a key function
|
|
330
|
+
*/
|
|
331
|
+
function assertUniqueBy(array, keyFn) {
|
|
332
|
+
const seen = new Set();
|
|
333
|
+
const duplicates = [];
|
|
334
|
+
array.forEach((item) => {
|
|
335
|
+
const key = keyFn(item);
|
|
336
|
+
if (seen.has(key)) {
|
|
337
|
+
duplicates.push(key);
|
|
338
|
+
}
|
|
339
|
+
seen.add(key);
|
|
340
|
+
});
|
|
341
|
+
if (duplicates.length > 0) {
|
|
342
|
+
throw new Error(`Found duplicate keys: ${duplicates.join(', ')}`);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
//# sourceMappingURL=test-assertions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-assertions.js","sourceRoot":"","sources":["../../../src/integration/utilities/test-assertions.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;AAWH,wDAuBC;AAKD,8DAcC;AAKD,0DAQC;AAKD,oDAyBC;AAKD,oDAcC;AASD,kDA0CC;AAKD,gDAMC;AAKD,kDAMC;AAKD,kDAMC;AASD,0DAiBC;AAKD,wEAYC;AASD,8DAgBC;AAKD,8DAiBC;AASD,sDAeC;AAMD,gDAeC;AASD,0BAIC;AAKD,kCAEC;AAKD,oEAeC;AAKD,gDAYC;AASD,8CAMC;AAKD,wCAYC;AAKD,wCAeC;AAvbD,+EAA+E;AAC/E,wBAAwB;AACxB,+EAA+E;AAE/E;;GAEG;AACH,SAAgB,sBAAsB,CAAC,KAAc;IACnD,MAAM,QAAQ,GAAG,KAAiB,CAAA;IAElC,MAAM,WAAW,GACf,QAAQ,CAAC,UAAU,KAAK,SAAS;QACjC,CAAC,QAAQ,CAAC,SAAS,EAAE,cAAc;YACjC,QAAQ,CAAC,SAAS,CAAC,cAAc,IAAI,GAAG,CAAC;QAC3C,QAAQ,CAAC,SAAS,EAAE,cAAc,KAAK,GAAG;QAC1C;YACE,wCAAwC;YACxC,qBAAqB;YACrB,qBAAqB;YACrB,oBAAoB;YACpB,sBAAsB;YACtB,UAAU;YACV,0BAA0B;SAC3B,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;IAE3B,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CACb,4CAA4C,QAAQ,CAAC,IAAI,aAAa,QAA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CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACrB,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,CAAA;QACvB,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAClB,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QACtB,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IACf,CAAC,CAAC,CAAA;IAEF,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,yBAAyB,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IACnE,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test Data Builders
|
|
3
|
+
*
|
|
4
|
+
* Provides factory functions for creating test data used across
|
|
5
|
+
* integration tests. This eliminates repetitive data creation and
|
|
6
|
+
* ensures consistent test fixtures.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* import {
|
|
10
|
+
* createTestItem,
|
|
11
|
+
* createTestItems,
|
|
12
|
+
* createBatchWriteRequest
|
|
13
|
+
* } from './utilities/test-data-builders'
|
|
14
|
+
*
|
|
15
|
+
* const item = createTestItem({ pk: 'user-1', sk: 'profile' })
|
|
16
|
+
* const items = createTestItems(100)
|
|
17
|
+
*/
|
|
18
|
+
import type { AttributeValue } from '@aws-sdk/client-dynamodb';
|
|
19
|
+
/**
|
|
20
|
+
* Basic DynamoDB item structure
|
|
21
|
+
*/
|
|
22
|
+
export interface TestItem {
|
|
23
|
+
pk: string;
|
|
24
|
+
sk: string;
|
|
25
|
+
[key: string]: unknown;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Options for creating test items
|
|
29
|
+
*/
|
|
30
|
+
export interface CreateTestItemOptions {
|
|
31
|
+
pk?: string;
|
|
32
|
+
sk?: string;
|
|
33
|
+
data?: Record<string, unknown>;
|
|
34
|
+
withTimestamp?: boolean;
|
|
35
|
+
withVersion?: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Creates a single test item
|
|
39
|
+
*/
|
|
40
|
+
export declare function createTestItem(options?: CreateTestItemOptions): TestItem;
|
|
41
|
+
/**
|
|
42
|
+
* Creates multiple test items with sequential IDs
|
|
43
|
+
*/
|
|
44
|
+
export declare function createTestItems(count: number, options?: {
|
|
45
|
+
pkPrefix?: string;
|
|
46
|
+
skPrefix?: string;
|
|
47
|
+
dataGenerator?: (index: number) => Record<string, unknown>;
|
|
48
|
+
withTimestamp?: boolean;
|
|
49
|
+
withVersion?: boolean;
|
|
50
|
+
}): TestItem[];
|
|
51
|
+
/**
|
|
52
|
+
* Creates a marshalled DynamoDB item
|
|
53
|
+
*/
|
|
54
|
+
export declare function createMarshalledItem(options?: CreateTestItemOptions): Record<string, AttributeValue>;
|
|
55
|
+
/**
|
|
56
|
+
* Creates multiple marshalled DynamoDB items
|
|
57
|
+
*/
|
|
58
|
+
export declare function createMarshalledItems(count: number, options?: Parameters<typeof createTestItems>[1]): Record<string, AttributeValue>[];
|
|
59
|
+
/**
|
|
60
|
+
* Creates a DynamoDB key object
|
|
61
|
+
*/
|
|
62
|
+
export declare function createKey(pk: string, sk: string): Record<string, AttributeValue>;
|
|
63
|
+
/**
|
|
64
|
+
* Creates multiple DynamoDB keys
|
|
65
|
+
*/
|
|
66
|
+
export declare function createKeys(items: Array<{
|
|
67
|
+
pk: string;
|
|
68
|
+
sk: string;
|
|
69
|
+
}>): Record<string, AttributeValue>[];
|
|
70
|
+
/**
|
|
71
|
+
* DynamoDB batch size limit
|
|
72
|
+
*/
|
|
73
|
+
export declare const DYNAMODB_BATCH_SIZE = 25;
|
|
74
|
+
/**
|
|
75
|
+
* Creates a BatchWriteItem request structure for DynamoDB
|
|
76
|
+
*/
|
|
77
|
+
export declare function createBatchWriteRequest(tableName: string, items: TestItem[]): {
|
|
78
|
+
RequestItems: {
|
|
79
|
+
[tableName: string]: Array<{
|
|
80
|
+
PutRequest: {
|
|
81
|
+
Item: Record<string, AttributeValue>;
|
|
82
|
+
};
|
|
83
|
+
}>;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Creates a BatchGetItem request structure for DynamoDB
|
|
88
|
+
*/
|
|
89
|
+
export declare function createBatchGetRequest(tableName: string, keys: Array<{
|
|
90
|
+
pk: string;
|
|
91
|
+
sk: string;
|
|
92
|
+
}>): {
|
|
93
|
+
RequestItems: {
|
|
94
|
+
[tableName: string]: {
|
|
95
|
+
Keys: Record<string, AttributeValue>[];
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Splits items into batches of the specified size
|
|
101
|
+
*/
|
|
102
|
+
export declare function splitIntoBatches<T>(items: T[], batchSize?: number): T[][];
|
|
103
|
+
/**
|
|
104
|
+
* Creates test content for S3 objects
|
|
105
|
+
*/
|
|
106
|
+
export declare function createS3Content(options?: {
|
|
107
|
+
type?: 'text' | 'json' | 'binary';
|
|
108
|
+
size?: number;
|
|
109
|
+
data?: unknown;
|
|
110
|
+
}): Buffer;
|
|
111
|
+
/**
|
|
112
|
+
* Creates S3 object metadata
|
|
113
|
+
*/
|
|
114
|
+
export declare function createS3Metadata(options?: {
|
|
115
|
+
contentType?: string;
|
|
116
|
+
customMetadata?: Record<string, string>;
|
|
117
|
+
}): {
|
|
118
|
+
ContentType: string;
|
|
119
|
+
Metadata?: Record<string, string>;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Creates an SQS message body
|
|
123
|
+
*/
|
|
124
|
+
export declare function createSQSMessageBody<T = Record<string, unknown>>(data: T): string;
|
|
125
|
+
/**
|
|
126
|
+
* Creates multiple SQS message entries for batch operations
|
|
127
|
+
*/
|
|
128
|
+
export declare function createSQSBatchEntries(messages: Array<{
|
|
129
|
+
id: string;
|
|
130
|
+
body: unknown;
|
|
131
|
+
delaySeconds?: number;
|
|
132
|
+
messageAttributes?: Record<string, {
|
|
133
|
+
DataType: string;
|
|
134
|
+
StringValue?: string;
|
|
135
|
+
}>;
|
|
136
|
+
}>): Array<{
|
|
137
|
+
Id: string;
|
|
138
|
+
MessageBody: string;
|
|
139
|
+
DelaySeconds?: number;
|
|
140
|
+
MessageAttributes?: Record<string, {
|
|
141
|
+
DataType: string;
|
|
142
|
+
StringValue?: string;
|
|
143
|
+
}>;
|
|
144
|
+
}>;
|
|
145
|
+
/**
|
|
146
|
+
* Creates an SNS message for publishing
|
|
147
|
+
*/
|
|
148
|
+
export declare function createSNSMessage(options: {
|
|
149
|
+
subject?: string;
|
|
150
|
+
message: unknown;
|
|
151
|
+
messageAttributes?: Record<string, {
|
|
152
|
+
DataType: string;
|
|
153
|
+
StringValue?: string;
|
|
154
|
+
}>;
|
|
155
|
+
}): {
|
|
156
|
+
Subject?: string;
|
|
157
|
+
Message: string;
|
|
158
|
+
MessageAttributes?: Record<string, {
|
|
159
|
+
DataType: string;
|
|
160
|
+
StringValue?: string;
|
|
161
|
+
}>;
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* Creates Step Functions execution input
|
|
165
|
+
*/
|
|
166
|
+
export declare function createSFNInput<T = Record<string, unknown>>(data: T): string;
|
|
167
|
+
/**
|
|
168
|
+
* Creates a Step Functions execution name
|
|
169
|
+
*/
|
|
170
|
+
export declare function createSFNExecutionName(prefix?: string): string;
|
|
171
|
+
/**
|
|
172
|
+
* Creates a random string of specified length
|
|
173
|
+
*/
|
|
174
|
+
export declare function createRandomString(length: number): string;
|
|
175
|
+
/**
|
|
176
|
+
* Creates test data with nested structures
|
|
177
|
+
*/
|
|
178
|
+
export declare function createNestedTestData(depth: number, breadth?: number): Record<string, unknown>;
|
|
179
|
+
/**
|
|
180
|
+
* Creates test data with various JavaScript types
|
|
181
|
+
*/
|
|
182
|
+
export declare function createMixedTypeTestData(): Record<string, unknown>;
|
|
183
|
+
/**
|
|
184
|
+
* Creates large test data for performance/memory tests
|
|
185
|
+
*/
|
|
186
|
+
export declare function createLargeTestData(options?: {
|
|
187
|
+
itemCount?: number;
|
|
188
|
+
stringLength?: number;
|
|
189
|
+
includeNested?: boolean;
|
|
190
|
+
}): Record<string, unknown>;
|
|
191
|
+
/**
|
|
192
|
+
* Unmarshalls a DynamoDB item to a plain JavaScript object
|
|
193
|
+
*/
|
|
194
|
+
export declare function unmarshallItem<T = Record<string, unknown>>(item: Record<string, AttributeValue>): T;
|
|
195
|
+
/**
|
|
196
|
+
* Unmarshalls multiple DynamoDB items
|
|
197
|
+
*/
|
|
198
|
+
export declare function unmarshallItems<T = Record<string, unknown>>(items: Record<string, AttributeValue>[]): T[];
|
|
199
|
+
/**
|
|
200
|
+
* Re-export for convenience
|
|
201
|
+
*/
|
|
202
|
+
export { marshall, unmarshall } from '@aws-sdk/util-dynamodb';
|