diff --git a/test/data/model/user_test.dart b/test/data/model/user_test.dart index 1d87938..5ba06db 100644 --- a/test/data/model/user_test.dart +++ b/test/data/model/user_test.dart @@ -3,9 +3,9 @@ import 'package:flutter_bloc_advance/main/main_local.mapper.g.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { + final DateTime createdDate = DateTime(2024, 1, 1); late User userModel; User initUser() { - final createdDate = DateTime.now(); return User( id: '1', login: 'test_login', @@ -44,9 +44,9 @@ void main() { expect(finalUser.activated, true); expect(finalUser.langKey, 'en'); expect(finalUser.createdBy, 'admin'); - expect(finalUser.createdDate, DateTime(2021, 1, 1)); + expect(finalUser.createdDate, createdDate); expect(finalUser.lastModifiedBy, 'admin'); - expect(finalUser.lastModifiedDate, DateTime(2021, 1, 2)); + expect(finalUser.lastModifiedDate, createdDate); expect(finalUser.authorities, ['ROLE_USER']); }); @@ -66,14 +66,15 @@ void main() { expect(updatedUser.activated, true); expect(updatedUser.langKey, 'en'); expect(updatedUser.createdBy, 'admin'); - expect(updatedUser.createdDate, DateTime(2021, 1, 1)); + expect(updatedUser.createdDate, createdDate); expect(updatedUser.lastModifiedBy, 'admin'); - expect(updatedUser.lastModifiedDate, DateTime(2021, 1, 2)); + expect(updatedUser.lastModifiedDate, createdDate); expect(updatedUser.authorities, ['ROLE_USER']); }); test('should deserialize from JSON', () { - const json = { + final createdDateString = createdDate.toIso8601String(); + final json = { 'id': '1', 'login': 'test_login', 'firstName': 'John', @@ -82,9 +83,9 @@ void main() { 'activated': true, 'langKey': 'en', 'createdBy': 'admin', - 'createdDate': '2021-01-01T00:00:00.000Z', + 'createdDate': createdDateString, 'lastModifiedBy': 'admin', - 'lastModifiedDate': '2021-01-02T00:00:00.000Z', + 'lastModifiedDate': createdDateString, 'authorities': ['ROLE_USER'], }; @@ -98,16 +99,17 @@ void main() { expect(finalUser?.activated, true); expect(finalUser?.langKey, 'en'); expect(finalUser?.createdBy, 'admin'); - expect(finalUser?.createdDate, DateTime.parse('2021-01-01T00:00:00.000Z')); + expect(finalUser?.createdDate, createdDate); expect(finalUser?.lastModifiedBy, 'admin'); - expect(finalUser?.lastModifiedDate, DateTime.parse('2021-01-02T00:00:00.000Z')); + expect(finalUser?.lastModifiedDate, createdDate); expect(finalUser?.authorities, ['ROLE_USER']); }); test('should deserialize from JSON string', () { //postUserJson = await rootBundle.loadString(mockDataPath+postUserMockData); - const jsonString = ''' + final createdDateString = createdDate.toIso8601String(); + final jsonString = ''' { "id": "1", "login": "test_login", @@ -117,9 +119,9 @@ void main() { "activated": true, "langKey": "en", "createdBy": "admin", - "createdDate": "2021-01-01T00:00:00.000Z", + "createdDate": "$createdDateString", "lastModifiedBy": "admin", - "lastModifiedDate": "2021-01-02T00:00:00.000Z", + "lastModifiedDate": "$createdDateString", "authorities": ["ROLE_USER"] } '''; @@ -134,9 +136,9 @@ void main() { expect(finalUser?.activated, true); expect(finalUser?.langKey, 'en'); expect(finalUser?.createdBy, 'admin'); - expect(finalUser?.createdDate, DateTime.parse('2021-01-01T00:00:00.000Z')); + expect(finalUser?.createdDate, createdDate); expect(finalUser?.lastModifiedBy, 'admin'); - expect(finalUser?.lastModifiedDate, DateTime.parse('2021-01-02T00:00:00.000Z')); + expect(finalUser?.lastModifiedDate, createdDate); expect(finalUser?.authorities, ['ROLE_USER']); }); });