Skip to content

Commit

Permalink
test: add contentType from payload type and data as conditional to th…
Browse files Browse the repository at this point in the history
…e request
  • Loading branch information
JoaoMacedo03 committed Aug 15, 2023
1 parent 899c8a2 commit 9cfd34c
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/zendesk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,4 +326,41 @@ describe('ZendeskClientBase', () => {
expect(mockZendeskClient.request).toHaveBeenCalledTimes(1);
}
);

it('should call makeRequest with the correct ContentType', async () => {
const expectedContentType = 'application/json';
const payload: PayloadRequestZendesk = {
url: 'url',
method: 'method',
contentType: 'application/json'
};
await zendeskClientBase.makeRequest(payload);
delete payload.retryCount;
expect(mockZendeskClient.request).toHaveBeenCalledWith({
...payload,
secure: false,
contentType: expectedContentType,
httpCompleteResponse: true
});
expect(mockZendeskClient.request).toHaveBeenCalledTimes(1);
});

it('should call makeRequest with the correct data', async () => {
const expectedData = { id: '1' };
const payload: PayloadRequestZendesk = {
url: 'url',
method: 'method',
data: { id: '1' }
};
await zendeskClientBase.makeRequest(payload);
delete payload.retryCount;
expect(mockZendeskClient.request).toHaveBeenCalledWith({
...payload,
secure: false,
data: expectedData,
httpCompleteResponse: true,
contentType: 'application/x-www-form-urlencoded'
});
expect(mockZendeskClient.request).toHaveBeenCalledTimes(1);
});
});

0 comments on commit 9cfd34c

Please sign in to comment.