Added missing application/json content-type when calling Shlink with payload

This commit is contained in:
Alejandro Celaya
2022-12-17 09:57:40 +01:00
parent b106b3cd0a
commit 2603f2f987
3 changed files with 48 additions and 4 deletions

View File

@@ -14,13 +14,39 @@ describe('HttpClient', () => {
await expect(httpClient.fetchJson('')).rejects.toEqual(theError);
});
it('return json on failure', async () => {
it.each([
[undefined],
[{}],
[{ body: undefined }],
[{ body: '' }],
])('return json on failure', async (options) => {
const theJson = { foo: 'bar' };
fetch.mockResolvedValue({ json: () => theJson, ok: true });
const result = await httpClient.fetchJson('');
const result = await httpClient.fetchJson('the_url', options);
expect(result).toEqual(theJson);
expect(fetch).toHaveBeenCalledWith('the_url', options);
});
it.each([
[{ body: 'the_body' }],
[{
body: 'the_body',
headers: {
'Content-Type': 'text/plain',
},
}],
])('forwards JSON content-type when appropriate', async (options) => {
const theJson = { foo: 'bar' };
fetch.mockResolvedValue({ json: () => theJson, ok: true });
const result = await httpClient.fetchJson('the_url', options);
expect(result).toEqual(theJson);
expect(fetch).toHaveBeenCalledWith('the_url', expect.objectContaining({
headers: { 'Content-Type': 'application/json' },
}));
});
});