Skip to content

Commit

Permalink
Verify that API parameters are build correctly (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
Siegrift authored Nov 30, 2023
1 parent 900628d commit ec260f5
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions packages/pusher/src/api-requests/data-provider.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as adapterModule from '@api3/airnode-adapter';
import axios from 'axios';

import {
config,
Expand All @@ -8,9 +9,12 @@ import {
} from '../../test/fixtures';
import { logger } from '../logger';
import * as stateModule from '../state';
import type { Config } from '../validation/schema';

import { makeTemplateRequests } from './data-provider';

jest.mock('axios');

describe(makeTemplateRequests.name, () => {
it('makes a single template request for multiple beacons', async () => {
const state = stateModule.getInitialState(config);
Expand All @@ -20,6 +24,7 @@ describe(makeTemplateRequests.name, () => {
const response = await makeTemplateRequests(config.triggers.signedApiUpdates[0]!);

expect(response).toStrictEqual(nodaryTemplateResponses);
expect(adapterModule.buildAndExecuteRequest).toHaveBeenCalledTimes(1);
});

it('handles request failure', async () => {
Expand All @@ -38,4 +43,63 @@ describe(makeTemplateRequests.name, () => {
operationTemplateId: '0xcc35bd1800c06c12856a87311dd95bfcbb3add875844021d59a929d79f3c99bd',
});
});

it('can uses fixed operational parameters', async () => {
const configWithFixedOperationalParameters: Config = {
...config,
ois: [
{
...config.ois[0]!,
endpoints: [
{
...config.ois[0]!.endpoints[0]!,
fixedOperationParameters: [
{
operationParameter: {
in: 'query',
name: 'some-api-parameter',
},
value: 'some-value',
},
],
},
],
apiSpecifications: {
...config.ois[0]!.apiSpecifications,
paths: {
'/feed/latestV2': {
get: {
parameters: [
{ in: 'query', name: 'names' },
{ in: 'query', name: 'some-api-parameter' },
],
},
},
},
servers: [{ url: 'https://api.nodary.io' }],
security: { NodarySecurityScheme1ApiKey: [] },
},
},
],
};
const state = stateModule.getInitialState(configWithFixedOperationalParameters);
jest.spyOn(stateModule, 'getState').mockReturnValue(state);
(axios as jest.MockedFunction<typeof axios>).mockRejectedValue(new Error('network error'));

await makeTemplateRequests(config.triggers.signedApiUpdates[0]!);

expect(axios).toHaveBeenCalledTimes(1);
expect(axios).toHaveBeenCalledWith({
data: undefined,
headers: {
'x-nodary-api-key': 'invalid-api-key',
},
method: 'get',
params: {
'some-api-parameter': 'some-value',
},
timeout: 10_000,
url: 'https://api.nodary.io/feed/latestV2',
});
});
});

0 comments on commit ec260f5

Please sign in to comment.