Skip to content

Commit

Permalink
Merge pull request #209 from skedify/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken Depelchin authored Oct 26, 2020
2 parents 5683fbb + 8ad8cc3 commit 2dd03f6
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ You can also specify custom headers on requests:

```js
SDK.appointments
.headers({'X-Scheduling-Rules', 'disallow-appointment-overlap'})
.headers({ 'X-Scheduling-Rules' : 'disallow-appointment-overlap' })
.update({
/* insert properties of appointment here */
})
Expand Down
25 changes: 25 additions & 0 deletions src/Skedify.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,31 @@ describe('API/Config', () => {
uninstallSkedifySDKMock(SDK)
})

it('should be possible to set custom headers', async () => {
const SDK = new API({
auth_provider: API.createAuthProviderString('public_client', {
client_id: 'someclientidtokengoeshere',
realm: 'http://127.0.0.1',
}),
locale: 'nl-BE',
headers: {
Host: 'api.example.com',
},
})

installSkedifySDKMock(SDK)

expect(
await matchRequest(
SDK.appointments().headers({
'X-Scheduling-Rules': 'disallow-appointment-overlap',
})
)
).toMatchSnapshot()

uninstallSkedifySDKMock(SDK)
})

it('should throw when a resource requires a custom domain endpoint when it is not defined', () => {
const SDK = new API({
auth_provider: API.createAuthProviderString('public_client', {
Expand Down
18 changes: 18 additions & 0 deletions src/__snapshots__/Skedify.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1874,6 +1874,24 @@ Object {
}
`;

exports[`API/Config should be possible to set custom headers 1`] = `
Object {
"data": undefined,
"headers": Object {
"Accept": "application/json, text/plain, */*",
"Accept-Language": "nl-BE, nl;q=0.667, *;q=0.333",
"Authorization": "Bearer fake_example_access_token",
"Cache-Control": "no-store",
"Host": "api.example.com",
"Pragma": "no-cache",
"X-Scheduling-Rules": "disallow-appointment-overlap",
},
"method": "get",
"params": undefined,
"url": "http://127.0.0.1/appointments",
}
`;

exports[`API/Config should throw an error when onConfigurationChange is not passed a function 1`] = `"[CONFIG]: You tried to call \`.onConfigurationChange(null)\` but it must receive a function."`;

exports[`API/Config should throw an error when overriding items on the configuration object directly 1`] = `"Cannot assign to read only property 'locale' of object '#<Object>'"`;
Expand Down
9 changes: 9 additions & 0 deletions src/resources/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Object {
"start",
"end",
"contact",
"office",
"page",
"per_page",
],
Expand Down Expand Up @@ -1045,6 +1046,14 @@ Object {
"key": "location[geolocation]",
"name": "geolocation",
},
Object {
"key": "location[country]",
"name": "country",
},
Object {
"key": "location[postal_code]",
"name": "postal_code",
},
"limit",
"page",
"per_page",
Expand Down
2 changes: 1 addition & 1 deletion src/resources/appointments.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const appointments = createResourceDescription(
'outcomes',
'appointment_outcomes',
],
filters: ['uuid', 'state', 'start', 'end', 'contact'],
filters: ['uuid', 'state', 'start', 'end', 'contact', 'office'],
headers: {
[HTTP_VERB_POST]: {
recaptcha: (value) => {
Expand Down
2 changes: 2 additions & 0 deletions src/resources/offices.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export const offices = createResourceDescription(
'schedulable',
'nearest_to_geo',
{ name: 'geolocation', key: 'location[geolocation]' },
{ name: 'country', key: 'location[country]' },
{ name: 'postal_code', key: 'location[postal_code]' },
'limit',
],
},
Expand Down

0 comments on commit 2dd03f6

Please sign in to comment.