Test Fields
class
This commit is contained in:
parent
039f0b3443
commit
323ad807bd
4 changed files with 20 additions and 0 deletions
|
@ -79,6 +79,12 @@ main() {
|
|||
});
|
||||
});
|
||||
|
||||
test('fields', () {
|
||||
expect(BookFields.author, 'author');
|
||||
expect(BookFields.notModels, 'not_models');
|
||||
expect(BookFields.camelCaseString, 'camelCase');
|
||||
});
|
||||
|
||||
group('deserialization', () {
|
||||
test('deserialization sets proper fields', () {
|
||||
var book = BookSerializer.fromMap(deathlyHallowsMap);
|
||||
|
|
|
@ -10,4 +10,7 @@ abstract class _Book extends Model {
|
|||
String author, title, description;
|
||||
int pageCount;
|
||||
List<double> notModels;
|
||||
|
||||
@Alias('camelCase')
|
||||
String camelCaseString;
|
||||
}
|
|
@ -14,6 +14,7 @@ class Book extends _Book {
|
|||
this.description,
|
||||
this.pageCount,
|
||||
this.notModels,
|
||||
this.camelCaseString,
|
||||
this.createdAt,
|
||||
this.updatedAt});
|
||||
|
||||
|
@ -35,6 +36,9 @@ class Book extends _Book {
|
|||
@override
|
||||
final List<double> notModels;
|
||||
|
||||
@override
|
||||
final String camelCaseString;
|
||||
|
||||
@override
|
||||
final DateTime createdAt;
|
||||
|
||||
|
@ -48,6 +52,7 @@ class Book extends _Book {
|
|||
String description,
|
||||
int pageCount,
|
||||
List<double> notModels,
|
||||
String camelCaseString,
|
||||
DateTime createdAt,
|
||||
DateTime updatedAt}) {
|
||||
return new Book(
|
||||
|
@ -57,6 +62,7 @@ class Book extends _Book {
|
|||
description: description ?? this.description,
|
||||
pageCount: pageCount ?? this.pageCount,
|
||||
notModels: notModels ?? this.notModels,
|
||||
camelCaseString: camelCaseString ?? this.camelCaseString,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
updatedAt: updatedAt ?? this.updatedAt);
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ abstract class BookSerializer {
|
|||
String description,
|
||||
int pageCount,
|
||||
List<double> notModels,
|
||||
String camelCaseString,
|
||||
DateTime createdAt,
|
||||
DateTime updatedAt}) {
|
||||
return new Book(
|
||||
|
@ -23,6 +24,7 @@ abstract class BookSerializer {
|
|||
description: map['description'],
|
||||
pageCount: map['page_count'],
|
||||
notModels: map['not_models'],
|
||||
camelCaseString: map['camelCase'],
|
||||
createdAt: map['created_at'] != null
|
||||
? DateTime.parse(map['created_at'])
|
||||
: null,
|
||||
|
@ -39,6 +41,7 @@ abstract class BookSerializer {
|
|||
'description': model.description,
|
||||
'page_count': model.pageCount,
|
||||
'not_models': model.notModels,
|
||||
'camelCase': model.camelCaseString,
|
||||
'created_at': model.createdAt?.toIso8601String(),
|
||||
'updated_at': model.updatedAt?.toIso8601String()
|
||||
};
|
||||
|
@ -58,6 +61,8 @@ abstract class BookFields {
|
|||
|
||||
static const String notModels = 'not_models';
|
||||
|
||||
static const String camelCaseString = 'camelCase';
|
||||
|
||||
static const String createdAt = 'created_at';
|
||||
|
||||
static const String updatedAt = 'updated_at';
|
||||
|
|
Loading…
Reference in a new issue