Add mock WeatherProvider
This commit is contained in:
38
routes/weatherProviders/mock.ts
Normal file
38
routes/weatherProviders/mock.ts
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import { GeoCoordinates, WateringData, WeatherData, WeatherProvider } from "../../types";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A WeatherProvider for testing purposes that returns weather data that is provided in the constructor.
|
||||||
|
* This is a special WeatherProvider designed for testing purposes and should not be activated using the
|
||||||
|
* WEATHER_PROVIDER environment variable.
|
||||||
|
*/
|
||||||
|
export default class MockWeatherProvider implements WeatherProvider{
|
||||||
|
|
||||||
|
private readonly mockData: MockWeatherData;
|
||||||
|
|
||||||
|
public constructor(mockData: MockWeatherData) {
|
||||||
|
this.mockData = mockData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getWateringData( coordinates: GeoCoordinates ): Promise< WateringData > {
|
||||||
|
const data = this.mockData.wateringData;
|
||||||
|
if ( !data.weatherProvider ) {
|
||||||
|
data.weatherProvider = "mock";
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getWeatherData( coordinates: GeoCoordinates ): Promise< WeatherData > {
|
||||||
|
const data = this.mockData.weatherData;
|
||||||
|
if ( !data.weatherProvider ) {
|
||||||
|
data.weatherProvider = "mock";
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface MockWeatherData {
|
||||||
|
wateringData?: WateringData,
|
||||||
|
weatherData?: WeatherData
|
||||||
|
}
|
||||||
2
types.ts
2
types.ts
@@ -103,4 +103,4 @@ export interface WeatherProvider {
|
|||||||
getWeatherData?( coordinates : GeoCoordinates ): Promise< WeatherData >;
|
getWeatherData?( coordinates : GeoCoordinates ): Promise< WeatherData >;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type WeatherProviderId = "OWM" | "DarkSky" | "local";
|
export type WeatherProviderId = "OWM" | "DarkSky" | "local" | "mock";
|
||||||
|
|||||||
Reference in New Issue
Block a user