Test Fields class

This commit is contained in:
Tobe O 2018-03-09 07:43:17 -05:00
parent 039f0b3443
commit 323ad807bd
4 changed files with 20 additions and 0 deletions

View file

@ -79,6 +79,12 @@ main() {
}); });
}); });
test('fields', () {
expect(BookFields.author, 'author');
expect(BookFields.notModels, 'not_models');
expect(BookFields.camelCaseString, 'camelCase');
});
group('deserialization', () { group('deserialization', () {
test('deserialization sets proper fields', () { test('deserialization sets proper fields', () {
var book = BookSerializer.fromMap(deathlyHallowsMap); var book = BookSerializer.fromMap(deathlyHallowsMap);

View file

@ -10,4 +10,7 @@ abstract class _Book extends Model {
String author, title, description; String author, title, description;
int pageCount; int pageCount;
List<double> notModels; List<double> notModels;
@Alias('camelCase')
String camelCaseString;
} }

View file

@ -14,6 +14,7 @@ class Book extends _Book {
this.description, this.description,
this.pageCount, this.pageCount,
this.notModels, this.notModels,
this.camelCaseString,
this.createdAt, this.createdAt,
this.updatedAt}); this.updatedAt});
@ -35,6 +36,9 @@ class Book extends _Book {
@override @override
final List<double> notModels; final List<double> notModels;
@override
final String camelCaseString;
@override @override
final DateTime createdAt; final DateTime createdAt;
@ -48,6 +52,7 @@ class Book extends _Book {
String description, String description,
int pageCount, int pageCount,
List<double> notModels, List<double> notModels,
String camelCaseString,
DateTime createdAt, DateTime createdAt,
DateTime updatedAt}) { DateTime updatedAt}) {
return new Book( return new Book(
@ -57,6 +62,7 @@ class Book extends _Book {
description: description ?? this.description, description: description ?? this.description,
pageCount: pageCount ?? this.pageCount, pageCount: pageCount ?? this.pageCount,
notModels: notModels ?? this.notModels, notModels: notModels ?? this.notModels,
camelCaseString: camelCaseString ?? this.camelCaseString,
createdAt: createdAt ?? this.createdAt, createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt); updatedAt: updatedAt ?? this.updatedAt);
} }

View file

@ -14,6 +14,7 @@ abstract class BookSerializer {
String description, String description,
int pageCount, int pageCount,
List<double> notModels, List<double> notModels,
String camelCaseString,
DateTime createdAt, DateTime createdAt,
DateTime updatedAt}) { DateTime updatedAt}) {
return new Book( return new Book(
@ -23,6 +24,7 @@ abstract class BookSerializer {
description: map['description'], description: map['description'],
pageCount: map['page_count'], pageCount: map['page_count'],
notModels: map['not_models'], notModels: map['not_models'],
camelCaseString: map['camelCase'],
createdAt: map['created_at'] != null createdAt: map['created_at'] != null
? DateTime.parse(map['created_at']) ? DateTime.parse(map['created_at'])
: null, : null,
@ -39,6 +41,7 @@ abstract class BookSerializer {
'description': model.description, 'description': model.description,
'page_count': model.pageCount, 'page_count': model.pageCount,
'not_models': model.notModels, 'not_models': model.notModels,
'camelCase': model.camelCaseString,
'created_at': model.createdAt?.toIso8601String(), 'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String() 'updated_at': model.updatedAt?.toIso8601String()
}; };
@ -58,6 +61,8 @@ abstract class BookFields {
static const String notModels = 'not_models'; static const String notModels = 'not_models';
static const String camelCaseString = 'camelCase';
static const String createdAt = 'created_at'; static const String createdAt = 'created_at';
static const String updatedAt = 'updated_at'; static const String updatedAt = 'updated_at';