Create typed_service_test.dart
This commit is contained in:
parent
d735528df9
commit
edd19d3d12
1 changed files with 66 additions and 0 deletions
66
test/typed_service_test.dart
Normal file
66
test/typed_service_test.dart
Normal file
|
@ -0,0 +1,66 @@
|
|||
import 'package:angel_framework/angel_framework.dart';
|
||||
import 'package:angel_framework/common.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'common.dart';
|
||||
|
||||
main() {
|
||||
var svc = new TypedService<Todo>(new MapService());
|
||||
|
||||
test('force model', () {
|
||||
expect(() => new TypedService<String>(null), throwsException);
|
||||
});
|
||||
|
||||
test('serialize', () {
|
||||
expect(svc.serialize({'foo': 'bar'}), {'foo': 'bar'});
|
||||
expect(
|
||||
svc.serialize([
|
||||
{'foo': 'bar'}
|
||||
]),
|
||||
[
|
||||
{'foo': 'bar'}
|
||||
]);
|
||||
expect(() => svc.serialize(2), throwsArgumentError);
|
||||
var now = new DateTime.now();
|
||||
var t =
|
||||
new Todo(text: 'a', completed: false, createdAt: now, updatedAt: now);
|
||||
var m = svc.serialize(t);
|
||||
print(m);
|
||||
expect(m..remove('_identityHashCode'), {
|
||||
'id': null,
|
||||
'createdAt': now.toIso8601String(),
|
||||
'updatedAt': now.toIso8601String(),
|
||||
'text': 'a',
|
||||
'completed': false
|
||||
});
|
||||
});
|
||||
|
||||
test('deserialize date', () {
|
||||
var now = new DateTime.now();
|
||||
var m = svc.deserialize({
|
||||
'createdAt': now.toIso8601String(),
|
||||
'updatedAt': now.toIso8601String()
|
||||
});
|
||||
expect(m, const IsInstanceOf<Todo>());
|
||||
var t = m as Todo;
|
||||
expect(t.createdAt.millisecondsSinceEpoch, now.millisecondsSinceEpoch);
|
||||
});
|
||||
|
||||
test('deserialize date w/ underscore', () {
|
||||
var now = new DateTime.now();
|
||||
var m = svc.deserialize({
|
||||
'created_at': now.toIso8601String(),
|
||||
'updated_at': now.toIso8601String()
|
||||
});
|
||||
expect(m, const IsInstanceOf<Todo>());
|
||||
var t = m as Todo;
|
||||
expect(t.createdAt.millisecondsSinceEpoch, now.millisecondsSinceEpoch);
|
||||
});
|
||||
}
|
||||
|
||||
class Todo extends Model {
|
||||
String text;
|
||||
bool completed;
|
||||
@override
|
||||
DateTime createdAt, updatedAt;
|
||||
Todo({this.text, this.completed, this.createdAt, this.updatedAt});
|
||||
}
|
Loading…
Reference in a new issue