UNPKG

@mbc-cqrs-serverless/core

Version:
203 lines (202 loc) 5.61 kB
/** * Test Data Builders * * Provides factory functions for creating test data used across * integration tests. This eliminates repetitive data creation and * ensures consistent test fixtures. * * Usage: * import { * createTestItem, * createTestItems, * createBatchWriteRequest * } from './utilities/test-data-builders' * * const item = createTestItem({ pk: 'user-1', sk: 'profile' }) * const items = createTestItems(100) */ import type { AttributeValue } from '@aws-sdk/client-dynamodb'; /** * Basic DynamoDB item structure */ export interface TestItem { pk: string; sk: string; [key: string]: unknown; } /** * Options for creating test items */ export interface CreateTestItemOptions { pk?: string; sk?: string; data?: Record<string, unknown>; withTimestamp?: boolean; withVersion?: number; } /** * Creates a single test item */ export declare function createTestItem(options?: CreateTestItemOptions): TestItem; /** * Creates multiple test items with sequential IDs */ export declare function createTestItems(count: number, options?: { pkPrefix?: string; skPrefix?: string; dataGenerator?: (index: number) => Record<string, unknown>; withTimestamp?: boolean; withVersion?: boolean; }): TestItem[]; /** * Creates a marshalled DynamoDB item */ export declare function createMarshalledItem(options?: CreateTestItemOptions): Record<string, AttributeValue>; /** * Creates multiple marshalled DynamoDB items */ export declare function createMarshalledItems(count: number, options?: Parameters<typeof createTestItems>[1]): Record<string, AttributeValue>[]; /** * Creates a DynamoDB key object */ export declare function createKey(pk: string, sk: string): Record<string, AttributeValue>; /** * Creates multiple DynamoDB keys */ export declare function createKeys(items: Array<{ pk: string; sk: string; }>): Record<string, AttributeValue>[]; /** * DynamoDB batch size limit */ export declare const DYNAMODB_BATCH_SIZE = 25; /** * Creates a BatchWriteItem request structure for DynamoDB */ export declare function createBatchWriteRequest(tableName: string, items: TestItem[]): { RequestItems: { [tableName: string]: Array<{ PutRequest: { Item: Record<string, AttributeValue>; }; }>; }; }; /** * Creates a BatchGetItem request structure for DynamoDB */ export declare function createBatchGetRequest(tableName: string, keys: Array<{ pk: string; sk: string; }>): { RequestItems: { [tableName: string]: { Keys: Record<string, AttributeValue>[]; }; }; }; /** * Splits items into batches of the specified size */ export declare function splitIntoBatches<T>(items: T[], batchSize?: number): T[][]; /** * Creates test content for S3 objects */ export declare function createS3Content(options?: { type?: 'text' | 'json' | 'binary'; size?: number; data?: unknown; }): Buffer; /** * Creates S3 object metadata */ export declare function createS3Metadata(options?: { contentType?: string; customMetadata?: Record<string, string>; }): { ContentType: string; Metadata?: Record<string, string>; }; /** * Creates an SQS message body */ export declare function createSQSMessageBody<T = Record<string, unknown>>(data: T): string; /** * Creates multiple SQS message entries for batch operations */ export declare function createSQSBatchEntries(messages: Array<{ id: string; body: unknown; delaySeconds?: number; messageAttributes?: Record<string, { DataType: string; StringValue?: string; }>; }>): Array<{ Id: string; MessageBody: string; DelaySeconds?: number; MessageAttributes?: Record<string, { DataType: string; StringValue?: string; }>; }>; /** * Creates an SNS message for publishing */ export declare function createSNSMessage(options: { subject?: string; message: unknown; messageAttributes?: Record<string, { DataType: string; StringValue?: string; }>; }): { Subject?: string; Message: string; MessageAttributes?: Record<string, { DataType: string; StringValue?: string; }>; }; /** * Creates Step Functions execution input */ export declare function createSFNInput<T = Record<string, unknown>>(data: T): string; /** * Creates a Step Functions execution name */ export declare function createSFNExecutionName(prefix?: string): string; /** * Creates a random string of specified length */ export declare function createRandomString(length: number): string; /** * Creates test data with nested structures */ export declare function createNestedTestData(depth: number, breadth?: number): Record<string, unknown>; /** * Creates test data with various JavaScript types */ export declare function createMixedTypeTestData(): Record<string, unknown>; /** * Creates large test data for performance/memory tests */ export declare function createLargeTestData(options?: { itemCount?: number; stringLength?: number; includeNested?: boolean; }): Record<string, unknown>; /** * Unmarshalls a DynamoDB item to a plain JavaScript object */ export declare function unmarshallItem<T = Record<string, unknown>>(item: Record<string, AttributeValue>): T; /** * Unmarshalls multiple DynamoDB items */ export declare function unmarshallItems<T = Record<string, unknown>>(items: Record<string, AttributeValue>[]): T[]; /** * Re-export for convenience */ export { marshall, unmarshall } from '@aws-sdk/util-dynamodb';