import { Agent } from 'https' import { DynamoDB } from '@aws-sdk/client-dynamodb' import { jest } from '@jest/globals' import { NodeHttpHandler } from '@smithy/node-http-handler' import type { DbConfig } from '../../../../src/Database/index.js' import { DynamoDatabase } from '../../../../src/Database/integrations/dynamo/DynamoDatabase.js' const config: DbConfig<'dynamo'> = { type: 'dynamo', region: 'ca-central-1', tableName: 'myTable', } const expectedImplConfig = { region: config.region, maxAttempts: 3, requestHandler: new NodeHttpHandler({ connectionTimeout: 60000, socketTimeout: 60000, httpsAgent: new Agent({ keepAlive: false, maxSockets: 50, rejectUnauthorized: true }), }), } describe('DynamoDatabase', () => { test('DynamoDatabase', async () => { const mockTrans = { a: 'b' } as any const mockClient = jest.fn( () => ({ test: async () => mockTrans, }) as any as DynamoDB ) DynamoDatabase['dynamoProvider'] = mockClient const underTest = new DynamoDatabase(config) expect(mockClient).toBeCalledWith(expectedImplConfig) // no transaction const trans = await underTest.transaction() expect(trans).toBe(null) }) })