Skip to content

Commit 4912c9b

Browse files
author
Rostislav Wolny
committed
getHotels: Places added to filter
1 parent 778aa4d commit 4912c9b

File tree

4 files changed

+57
-11
lines changed

4 files changed

+57
-11
lines changed

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ export namespace Hotels {
327327
maxPrice?: number | null;
328328
minPrice?: number | null;
329329
minReviewScore?: number | null;
330+
places?: string[] | null;
330331
bounds?: Geo.Bounds | null;
331332
mapTileBounds?: string[] | null;
332333
stars?: number[] | null;

src/Hotels/DataAccess.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ describe('HotelsDataAccess', () => {
3030
const hotelsFilter: HotelsFilter = new HotelsFilter({
3131
adults: 2,
3232
checkIn: '2017-11-11',
33-
checkOut: '2017-11-12'
33+
checkOut: '2017-11-12',
34+
places: ['poi:1', 'poi:2']
3435
});
3536

3637
chai.expect(await Dao.getHotels(hotelsFilter))
3738
.to.deep.equal(HotelsResults.availableHotels);
3839
chai.expect(apiStub.callCount).to.equal(1);
39-
chai.expect(apiStub.getCall(0).args[0]).to.equal('hotels/list/?adults=2&check_in=2017-11-11&check_out=2017-11-12');
40+
chai.expect(apiStub.getCall(0).args[0])
41+
.to.equal('hotels/list/?adults=2&check_in=2017-11-11&check_out=2017-11-12&places=poi%3A1%7Cpoi%3A2');
4042
});
4143

4244
it('should use map tiles if bounds and zoom are passed', async () => {

src/Hotels/Filter.test.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,19 @@ describe('HotelsFilter', () => {
6262
};
6363
chai.expect(createFilter).to.throw('Adults count is mandatory.');
6464
});
65-
it('should raise error when bounds passed witn mapTileBounds', () => {
65+
it('should raise error on missing bounds', () => {
66+
const createFilter = () => {
67+
return new HotelsFilter({
68+
adults: 1,
69+
checkIn: '2017-11-11',
70+
checkOut: '2017-11-12',
71+
});
72+
};
73+
chai.expect(createFilter).to.throw(
74+
'Bounds, mapTileBounds and places have to be used exclusively and one of them has to be present.'
75+
);
76+
});
77+
it('should raise error when bounds passed with mapTileBounds', () => {
6678
const createFilter = () => {
6779
return new HotelsFilter({
6880
adults: 1,
@@ -77,14 +89,36 @@ describe('HotelsFilter', () => {
7789
mapTileBounds: ['1', '2']
7890
});
7991
};
80-
chai.expect(createFilter).to.throw('Bounds and mapTileBounds have to be used exclusively.');
92+
chai.expect(createFilter).to.throw(
93+
'Bounds, mapTileBounds and places have to be used exclusively and one of them has to be present.'
94+
);
95+
});
96+
it('should raise error when bounds passed with places', () => {
97+
const createFilter = () => {
98+
return new HotelsFilter({
99+
adults: 1,
100+
checkIn: '2017-11-11',
101+
checkOut: '2017-11-12',
102+
bounds: {
103+
south: 1,
104+
west: 2,
105+
north: 3,
106+
east: 4,
107+
},
108+
places: ['poi:1', 'poi:2']
109+
});
110+
};
111+
chai.expect(createFilter).to.throw(
112+
'Bounds, mapTileBounds and places have to be used exclusively and one of them has to be present.'
113+
);
81114
});
82115
it('should raise error when same dates are passed', () => {
83116
const createFilter = () => {
84117
return new HotelsFilter({
85118
adults: 1,
86119
checkIn: '2017-11-11',
87120
checkOut: '2017-11-11',
121+
mapTileBounds: ['123', '321'],
88122
});
89123
};
90124
chai.expect(createFilter).to.throw('Invalid checkIn/checkOut combination.');
@@ -95,6 +129,7 @@ describe('HotelsFilter', () => {
95129
adults: 1,
96130
checkIn: 'xxx',
97131
checkOut: 'fdfdfd',
132+
mapTileBounds: ['123', '321'],
98133
});
99134
};
100135
chai.expect(createFilter).to.throw('Invalid checkIn date.');
@@ -105,6 +140,7 @@ describe('HotelsFilter', () => {
105140
adults: 1,
106141
checkIn: '2017-11-11',
107142
checkOut: 'fdfdfd',
143+
places: ['poi:1'],
108144
});
109145
};
110146
chai.expect(createFilter).to.throw('Invalid checkOut date.');

src/Hotels/Filter.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface HotelsFilterJSON {
1010
maxPrice?: number | null;
1111
minPrice?: number | null;
1212
minReviewScore?: number | null;
13+
places?: string[] | null;
1314
bounds?: Bounds | null;
1415
mapTileBounds?: string[] | null;
1516
stars?: number[] | null;
@@ -29,6 +30,7 @@ export interface HotelsFilterQuery {
2930
max_price?: number;
3031
min_price?: number;
3132
min_review_score?: number;
33+
places?: string;
3234
bounds?: string;
3335
map_tile_bounds?: string;
3436
stars?: string;
@@ -48,15 +50,16 @@ export class HotelsFilter {
4850
protected _maxPrice?: number | null;
4951
protected _minPrice?: number | null;
5052
protected _minReviewScore?: number | null;
51-
private _bounds?: Bounds | null;
53+
protected _places?: string[] | null;
54+
protected _bounds?: Bounds | null;
5255
protected _mapTileBounds?: string[] | null;
5356
protected _stars?: number[] | null;
5457
protected _currency?: string | null;
5558
protected _propertyTypes?: string[] | null;
5659
protected _hotelFacilities?: string[] | null;
5760
protected _roomFacilities?: string[] | null;
5861
protected _limit?: number;
59-
private _zoom?: number;
62+
protected _zoom?: number;
6063

6164
constructor(filter: HotelsFilterJSON) {
6265
this._checkIn = filter.checkIn;
@@ -67,6 +70,7 @@ export class HotelsFilter {
6770
this._minPrice = filter.minPrice;
6871
this._minReviewScore = filter.minReviewScore;
6972
this._bounds = filter.bounds;
73+
this._places = filter.places;
7074
this._mapTileBounds = filter.mapTileBounds;
7175
this._stars = filter.stars;
7276
this._currency = filter.currency;
@@ -104,6 +108,9 @@ export class HotelsFilter {
104108
if (this._minReviewScore) {
105109
query.min_review_score = this._minReviewScore;
106110
}
111+
if (this._places) {
112+
query.places = this._places.join('|');
113+
}
107114
if (this._bounds) {
108115
query.bounds = this._bounds.south + ',' + this._bounds.west + ',' + this._bounds.north + ',' + this._bounds.east;
109116
}
@@ -146,8 +153,11 @@ export class HotelsFilter {
146153
}
147154

148155
private validate(): void {
149-
if (this._bounds && this._mapTileBounds) {
150-
throw new Error('Bounds and mapTileBounds have to be used exclusively.');
156+
if (!this._adults) {
157+
throw new Error('Adults count is mandatory.');
158+
}
159+
if ([this._bounds, this._mapTileBounds, this._places].filter((it) => it).length !== 1) {
160+
throw new Error('Bounds, mapTileBounds and places have to be used exclusively and one of them has to be present.');
151161
}
152162
const chInDate = new Date(this._checkIn);
153163
const chOutDate = new Date(this._checkOut);
@@ -160,8 +170,5 @@ export class HotelsFilter {
160170
if (chOutDate <= chInDate) {
161171
throw new Error('Invalid checkIn/checkOut combination.');
162172
}
163-
if (!this._adults) {
164-
throw new Error('Adults count is mandatory.');
165-
}
166173
}
167174
}

0 commit comments

Comments
 (0)