Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Siegrift committed Oct 12, 2023
1 parent 037252a commit e2d39d1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
15 changes: 11 additions & 4 deletions packages/pusher/src/api-requests/data-provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import * as adapterModule from '@api3/airnode-adapter';

import {
config,
nodaryTemplateRequestErrorResponse,
nodaryTemplateRequestError,
nodaryTemplateRequestResponseData,
nodaryTemplateResponses,
} from '../../test/fixtures';
import { logger } from '../logger';
import * as stateModule from '../state';

import { makeTemplateRequests } from './data-provider';
Expand All @@ -24,11 +25,17 @@ describe(makeTemplateRequests.name, () => {
it('handles request failure', async () => {
const state = stateModule.getInitialState(config);
jest.spyOn(stateModule, 'getState').mockReturnValue(state);
jest.spyOn(adapterModule, 'buildAndExecuteRequest').mockRejectedValue(nodaryTemplateRequestErrorResponse);
jest.spyOn(logger, 'warn');
jest.spyOn(adapterModule, 'buildAndExecuteRequest').mockRejectedValue(nodaryTemplateRequestError);

await expect(makeTemplateRequests(config.triggers.signedApiUpdates[0]!)).rejects.toStrictEqual({
await makeTemplateRequests(config.triggers.signedApiUpdates[0]!);

expect(logger.warn).toHaveBeenCalledTimes(1);
expect(logger.warn).toHaveBeenCalledWith('Failed to make API call', {
endpointName: 'feed',
errorMessage: 'Invalid API key',
success: false,
oisTitle: 'Nodary',
operationTemplateId: '0xcc35bd1800c06c12856a87311dd95bfcbb3add875844021d59a929d79f3c99bd',
});
});
});
4 changes: 1 addition & 3 deletions packages/pusher/test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ export const nodaryTemplateRequestResponseData = {
},
} as AxiosResponse;

export const nodaryTemplateRequestErrorResponse = {
message: 'Invalid API key',
} as AxiosError;
export const nodaryTemplateRequestError = new Error('Invalid API key');

export const nodaryTemplateResponses: TemplateResponse[] = [
[
Expand Down

0 comments on commit e2d39d1

Please sign in to comment.