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 0aa4771
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 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',
});
});
});
6 changes: 2 additions & 4 deletions packages/pusher/test/fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AxiosError, AxiosResponse } from 'axios';
import type { AxiosResponse } from 'axios';

import type { SignedResponse, TemplateResponse } from '../src/sign-template-data';
import type { Config } from '../src/validation/schema';
Expand Down 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 0aa4771

Please sign in to comment.