-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #314 from teamleadercrm/CORE_make-it-possible-to-s…
…end-custom-headers Feature: Make it possible to send custom headers
- Loading branch information
Showing
9 changed files
with
159 additions
and
5 deletions.
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
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
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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
export default async ({ getAccessToken, version } = {}) => { | ||
export default async ({ getAccessToken, version, additionalHeaders } = {}) => { | ||
const accessToken = getAccessToken && (await getAccessToken()); | ||
return { | ||
'Content-Type': 'application/json', | ||
...(typeof accessToken !== 'undefined' && { Authorization: `Bearer ${accessToken}` }), | ||
...(version && { 'X-Api-Version': version }), | ||
...additionalHeaders, | ||
}; | ||
}; |
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,7 @@ | ||
export default (...headers) => | ||
headers.reduce((combined, headerConfiguration) => { | ||
if (!headerConfiguration || typeof headerConfiguration !== 'object') { | ||
return combined; | ||
} | ||
return { ...combined, ...headerConfiguration }; | ||
}, {}); |
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,83 @@ | ||
import mergeHeaders from '../../src/utils/mergeHeaders'; | ||
|
||
describe(`merge headers`, () => { | ||
it(`should merge the headers in a correct way`, () => { | ||
const globalHeaders = { | ||
'x-header-1': 'headerValue1', | ||
'x-header-2': 'headerValue2', | ||
}; | ||
|
||
const localHeaders = { | ||
'x-header-3': 'headerValue3', | ||
'x-header-4': 'headerValue4', | ||
}; | ||
|
||
const headers = mergeHeaders(globalHeaders, localHeaders); | ||
|
||
const expectedHeaders = { | ||
'x-header-1': 'headerValue1', | ||
'x-header-2': 'headerValue2', | ||
'x-header-3': 'headerValue3', | ||
'x-header-4': 'headerValue4', | ||
}; | ||
|
||
expect(headers).toEqual(expectedHeaders); | ||
}); | ||
|
||
it(`should merge the headers in a correct way when one header object is given`, () => { | ||
const globalHeaders = { | ||
'x-header-1': 'headerValue1', | ||
'x-header-2': 'headerValue2', | ||
}; | ||
|
||
const headers = mergeHeaders(globalHeaders); | ||
|
||
const expectedHeaders = { | ||
'x-header-1': 'headerValue1', | ||
'x-header-2': 'headerValue2', | ||
}; | ||
|
||
expect(headers).toEqual(expectedHeaders); | ||
}); | ||
|
||
it(`should merge the headers in a correct way when one header object is invalid`, () => { | ||
const globalHeaders = { | ||
'x-header-1': 'headerValue1', | ||
'x-header-2': 'headerValue2', | ||
}; | ||
|
||
const localHeaders = 'invalid'; | ||
|
||
const headers = mergeHeaders(globalHeaders, localHeaders); | ||
|
||
const expectedHeaders = { | ||
'x-header-1': 'headerValue1', | ||
'x-header-2': 'headerValue2', | ||
}; | ||
|
||
expect(headers).toEqual(expectedHeaders); | ||
}); | ||
|
||
it(`should merge the headers in a correct way when header objects are undefined`, () => { | ||
const headers = mergeHeaders(undefined, undefined); | ||
|
||
expect(headers).toEqual({}); | ||
}); | ||
it(`should merge the headers in a correct way when one header object is invalid`, () => { | ||
const globalHeaders = { | ||
'x-header-1': 'headerValue1', | ||
'x-header-2': 'headerValue2', | ||
}; | ||
|
||
const localHeaders = 'invalid'; | ||
|
||
const headers = mergeHeaders(globalHeaders, localHeaders); | ||
|
||
const expectedHeaders = { | ||
'x-header-1': 'headerValue1', | ||
'x-header-2': 'headerValue2', | ||
}; | ||
|
||
expect(headers).toEqual(expectedHeaders); | ||
}); | ||
}); |