mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-04-19 13:06:22 +00:00
Added missing application/json content-type when calling Shlink with payload
This commit is contained in:
@@ -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' },
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user