Fix serializer tests

* Map equality does not exist in Dart - how sucky!
* We no longer care about the micro-seconds
This commit is contained in:
Vishesh Handa
2019-01-18 15:37:19 +01:00
parent 7ba6f1eb77
commit f7e2253f55
2 changed files with 14 additions and 4 deletions

View File

@ -28,7 +28,7 @@ class Note implements Comparable {
if (json.containsKey("created")) {
var createdStr = json['created'].toString();
try {
created = DateTime.parse(json['created']);
created = DateTime.parse(json['created']).toLocal();
} catch (ex) {}
if (created == null) {
@ -37,7 +37,7 @@ class Note implements Comparable {
if (regex.hasMatch(createdStr)) {
// FIXME: Handle the timezone!
createdStr = createdStr.substring(0, 19);
created = DateTime.parse(json['created']);
created = DateTime.parse(createdStr);
}
}
@ -89,7 +89,12 @@ class Note implements Comparable {
id == other.id &&
body == other.body &&
created == other.created &&
extraProperties == other.extraProperties;
_equalMaps(extraProperties, other.extraProperties);
static bool _equalMaps(Map a, Map b) {
if (a.length != b.length) return false;
return a.keys.every((key) => b.containsKey(key) && a[key] == b[key]);
}
@override
String toString() {

View File

@ -3,10 +3,15 @@ import 'package:journal/storage/serializers.dart';
import 'package:test/test.dart';
DateTime nowWithoutMicro() {
var dt = DateTime.now();
return DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second);
}
main() {
group('Serializers', () {
var note =
Note(id: "2", body: "This is the body", created: new DateTime.now());
Note(id: "2", body: "This is the body", created: nowWithoutMicro());
test('JSON Serializer', () {
var serializer = new JsonNoteSerializer();