Skip to content

Commit

Permalink
feat: Set default for Accept field in header to take application/json (
Browse files Browse the repository at this point in the history
…apache#1413)

* Update SupersetClientClass.ts

* Update SupersetClientClass.ts

* add comment

* update test
  • Loading branch information
hughhhh authored and zhaoyongjie committed Nov 25, 2021
1 parent 2bc41cc commit 3168a23
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 3168a23

Please sign in to comment.