Skip to content

Commit

Permalink
chore: add no metadata tc
Browse files Browse the repository at this point in the history
  • Loading branch information
Sai Sankeerth committed Jun 24, 2024
1 parent c32cefc commit 2aec7b8
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/adapters/network.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ describe(`${funcName} Tests`, () => {
});

describe('logging in http methods', () => {
beforeEach(() => {
mockLoggerInstance.info.mockClear();
loggerUtil.getMatchedMetadata.mockClear();
});
test('when proper metadata is sent should call logger without error', async () => {
const statTags = {
metadata: {
Expand Down Expand Up @@ -93,4 +97,44 @@ describe('logging in http methods', () => {
},
});
});

test('when metadata is not sent should call logger without error', async () => {
const statTags = {
destType: 'DT',
feature: 'feat',
endpointPath: '/m/n/o',
requestMethod: 'post',
};
loggerUtil.getMatchedMetadata.mockReturnValue([statTags.metadata]);

axios.post.mockResolvedValueOnce({
status: 200,
data: { a: 1, b: 2, c: 'abc' },
headers: {
'Content-Type': 'apllication/json',
'X-Some-Header': 'headsome',
},
});
await expect(httpPOST('https://some.web.com/m/n/o', {}, {}, statTags)).resolves.not.toThrow(
Error,
);
expect(loggerUtil.getMatchedMetadata).toHaveBeenCalledTimes(2);

expect(mockLoggerInstance.info).toHaveBeenCalledTimes(2);

expect(mockLoggerInstance.info).toHaveBeenNthCalledWith(1, ' [DT] /m/n/o request', {
body: {},
url: 'https://some.web.com/m/n/o',
method: 'post',
});

expect(mockLoggerInstance.info).toHaveBeenNthCalledWith(2, ' [DT] /m/n/o response', {
body: { a: 1, b: 2, c: 'abc' },
status: 200,
headers: {
'Content-Type': 'apllication/json',
'X-Some-Header': 'headsome',
},
});
});
});

0 comments on commit 2aec7b8

Please sign in to comment.