Skip to content

Commit

Permalink
Cleanups and more unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
veeck committed Oct 20, 2022
1 parent 4094ebb commit b065241
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
4 changes: 2 additions & 2 deletions modules/default/weather/providers/weathergov.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ WeatherProvider.register("weathergov", {
const days = [];

// variable for date
let weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh);
let weather = new WeatherObject();
for (const forecast of forecasts) {
weather.date = moment(forecast.startTime.slice(0, 19));
if (forecast.windSpeed.search(" ") < 0) {
Expand All @@ -187,7 +187,7 @@ WeatherProvider.register("weathergov", {

days.push(weather);

weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh);
weather = new WeatherObject();
}

// push weather information to days array
Expand Down
1 change: 0 additions & 1 deletion tests/e2e/modules/weather_current_spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const moment = require("moment");
const helpers = require("../helpers/global-setup");
const weatherFunc = require("../helpers/weather-functions");

Expand Down
18 changes: 17 additions & 1 deletion tests/unit/functions/weather_object_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe("WeatherObject", () => {
beforeAll(() => {
originalTimeZone = moment.tz.guess();
moment.tz.setDefault("Africa/Dar_es_Salaam");
weatherobject = new WeatherObject("metric", "metric", "metric", true);
weatherobject = new WeatherObject();
});

it("should return true for daytime at noon", () => {
Expand All @@ -25,10 +25,26 @@ describe("WeatherObject", () => {
expect(weatherobject.isDayTime()).toBe(false);
});

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

it("should return sunset as the next sunaction", () => {
weatherobject.date = moment(14, "HH");
weatherobject.updateSunTime(-6.774877582342688, 37.63345667023327);
expect(weatherobject.nextSunAction()).toBe("sunset");
});

it("should convert windspeed correctly from mph to mps", () => {
expect(Math.round(weatherobject.convertWindToMetric(93.951324266285))).toBe(42);
});

it("should convert windspeed correctly from kmh to mps", () => {
expect(Math.round(weatherobject.convertWindToMs(151.2))).toBe(42);
});

it("should convert wind direction correctly from cardinal to value", () => {
expect(weatherobject.valueWindDirection("SSE")).toBe(157);
});
Expand Down

0 comments on commit b065241

Please sign in to comment.