Move mock WeatherProvider to weather.spec.ts
This commit is contained in:
@@ -5,6 +5,7 @@ import * as MockExpressResponse from 'mock-express-response';
|
|||||||
import * as MockDate from 'mockdate';
|
import * as MockDate from 'mockdate';
|
||||||
|
|
||||||
import { getWateringData } from './weather';
|
import { getWateringData } from './weather';
|
||||||
|
import { GeoCoordinates, WateringData, WeatherData, WeatherProvider } from "../types";
|
||||||
|
|
||||||
const expected = require( '../test/expected.json' );
|
const expected = require( '../test/expected.json' );
|
||||||
const replies = require( '../test/replies.json' );
|
const replies = require( '../test/replies.json' );
|
||||||
@@ -59,3 +60,41 @@ function mockOWM() {
|
|||||||
.get( "/" )
|
.get( "/" )
|
||||||
.reply( 200, replies[location].OWMData );
|
.reply( 200, replies[location].OWMData );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 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
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
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
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user