mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-27 17:29:50 +08:00
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:
@ -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() {
|
||||
|
@ -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();
|
||||
|
Reference in New Issue
Block a user