feat: add many tests for calendarwebapp.jsonexport.JSONExporter

This commit is contained in:
Johannes Loher 2018-01-14 15:04:49 +01:00
parent 3f11970424
commit ad1a966c99
2 changed files with 129 additions and 6 deletions

View file

@ -60,13 +60,12 @@ private:
@Autowire EventStore eventStore;
public:
auto write() @system
auto write(in Date today = cast(Date) Clock.currTime) @system
{
import std.algorithm : each, map;
import std.range : array;
import std.format : format;
immutable today = cast(Date) Clock.currTime;
immutable todayName = "%s, %s. %s. %s".format(today.dayOfWeek.toGerString,
today.day, today.month.toGerString, today.year);
immutable todays = Todays(today.year, today.month, today.day, today.dayOfWeek, todayName);

View file

@ -3,11 +3,12 @@ module test.calendarwebapp.testjsonexport;
import calendarwebapp.event;
import calendarwebapp.jsonexport;
import poodinis;
import core.exception : AssertError;
import poodinis;
import std.algorithm.iteration : each;
import std.conv : to;
import std.datetime.date : Date, Month;
import std.exception : enforce;
import std.range.interfaces : InputRange, inputRangeObject;
@ -15,7 +16,7 @@ import std.range.primitives : empty;
import unit_threaded;
@("JSONExporter.empty")
@("JSONExporter.write with 0 events")
@system unittest
{
auto container = new shared DependencyContainer();
@ -25,7 +26,7 @@ import unit_threaded;
exporter.write.each!(dayData => dayData.eventList.empty.shouldBeTrue);
}
@("JSONExporter.1 event")
@("JSONExporter.write with 1 event")
@system unittest
{
auto container = new shared DependencyContainer();
@ -40,6 +41,129 @@ import unit_threaded;
: dayData.eventList.empty.shouldBeTrue);
}
@("JSONExporter.write with 2 events at the same date")
@system unittest
{
auto container = new shared DependencyContainer();
container.register!(EventStore, StubEventStore);
container.register!JSONExporter;
auto exporter = container.resolve!JSONExporter;
auto eventStore = container.resolve!EventStore;
immutable event1 = Event("599090de97355141140fc698", Date(2018, 1, 14));
immutable event2 = Event("59cb9ad8fc0ba5751c0df02b", Date(2018, 1, 14));
eventStore.addEvent(event1);
eventStore.addEvent(event2);
exporter.write(Date(2018, 1, 14)).each!(dayData => (dayData.year == 2018
&& dayData.month == Month.jan && dayData.day == 14) ? dayData.eventList.shouldEqual([event1,
event2]) : dayData.eventList.empty.shouldBeTrue);
}
@("JSONExporter.write with 2 events at different dates")
@system unittest
{
auto container = new shared DependencyContainer();
container.register!(EventStore, StubEventStore);
container.register!JSONExporter;
auto exporter = container.resolve!JSONExporter;
auto eventStore = container.resolve!EventStore;
immutable event1 = Event("599090de97355141140fc698", Date(2018, 1, 14));
immutable event2 = Event("59cb9ad8fc0ba5751c0df02b", Date(2018, 1, 15));
eventStore.addEvent(event1);
eventStore.addEvent(event2);
exporter.write(Date(2018, 1, 14)).each!((dayData) {
immutable date = Date(dayData.year, dayData.month.to!int, dayData.day);
if (date == Date(2018, 1, 14))
{
dayData.eventList.shouldEqual([event1]);
}
else if (date == Date(2018, 1, 15))
{
dayData.eventList.shouldEqual([event2]);
}
else
{
dayData.eventList.empty.shouldBeTrue;
}
});
}
@("JSONExporter.write check date inbetween begin and end")
@system unittest
{
auto container = new shared DependencyContainer();
container.register!(EventStore, StubEventStore);
container.register!JSONExporter;
auto exporter = container.resolve!JSONExporter;
DayData(2018, Month.jan, "Januar", 14, DayType.Holiday, [], "Sonntag", []).shouldBeIn(
exporter.write(Date(2018, 1, 14)));
}
@("JSONExporter.write check date at begin")
@system unittest
{
auto container = new shared DependencyContainer();
container.register!(EventStore, StubEventStore);
container.register!JSONExporter;
auto exporter = container.resolve!JSONExporter;
DayData(2018, Month.jan, "Januar", 1, DayType.Workday, [], "Montag", []).shouldBeIn(
exporter.write(Date(2018, 1, 14)));
}
@("JSONExporter.write check date just after begin")
@system unittest
{
auto container = new shared DependencyContainer();
container.register!(EventStore, StubEventStore);
container.register!JSONExporter;
auto exporter = container.resolve!JSONExporter;
DayData(2018, Month.jan, "Januar", 2, DayType.Workday, [], "Dienstag", []).shouldBeIn(
exporter.write(Date(2018, 1, 14)));
}
@("JSONExporter.write check date before begin")
@system unittest
{
auto container = new shared DependencyContainer();
container.register!(EventStore, StubEventStore);
container.register!JSONExporter;
auto exporter = container.resolve!JSONExporter;
DayData(2017, Month.dec, "Dezember", 1, DayType.Holiday, [], "Sonntag", []).shouldNotBeIn(
exporter.write(Date(2018, 1, 14)));
}
@("JSONExporter.write check date at end")
@system unittest
{
auto container = new shared DependencyContainer();
container.register!(EventStore, StubEventStore);
container.register!JSONExporter;
auto exporter = container.resolve!JSONExporter;
DayData(2018, Month.mar, "März", 31, DayType.Weekend, [], "Samstag", []).shouldBeIn(
exporter.write(Date(2018, 1, 14)));
}
@("JSONExporter.write check date just before end")
@system unittest
{
auto container = new shared DependencyContainer();
container.register!(EventStore, StubEventStore);
container.register!JSONExporter;
auto exporter = container.resolve!JSONExporter;
DayData(2018, Month.mar, "März", 30, DayType.Workday, [], "Freitag", []).shouldBeIn(
exporter.write(Date(2018, 1, 14)));
}
@("JSONExporter.write check date after end")
@system unittest
{
auto container = new shared DependencyContainer();
container.register!(EventStore, StubEventStore);
container.register!JSONExporter;
auto exporter = container.resolve!JSONExporter;
DayData(2018, Month.apr, "April", 1, DayType.Holiday, [], "Sonntag", []).shouldNotBeIn(
exporter.write(Date(2018, 1, 14)));
}
@("DayJSONManager with begin > end")
@system unittest
{