forked from eatvio/eatvio_app
feat(tests): updated tests coverage to 66.5%
This commit is contained in:
@@ -189,5 +189,100 @@ void main() {
|
||||
expect(comment.authorName, 'John Doe');
|
||||
expect(comment.body, 'Test comment');
|
||||
});
|
||||
|
||||
test('toJson serializes Comment correctly', () {
|
||||
final comment = Comment(
|
||||
id: 1,
|
||||
authorName: 'John Doe',
|
||||
authorSlug: 'john-doe',
|
||||
authorProfileIcon: 'icon.jpg',
|
||||
body: 'Test comment body',
|
||||
childrenComments: [],
|
||||
createdAt: DateTime(2023, 1, 1),
|
||||
);
|
||||
|
||||
final json = comment.toJson();
|
||||
|
||||
expect(json['id'], 1);
|
||||
expect(json['author_name'], 'John Doe');
|
||||
expect(json['author_slug'], 'john-doe');
|
||||
expect(json['body'], 'Test comment body');
|
||||
expect(json['children_comments'], isA<List>());
|
||||
});
|
||||
|
||||
test('toJson serializes Comment with nested children correctly', () {
|
||||
final childComment = Comment(
|
||||
id: 2,
|
||||
authorName: 'Jane Smith',
|
||||
authorSlug: 'jane-smith',
|
||||
authorProfileIcon: 'icon2.jpg',
|
||||
body: 'Reply comment',
|
||||
childrenComments: [],
|
||||
createdAt: DateTime(2023, 1, 2),
|
||||
);
|
||||
|
||||
final parentComment = Comment(
|
||||
id: 1,
|
||||
authorName: 'John Doe',
|
||||
authorSlug: 'john-doe',
|
||||
authorProfileIcon: 'icon1.jpg',
|
||||
body: 'Parent comment',
|
||||
childrenComments: [childComment],
|
||||
createdAt: DateTime(2023, 1, 1),
|
||||
);
|
||||
|
||||
final json = parentComment.toJson();
|
||||
|
||||
expect(json['id'], 1);
|
||||
expect(json['children_comments'], isA<List>());
|
||||
expect((json['children_comments'] as List).length, 1);
|
||||
});
|
||||
});
|
||||
|
||||
group('CommentModel', () {
|
||||
test('toJson serializes CommentModel correctly', () {
|
||||
final comments = [
|
||||
Comment(
|
||||
id: 1,
|
||||
authorName: 'John Doe',
|
||||
authorSlug: 'john-doe',
|
||||
authorProfileIcon: 'icon1.jpg',
|
||||
body: 'First comment',
|
||||
childrenComments: [],
|
||||
createdAt: DateTime(2023, 1, 1),
|
||||
),
|
||||
];
|
||||
|
||||
const links = Links(
|
||||
first: 'http://example.com?page=1',
|
||||
last: 'http://example.com?page=1',
|
||||
prev: null,
|
||||
next: null,
|
||||
);
|
||||
|
||||
const meta = Meta(
|
||||
currentPage: 1,
|
||||
from: 1,
|
||||
lastPage: 1,
|
||||
links: [],
|
||||
path: '/api/comments',
|
||||
perPage: 10,
|
||||
to: 1,
|
||||
total: 1,
|
||||
);
|
||||
|
||||
final model = CommentModel(
|
||||
data: comments,
|
||||
links: links,
|
||||
meta: meta,
|
||||
);
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
expect(json.containsKey('data'), isTrue);
|
||||
expect(json.containsKey('links'), isTrue);
|
||||
expect(json.containsKey('meta'), isTrue);
|
||||
expect((json['data'] as List).length, 1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user