Skip to content

Commit

Permalink
Fix weatherobject tests
Browse files Browse the repository at this point in the history
  • Loading branch information
veeck committed Jan 26, 2023
1 parent 9301b62 commit e3c2290
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions modules/default/weather/weatherobject.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,12 @@ class WeatherObject {
* Determines if the sun sets or rises next. Uses the current time and not
* the date from the weather-forecast.
*
* @param {Moment} date an optional date where you want to get the next
* action for. Useful only in tests, defaults to the current time.
* @returns {string} "sunset" or "sunrise"
*/
nextSunAction() {
return moment().isBetween(this.sunrise, this.sunset) ? "sunset" : "sunrise";
nextSunAction(date = moment()) {
return date.isBetween(this.sunrise, this.sunset) ? "sunset" : "sunrise";
}

feelsLike() {
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/functions/weather_object_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ describe("WeatherObject", () => {
});

it("should return sunrise as the next sunaction", () => {
weatherobject.date = moment("00:00", "HH:mm");
weatherobject.updateSunTime(-6.774877582342688, 37.63345667023327);
expect(weatherobject.nextSunAction()).toBe("sunrise");
let midnight = moment("00:00", "HH:mm");
expect(weatherobject.nextSunAction(midnight)).toBe("sunrise");
});

it("should return sunset as the next sunaction", () => {
weatherobject.date = moment("12:00", "HH:mm");
weatherobject.updateSunTime(-6.774877582342688, 37.63345667023327);
expect(weatherobject.nextSunAction()).toBe("sunset");
let noon = moment(weatherobject.sunrise).hour(14);
expect(weatherobject.nextSunAction(noon)).toBe("sunset");
});

it("should return an already defined feelsLike info", () => {
Expand Down

0 comments on commit e3c2290

Please sign in to comment.