Skip to content

Commit 1773eca

Browse files
authored
Remove convert price for hotel rate (#131)
* Remove convertPrice for hotel rate and fix test * Bump version * Update prod build * Remove convertPrice to selected currency in updateCurrency * Update prod build * Update travis config
1 parent 0b87177 commit 1773eca

File tree

8 files changed

+8
-116
lines changed

8 files changed

+8
-116
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
language: node_js
22
sudo: required
33
dist: trusty
4-
node_js: stable
4+
node_js:
5+
- 14
56
addons:
67
apt:
78
sources:

dist/WegoSdk.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "wego-sdk",
3-
"version": "1.4.8",
3+
"version": "1.5.0",
44
"description": "Wego SDK",
55
"main": "dist/WegoSdk.js",
66
"files": [

src/hotel-search/Merger.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,6 @@ HotelSearchClient.prototype = {
5050
updateCurrency: function (currency) {
5151
this.currency = currency;
5252

53-
var hotelMap = this.__hotelMap;
54-
for (var hotelId in hotelMap) {
55-
hotelMap[hotelId].rates.forEach(function (rate) {
56-
rate.price = dataUtils.convertPrice(rate.price, currency);
57-
});
58-
}
59-
this._cloneHotels(Object.keys(hotelMap));
60-
6153
var filter = this.__filter;
6254
filter.minPrice = dataUtils.convertPrice(filter.minPrice, currency);
6355
filter.maxPrice = dataUtils.convertPrice(filter.maxPrice, currency);
@@ -104,7 +96,7 @@ HotelSearchClient.prototype = {
10496
var self = this;
10597

10698
newRates.forEach(function (newRate) {
107-
dataUtils.prepareRate(newRate, self.currency, self.__staticData);
99+
dataUtils.prepareRateProvider(newRate, self.__staticData);
108100

109101
var hotelId = newRate.hotelId;
110102
var hotel = self.__hotelMap[hotelId];

src/hotel-search/dataUtils.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@ module.exports = {
5555
}
5656
},
5757

58-
prepareRate: function (rate, currency, staticData) {
58+
prepareRateProvider: function (rate, staticData) {
5959
rate.provider = staticData.providers[rate.providerCode];
60-
rate.price = this.convertPrice(rate.price, currency);
6160
},
6261

6362
convertPrice: function (price, currency) {

test/hotel-search/HotelSearchClient.spec.js

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -116,45 +116,6 @@ describe("HotelSearchClient", function () {
116116
expect(hotelIds).to.deep.equal([2]);
117117
});
118118

119-
it("#updateCurrency", function () {
120-
var hotels, filter;
121-
var client = new HotelSearchClient(hotelSearchEndpointUrl, {
122-
onHotelsChanged: function (_hotels) {
123-
hotels = _hotels;
124-
},
125-
onDisplayedFilterChanged: function (_filter) {
126-
filter = _filter;
127-
}
128-
});
129-
130-
mockAjaxCall(client);
131-
132-
var hotel = {
133-
id: 1
134-
};
135-
136-
client.handleSearchResponse({
137-
hotels: [hotel],
138-
rates: [
139-
{
140-
hotelId: 1,
141-
price: {
142-
currencyCode: "SGD",
143-
amount: 1000,
144-
amountUsd: 100
145-
}
146-
}
147-
]
148-
});
149-
150-
client.updateCurrency({
151-
code: "VND",
152-
rate: 2
153-
});
154-
155-
expect(hotels[0].rates[0].price.amount).to.equal(200);
156-
});
157-
158119
describe("#searchHotels", function () {
159120
it("start poller", function () {
160121
client.poller.timer = null;

test/hotel-search/Merger.spec.js

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -17,49 +17,6 @@ describe('Merger', function() {
1717
});
1818

1919
describe('#updateCurrency', function() {
20-
it('update hotel rate', function() {
21-
var hotel = {
22-
id: 1,
23-
};
24-
25-
var roomsCount = 1;
26-
var nightsCount = 2;
27-
var amountUsd = 10.15;
28-
var totalAmountUsd = amountUsd * roomsCount * nightsCount;
29-
30-
var rate = {
31-
hotelId: 1,
32-
price: {
33-
currencyCode: 'vnd',
34-
amountUsd: 10.15,
35-
totalAmountUsd: totalAmountUsd
36-
}
37-
};
38-
39-
var currency = {
40-
code: 'sgd',
41-
rate: 2,
42-
};
43-
44-
merger.mergeResponse({
45-
hotels: [hotel],
46-
rates: [rate]
47-
});
48-
49-
var oldHotels = merger.getHotels();
50-
var oldHotel = oldHotels[0];
51-
52-
merger.updateCurrency(currency);
53-
54-
var newHotels = merger.getHotels();
55-
var newHotel = newHotels[0];
56-
57-
expect(newHotel.rates[0].price.amount).to.equal(20);
58-
expect(newHotel.rates[0].price.totalAmount).to.equal(40);
59-
expect(newHotels).to.not.equal(oldHotels);
60-
expect(newHotel).to.not.equal(oldHotel);
61-
});
62-
6320
it('update minPrice', function() {
6421
merger.mergeResponse({
6522
filter: {

test/hotel-search/dataUtils.spec.js

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ describe('dataUtils', function() {
8585
})
8686
});
8787

88-
describe('#prepareRate', function() {
88+
describe('#prepareRateProvider', function() {
8989
it('provider', function() {
9090
var providerCode = 1;
9191
var provider = {
@@ -96,32 +96,14 @@ describe('dataUtils', function() {
9696
providerCode: providerCode,
9797
};
9898

99-
dataUtils.prepareRate(rate, {}, createStaticData({
99+
dataUtils.prepareRateProvider(rate, createStaticData({
100100
providers: {
101101
1: provider
102102
}
103103
}));
104104

105105
expect(rate.provider).to.equal(provider);
106106
});
107-
108-
it('price', function() {
109-
var rate = {
110-
price: {
111-
currencyCode: 'VND',
112-
amountUsd: 10,
113-
}
114-
};
115-
116-
var currency = {
117-
code: 'SGD',
118-
rate: 2
119-
};
120-
121-
dataUtils.prepareRate(rate, currency, createStaticData());
122-
123-
expect(rate.price.amount).to.equal(20);
124-
})
125107
});
126108

127109
describe('#convertPrice', function() {

0 commit comments

Comments
 (0)