Unofficial Dart implementation of Deutsche Bahn’s construction site API
https://pub.dev/packages/db_construction_site
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.8 KiB
59 lines
1.8 KiB
import 'dart:convert';
|
|
|
|
import 'package:db_construction_site/models/connection.dart';
|
|
import 'package:db_construction_site/models/connection_type.dart';
|
|
import 'package:db_construction_site/models/region.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
void main() {
|
|
test('test if json parsing works as expected', () {
|
|
const exampleConnectionJsonString = """
|
|
{
|
|
"id": "3",
|
|
"name": "RE 17",
|
|
"kbnr": "430",
|
|
"von": "Warburg",
|
|
"verlauf": [
|
|
"Hagen Hbf",
|
|
"Arnsberg (Westf)",
|
|
"Meschede",
|
|
"Warburg (Westf)",
|
|
"Hofgeismar",
|
|
"Kassel-Wilhelmshöhe"
|
|
],
|
|
"nach": "Kassel",
|
|
"via": "",
|
|
"timestamp": "2018-11-16 05:15:43",
|
|
"verfall": "2018-12-02 23:15:00",
|
|
"verbindung": "regional",
|
|
"fern_id": null,
|
|
"land": "hessen",
|
|
"url": "https://bauinfos.deutschebahn.com/hessen/Strecke/430-Warburg-Kassel/3",
|
|
"ics": "https://bauinfos.deutschebahn.com/docs/hessen/ical-hessen-430.ics",
|
|
"doc": "https://bauinfos.deutschebahn.com/docs/hessen/430.pdf",
|
|
"meldungen": [],
|
|
"infos": []
|
|
}
|
|
""";
|
|
Map<String, dynamic> json;
|
|
try {
|
|
json = JsonDecoder().convert(exampleConnectionJsonString);
|
|
assert(json != null);
|
|
} catch (e) {
|
|
print("JSON decoding failed, skipping test.");
|
|
return;
|
|
}
|
|
final connection = Connection.fromJson(json);
|
|
expect(connection.id, "3");
|
|
expect(connection.name, "RE 17");
|
|
expect(connection.courseBookNumber, "430");
|
|
expect(connection.origin, "Warburg");
|
|
expect(connection.stops, contains("Hagen Hbf"));
|
|
expect(connection.destination, "Kassel");
|
|
expect(connection.via, "");
|
|
expect(connection.timestamp, DateTime(2018, 11, 16, 05, 15, 43));
|
|
expect(connection.expiryDate, DateTime(2018, 12, 02, 23, 15, 00));
|
|
expect(connection.type, ConnectionType.regional);
|
|
expect(connection.region, Region.hesse);
|
|
});
|
|
} |