Skip to content

Commit

Permalink
propagate bazooka failure in auxo
Browse files Browse the repository at this point in the history
  • Loading branch information
jerryfan01234 committed Oct 23, 2024
1 parent b9fcc40 commit 45b90f8
Show file tree
Hide file tree
Showing 3 changed files with 569 additions and 458 deletions.
90 changes: 87 additions & 3 deletions indexer/services/auxo/__tests__/index.test.ts
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();
});
});
Loading

0 comments on commit 45b90f8

Please sign in to comment.