-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cubejs-client-core): Remove Content-Type header from requests in …
…HttpTransport (#709) * fix(cubejs-client-core): Remove Content-Type header from requests in HttpTransport
- Loading branch information
1 parent
d3c735b
commit f6e366c
Showing
2 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* eslint-disable import/first */ | ||
/* eslint-disable import/newline-after-import */ | ||
/* globals describe,test,expect,jest,afterEach */ | ||
import '@babel/runtime/regenerator'; | ||
jest.mock('cross-fetch'); | ||
import fetch from 'cross-fetch'; | ||
import HttpTransport from './HttpTransport'; | ||
|
||
describe('HttpTransport', () => { | ||
const apiUrl = 'http://localhost:3000/cubejs-api/v1'; | ||
const query = { | ||
measures: ['Orders.count'], | ||
dimensions: ['Users.country'] | ||
}; | ||
const queryUrlEncoded = '%7B%22measures%22%3A%5B%22Orders.count%22%5D%2C%22dimensions%22%3A%5B%22Users.country%22%5D%7D'; | ||
|
||
afterEach(() => { | ||
fetch.mockClear(); | ||
}); | ||
|
||
test('it serializes the query object and sends it in the query string', async () => { | ||
const transport = new HttpTransport({ | ||
authorization: 'token', | ||
apiUrl, | ||
}); | ||
const req = transport.request('load', { query }); | ||
await req.subscribe(() => { }); | ||
expect(fetch).toHaveBeenCalledTimes(1); | ||
expect(fetch).toHaveBeenCalledWith(`${apiUrl}/load?query=${queryUrlEncoded}`, { | ||
headers: { | ||
Authorization: 'token', | ||
} | ||
}); | ||
}); | ||
|
||
test('it passes extra headers and serializes extra params', async () => { | ||
const extraParams = { foo: 'bar' }; | ||
const serializedExtraParams = encodeURIComponent(JSON.stringify(extraParams)); | ||
const transport = new HttpTransport({ | ||
authorization: 'token', | ||
apiUrl, | ||
headers: { | ||
'X-Extra-Header': '42' | ||
} | ||
}); | ||
const req = transport.request('meta', { extraParams }); | ||
await req.subscribe(() => { }); | ||
expect(fetch).toHaveBeenCalledTimes(1); | ||
expect(fetch).toHaveBeenCalledWith(`${apiUrl}/meta?extraParams=${serializedExtraParams}`, { | ||
headers: { | ||
Authorization: 'token', | ||
'X-Extra-Header': '42' | ||
} | ||
}); | ||
}); | ||
}); |