-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: make duffel.stays.accommodation.suggestions API call
- Loading branch information
Showing
6 changed files
with
73 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import nock from 'nock' | ||
import { Duffel } from '../../index' | ||
import { MOCK_ACCOMMODATION_SUGGESTION } from '../mocks' | ||
|
||
const duffel = new Duffel({ token: 'mockToken' }) | ||
describe('Stays/Accommodation', () => { | ||
afterEach(() => { | ||
nock.cleanAll() | ||
}) | ||
|
||
it('should post to /stays/suggestions when `suggestions` is called', async () => { | ||
const query = 'rits' | ||
const mockResponse = { data: [MOCK_ACCOMMODATION_SUGGESTION] } | ||
|
||
nock(/(.*)/) | ||
.post('/stays/accommodation/suggestions', (body) => { | ||
expect(body.data.query).toEqual(query) | ||
return true | ||
}) | ||
.reply(200, mockResponse) | ||
|
||
const response = await duffel.stays.accommodation.suggestions(query) | ||
expect(response.data).toEqual(mockResponse.data) | ||
}) | ||
}) |
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,31 @@ | ||
import { Client } from '../../Client' | ||
import { StaysAccommodationSuggestion } from '../StaysTypes' | ||
import { Resource } from '../../Resource' | ||
import { DuffelResponse } from '../../types' | ||
|
||
export class Accommodation extends Resource { | ||
/** | ||
* Endpoint path | ||
*/ | ||
path: string | ||
|
||
constructor(client: Client) { | ||
super(client) | ||
this.path = 'stays/accommodation' | ||
} | ||
|
||
/** | ||
* Create a booking | ||
* @param {object} payload - The booking payload, including quote id and guest information | ||
*/ | ||
public suggestions = async ( | ||
query: string, | ||
): Promise<DuffelResponse<StaysAccommodationSuggestion[]>> => | ||
this.request({ | ||
method: 'POST', | ||
path: `${this.path}/suggestions`, | ||
data: { | ||
query: query, | ||
}, | ||
}) | ||
} |
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 @@ | ||
export * from './Accommodation' |
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