Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion defaultmodules/compliments/compliments.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ Module.register("compliments", {
timeOfDay = "evening";
}

if (timeOfDay && this.config.compliments.hasOwnProperty(timeOfDay)) {
if (this.config.compliments.hasOwnProperty(timeOfDay)) {
compliments = [...this.config.compliments[timeOfDay]];
}

Expand Down
14 changes: 6 additions & 8 deletions defaultmodules/weather/weatherutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,12 @@ const WeatherUtils = {

let imperialWeatherObject = { ...weatherObject };

if (imperialWeatherObject) {
if (imperialWeatherObject.feelsLikeTemp) imperialWeatherObject.feelsLikeTemp = this.convertTemp(imperialWeatherObject.feelsLikeTemp, "imperial");
if (imperialWeatherObject.maxTemperature) imperialWeatherObject.maxTemperature = this.convertTemp(imperialWeatherObject.maxTemperature, "imperial");
if (imperialWeatherObject.minTemperature) imperialWeatherObject.minTemperature = this.convertTemp(imperialWeatherObject.minTemperature, "imperial");
if (imperialWeatherObject.precipitationAmount) imperialWeatherObject.precipitationAmount = this.convertPrecipitationToInch(imperialWeatherObject.precipitationAmount, imperialWeatherObject.precipitationUnits);
if (imperialWeatherObject.temperature) imperialWeatherObject.temperature = this.convertTemp(imperialWeatherObject.temperature, "imperial");
if (imperialWeatherObject.windSpeed) imperialWeatherObject.windSpeed = this.convertWind(imperialWeatherObject.windSpeed, "imperial");
}
if ("feelsLikeTemp" in imperialWeatherObject) imperialWeatherObject.feelsLikeTemp = this.convertTemp(imperialWeatherObject.feelsLikeTemp, "imperial");
if ("maxTemperature" in imperialWeatherObject) imperialWeatherObject.maxTemperature = this.convertTemp(imperialWeatherObject.maxTemperature, "imperial");
if ("minTemperature" in imperialWeatherObject) imperialWeatherObject.minTemperature = this.convertTemp(imperialWeatherObject.minTemperature, "imperial");
if ("precipitationAmount" in imperialWeatherObject) imperialWeatherObject.precipitationAmount = this.convertPrecipitationToInch(imperialWeatherObject.precipitationAmount, imperialWeatherObject.precipitationUnits);
if ("temperature" in imperialWeatherObject) imperialWeatherObject.temperature = this.convertTemp(imperialWeatherObject.temperature, "imperial");
if ("windSpeed" in imperialWeatherObject) imperialWeatherObject.windSpeed = this.convertWind(imperialWeatherObject.windSpeed, "imperial");

return imperialWeatherObject;
}
Expand Down
47 changes: 47 additions & 0 deletions tests/unit/modules/default/weather/weather_utils_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,51 @@ describe("Weather utils tests", () => {
}
});
});

describe("convertWeatherObjectToImperial", () => {
it("should return null for null or empty input", () => {
expect(WeatherUtils.convertWeatherObjectToImperial(null)).toBeNull();
expect(WeatherUtils.convertWeatherObjectToImperial({})).toBeNull();
});

it("should convert 0°C correctly to 32°F", () => {
const result = WeatherUtils.convertWeatherObjectToImperial({ temperature: 0 });
expect(result.temperature).toBe(32);
});

it("should convert all temperature fields", () => {
const result = WeatherUtils.convertWeatherObjectToImperial({
temperature: 0,
feelsLikeTemp: 0,
minTemperature: -10,
maxTemperature: 10
});
expect(result.temperature).toBe(32);
expect(result.feelsLikeTemp).toBe(32);
expect(result.minTemperature).toBe(14);
expect(result.maxTemperature).toBe(50);
});

it("should convert windSpeed correctly", () => {
const result = WeatherUtils.convertWeatherObjectToImperial({ windSpeed: 10 });
expect(result.windSpeed).toBeCloseTo(22.369, 2);
});

it("should convert precipitationAmount correctly", () => {
const result = WeatherUtils.convertWeatherObjectToImperial({ precipitationAmount: 25.4, precipitationUnits: "mm" });
expect(result.precipitationAmount).toBeCloseTo(1, 5);
});

it("should not modify properties that are not present", () => {
const result = WeatherUtils.convertWeatherObjectToImperial({ temperature: 20 });
expect("windSpeed" in result).toBe(false);
expect("feelsLikeTemp" in result).toBe(false);
});

it("should not mutate the original object", () => {
const input = { temperature: 20 };
WeatherUtils.convertWeatherObjectToImperial(input);
expect(input.temperature).toBe(20);
});
});
});
Loading