feat: Set default for Accept field in header to take application/json (#1413)

* Update SupersetClientClass.ts

* Update SupersetClientClass.ts

* add comment

* update test
This commit is contained in:
Hugh A. Miles II 2021-11-08 12:59:45 -05:00 committed by Yongjie Zhao
parent 069d4115a8
commit 67f1083af6
2 changed files with 12 additions and 2 deletions

View File

@ -74,7 +74,7 @@ export default class SupersetClientClass {
this.baseUrl = url.href.replace(/\/+$/, ''); // always strip trailing slash
this.host = url.host;
this.protocol = url.protocol as Protocol;
this.headers = { ...headers };
this.headers = { Accept: 'application/json', ...headers }; // defaulting accept to json
this.mode = mode;
this.timeout = timeout;
this.credentials = credentials;

View File

@ -53,7 +53,7 @@ describe('SupersetClient', () => {
// this also tests that the ^above doesn't throw if configure is called appropriately
it('calls appropriate SupersetClient methods when configured', async () => {
expect.assertions(10);
expect.assertions(15);
const mockGetUrl = '/mock/get/url';
const mockPostUrl = '/mock/post/url';
const mockRequestUrl = '/mock/request/url';
@ -90,6 +90,16 @@ describe('SupersetClient', () => {
await SupersetClient.delete({ url: mockDeleteUrl });
await SupersetClient.put({ url: mockPutUrl });
await SupersetClient.request({ url: mockRequestUrl });
// Make sure network calls have Accept: 'application/json' in headers
const networkCalls = [mockGetUrl, mockPostUrl, mockRequestUrl, mockPutUrl, mockDeleteUrl];
networkCalls.map((url: string) =>
expect(fetchMock.calls(url)[0][1]?.headers).toStrictEqual({
Accept: 'application/json',
'X-CSRFToken': '',
}),
);
SupersetClient.isAuthenticated();
await SupersetClient.reAuthenticate();