-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b9fcc40
commit 45b90f8
Showing
3 changed files
with
569 additions
and
458 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,89 @@ | ||
describe('index', () => { | ||
it('true is true', () => { | ||
expect(true).toEqual(true); | ||
// handler.test.ts | ||
|
||
import { handler } from '../src'; | ||
|
||
import { InvokeCommandOutput } from '@aws-sdk/client-lambda'; | ||
import { APIGatewayEvent, Context } from 'aws-lambda'; | ||
import { AuxoEventJson } from 'src/types'; | ||
|
||
// Mock aws clients from AWS SDK | ||
const mockClientSend = jest.fn(); | ||
jest.mock('@aws-sdk/client-lambda', () => { | ||
const originalModule = jest.requireActual('@aws-sdk/client-lambda'); | ||
return { | ||
...originalModule, | ||
LambdaClient: jest.fn(() => ({ | ||
send: mockClientSend, | ||
})), | ||
InvokeCommand: originalModule.InvokeCommand, | ||
}; | ||
}); | ||
|
||
// Mock logger and startBugsnag from @dydxprotocol-indexer/base | ||
jest.mock('@dydxprotocol-indexer/base', () => { | ||
const actualModule = jest.requireActual('@dydxprotocol-indexer/base'); | ||
return { | ||
...actualModule, // Spread the actual module's exports | ||
logger: { | ||
info: jest.fn(), | ||
error: jest.fn(), | ||
crit: jest.fn(), | ||
}, | ||
startBugsnag: jest.fn(), | ||
}; | ||
}); | ||
|
||
// Mock upgradeBazooka to do nothing | ||
jest.mock('../src/helpers', () => ({ | ||
...jest.requireActual('../src/helpers'), | ||
upgradeBazooka: jest.fn().mockResolvedValue(undefined), | ||
})); | ||
|
||
describe('Auxo Handler', () => { | ||
beforeEach(() => { | ||
// Reset all mocks before each test | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should return 500 when Bazooka Lambda errors', async () => { | ||
mockClientSend.mockResolvedValueOnce({ | ||
StatusCode: 500, | ||
FunctionError: 'Some bazooka error', | ||
$metadata: { | ||
httpStatusCode: 200, // api returns 200 even if lambda runtime error | ||
requestId: 'mock-request-id-invoke', | ||
extendedRequestId: 'mock-extended-request-id-invoke', | ||
cfId: 'mock-cf-id-invoke', | ||
attempts: 1, | ||
totalRetryDelay: 0, | ||
}, | ||
} as InvokeCommandOutput); | ||
|
||
const mockEvent: APIGatewayEvent & AuxoEventJson = { | ||
// APIGatewayEvent properties | ||
body: null, | ||
headers: {}, | ||
multiValueHeaders: {}, | ||
httpMethod: 'POST', | ||
isBase64Encoded: false, | ||
path: '/deploy', | ||
pathParameters: null, | ||
queryStringParameters: null, | ||
multiValueQueryStringParameters: null, | ||
stageVariables: null, | ||
resource: '', | ||
requestContext: {} as any, | ||
// AuxoEventJson properties | ||
upgrade_tag: 'some_tag', | ||
prefix: 'some_prefix', | ||
region: 'us-east-1', | ||
regionAbbrev: 'us-east-1', | ||
addNewKafkaTopics: false, | ||
onlyRunDbMigrationAndCreateKafkaTopics: false, | ||
}; | ||
|
||
const mockContext: Context = {} as any; | ||
|
||
await expect(handler(mockEvent, mockContext)).rejects.toThrow(); | ||
}); | ||
}); |
Oops, something went wrong.