Skip to content

Commit 3fa41a1

Browse files
committed
Fix bug while choosing rainProb
1 parent f8d939f commit 3fa41a1

File tree

2 files changed

+6
-16
lines changed

2 files changed

+6
-16
lines changed

src/Prediction.js

+1-16
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,7 @@ function getCurrentTmp(data) {
5252
}
5353

5454
function getCurrentRainProb(data) {
55-
if (data[0]['_'] !== undefined) {
56-
return data[0]['_'];
57-
}
58-
var hour = new Date().getHours();
59-
if (hour <= 6) {
60-
return data[3]['_'];
61-
}
62-
if (hour <= 12) {
63-
return data[4]['_'];
64-
}
65-
if (hour <= 18) {
66-
return data[5]['_'];
67-
}
68-
if (hour <= 24) {
69-
return data[6]['_'];
70-
}
55+
return data.find(data => data['_'] !== undefined)['_'];
7156
}
7257

7358
module.exports = Prediction;

test/index.test.js

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ describe('Meteosapi', () => {
1212
assert.notEqual(data.tomorrow, undefined, 'Data.tomorrow should be defined');
1313
assert.notEqual(data.next2, undefined, 'Data.next2 should be defined');
1414
assert.notEqual(data.forecast, undefined, 'Data. forecast be defined');
15+
assert.notEqual(data.today.rainProb, undefined, 'Rain probability should be defined for today');
16+
assert.notEqual(data.tomorrow.rainProb, undefined, 'Rain probability should be defined for tomorrow');
17+
assert.notEqual(data.next2.rainProb, undefined, 'Rain probability should be defined for next2');
1518
});
1619
});
1720
it('should return the simplified wheather', () => {
@@ -23,6 +26,8 @@ describe('Meteosapi', () => {
2326
assert.notEqual(data.next2, undefined, 'Data.next2 should be defined');
2427
assert.equal(data.forecast, undefined, 'Data.forecast should be defined');
2528
assert.notEqual(data.today.rainProb, undefined, 'Rain probability should be defined for today');
29+
assert.notEqual(data.tomorrow.rainProb, undefined, 'Rain probability should be defined for tomorrow');
30+
assert.notEqual(data.next2.rainProb, undefined, 'Rain probability should be defined for next2');
2631
});
2732
});
2833
});

0 commit comments

Comments
 (0)