Skip to content

Commit 2457704

Browse files
chore: remove DateTime.now() from tests (#1060)
* chore: remove datetime.now from datastore interface * chore: remove datetime.now from datastore unit tests * chore: remove datetime now from datastore integ tests
1 parent 0551d11 commit 2457704

File tree

7 files changed

+66
-60
lines changed

7 files changed

+66
-60
lines changed

packages/amplify_datastore/example/integration_test/model_type_test.dart

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ void main() {
144144
});
145145

146146
group('List<AWSDate>', () {
147-
var now = DateTime.now();
148-
var list =
149-
List.generate(3, (i) => TemporalDate(now.add(Duration(days: i))));
147+
var dateTime = DateTime.parse("2021-11-09T18:53:12.183540Z");
148+
var list = List.generate(
149+
3, (i) => TemporalDate(dateTime.add(Duration(days: i))));
150150
var models = List.generate(5, (_) => DateListTypeModel(value: list));
151151
testModelOperations(models: models);
152152
});
@@ -186,9 +186,9 @@ void main() {
186186
});
187187

188188
group('List<AWSDateTime>', () {
189-
var now = DateTime.now();
190-
var list =
191-
List.generate(3, (i) => TemporalDateTime(now.add(Duration(days: i))));
189+
var dateTime = DateTime.parse("2021-11-09T18:53:12.183540Z");
190+
var list = List.generate(
191+
3, (i) => TemporalDateTime(dateTime.add(Duration(days: i))));
192192
var models = List.generate(5, (_) => DateTimeListTypeModel(value: list));
193193
testModelOperations(models: models);
194194
});
@@ -224,9 +224,9 @@ void main() {
224224
});
225225

226226
group('List<AWSTime>', () {
227-
var now = DateTime.now();
228-
var list =
229-
List.generate(3, (i) => TemporalTime(now.add(Duration(days: i))));
227+
var dateTime = DateTime.parse("2021-11-09T18:53:12.183540Z");
228+
var list = List.generate(
229+
3, (i) => TemporalTime(dateTime.add(Duration(days: i))));
230230
var models = List.generate(5, (_) => TimeListTypeModel(value: list));
231231
testModelOperations(models: models);
232232
});
@@ -263,9 +263,9 @@ void main() {
263263
group(
264264
'List<AWSTimestamp>',
265265
() {
266-
var now = DateTime.now();
266+
var dateTime = DateTime.parse("2021-11-09T18:53:12.183540Z");
267267
var list = List.generate(
268-
3, (i) => TemporalTimestamp(now.add(Duration(days: i))));
268+
3, (i) => TemporalTimestamp(dateTime.add(Duration(days: i))));
269269
var models =
270270
List.generate(5, (_) => TimestampListTypeModel(value: list));
271271
testModelOperations(models: models);

packages/amplify_datastore/example/integration_test/query_test/standard_query_operations_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void main() {
7474
Post testPost = Post(
7575
title: 'test post',
7676
blog: testBlog,
77-
created: TemporalDateTime(DateTime.now()),
77+
created: TemporalDateTime.fromString("2021-11-09T18:53:12.183540Z"),
7878
rating: 10,
7979
);
8080
await Amplify.DataStore.save(testPost);

packages/amplify_datastore/test/amplify_datastore_delete_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ void main() {
6565
id: '4281dfba-96c8-4a38-9a8e-35c7e893ea47',
6666
title: 'test title',
6767
rating: 0,
68-
created: TemporalDateTime.now())),
68+
created:
69+
TemporalDateTime.fromString("2021-11-09T18:53:12.183540Z"))),
6970
throwsA(isA<DataStoreException>()
7071
.having((exception) => exception.message, 'message',
7172
'Delete failed for whatever known reason')

packages/amplify_datastore_plugin_interface/test/amplify_temporal_date_test.dart

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,30 @@ import 'package:flutter_test/flutter_test.dart';
1818

1919
void main() {
2020
test('AWSDate from DateTime success', () async {
21-
DateTime now = DateTime.now();
21+
DateTime dateTime = DateTime.parse("2021-11-09T18:53:12.183540Z");
2222

23-
TemporalDate awsDate = TemporalDate(now);
24-
now = now.toUtc();
23+
TemporalDate awsDate = TemporalDate(dateTime);
24+
dateTime = dateTime.toUtc();
2525

2626
expect(awsDate.getOffset(), null);
27-
expect(awsDate.getDateTime(), DateTime.utc(now.year, now.month, now.day));
28-
expect(awsDate.format(), now.toIso8601String().substring(0, 10));
27+
expect(awsDate.getDateTime(),
28+
DateTime.utc(dateTime.year, dateTime.month, dateTime.day));
29+
expect(awsDate.format(), dateTime.toIso8601String().substring(0, 10));
2930
});
3031

3132
test('AWSDate from DateTime with offset success', () async {
32-
DateTime now = DateTime.now();
33+
DateTime dateTime = DateTime.parse("2021-11-09T18:53:12.183540Z");
3334
Duration offset = Duration(hours: 3, minutes: 30);
3435

35-
TemporalDate awsDate = TemporalDate.withOffset(now, offset);
36+
TemporalDate awsDate = TemporalDate.withOffset(dateTime, offset);
3637

37-
now = now.toUtc();
38+
dateTime = dateTime.toUtc();
3839

3940
expect(awsDate.getOffset(), offset);
40-
expect(awsDate.getDateTime(), DateTime.utc(now.year, now.month, now.day));
41-
expect(awsDate.format(), now.toIso8601String().substring(0, 10) + "+03:30");
41+
expect(awsDate.getDateTime(),
42+
DateTime.utc(dateTime.year, dateTime.month, dateTime.day));
43+
expect(awsDate.format(),
44+
dateTime.toIso8601String().substring(0, 10) + "+03:30");
4245
});
4346

4447
test('AWSDate from string YYYY-MM-DD success', () async {
@@ -85,9 +88,9 @@ void main() {
8588
});
8689

8790
test('AWSDate with day Duration fails', () async {
91+
DateTime dateTime = DateTime.parse("2021-11-09T18:53:12.183540Z");
8892
Duration duration = Duration(days: 10, hours: 3, minutes: 30, seconds: 30);
89-
expect(() => TemporalDate.withOffset(DateTime.now(), duration),
90-
throwsException);
93+
expect(() => TemporalDate.withOffset(dateTime, duration), throwsException);
9194
});
9295

9396
test('AWSDate from string YYYY-MM fails', () async {

packages/amplify_datastore_plugin_interface/test/amplify_temporal_datetime_test.dart

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,27 @@ import 'package:flutter_test/flutter_test.dart';
1818

1919
void main() {
2020
test('AWSDateTime from DateTime success', () async {
21-
DateTime now = DateTime.now();
21+
DateTime dateTime = DateTime.parse("2021-11-09T18:53:12.183540Z");
2222

23-
TemporalDateTime time = TemporalDateTime(now);
24-
now = now.toUtc();
23+
TemporalDateTime time = TemporalDateTime(dateTime);
24+
dateTime = dateTime.toUtc();
2525

2626
expect(time.getOffset(), Duration());
27-
expect(time.getDateTimeInUtc(), now);
28-
expect(time.format(), now.toIso8601String().substring(0, 26) + "000Z");
27+
expect(time.getDateTimeInUtc(), dateTime);
28+
expect(time.format(), dateTime.toIso8601String().substring(0, 26) + "000Z");
2929
});
3030

3131
test('AWSDateTime from DateTime with offset success', () async {
32-
DateTime now = DateTime.now();
32+
DateTime dateTime = DateTime.parse("2021-11-09T18:53:12.183540Z");
3333
Duration offset = Duration(hours: 3, minutes: 30);
3434

35-
TemporalDateTime time = TemporalDateTime.withOffset(now, offset);
36-
now = now.toUtc();
35+
TemporalDateTime time = TemporalDateTime.withOffset(dateTime, offset);
36+
dateTime = dateTime.toUtc();
3737

3838
expect(time.getOffset(), offset);
39-
expect(time.getDateTimeInUtc(), now);
39+
expect(time.getDateTimeInUtc(), dateTime);
4040
expect(time.format(),
41-
now.toIso8601String().substring(0, 26) + "000" + "+03:30");
41+
dateTime.toIso8601String().substring(0, 26) + "000" + "+03:30");
4242
});
4343

4444
test('AWSDateTime from string YYYY-MM-DDThh:mmZ success', () async {
@@ -134,16 +134,16 @@ void main() {
134134
});
135135

136136
test('AWSDateTime from offset with single digit duration', () async {
137-
DateTime now = DateTime.now();
137+
DateTime dateTime = DateTime.parse("2021-11-09T18:53:12.183540Z");
138138
Duration offset = Duration(hours: 3, minutes: 3, seconds: 03);
139139

140-
TemporalDateTime time = TemporalDateTime.withOffset(now, offset);
141-
now = now.toUtc();
140+
TemporalDateTime time = TemporalDateTime.withOffset(dateTime, offset);
141+
dateTime = dateTime.toUtc();
142142

143143
expect(time.getOffset(), offset);
144-
expect(time.getDateTimeInUtc(), now);
144+
expect(time.getDateTimeInUtc(), dateTime);
145145
expect(time.format(),
146-
now.toIso8601String().substring(0, 26) + "000" + "+03:03:03");
146+
dateTime.toIso8601String().substring(0, 26) + "000" + "+03:03:03");
147147
});
148148

149149
test('AWSDateTime from string YYYY-MM-DDThh:mm fails', () async {

packages/amplify_datastore_plugin_interface/test/amplify_temporal_time_test.dart

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,33 @@ import 'package:flutter_test/flutter_test.dart';
1818

1919
void main() {
2020
test('AWSTime from DateTime success', () async {
21-
DateTime now = DateTime.now();
21+
DateTime dateTime = DateTime.parse("2021-11-09T18:53:12.183540Z");
2222

23-
TemporalTime time = TemporalTime(now);
24-
now = now.toUtc();
23+
TemporalTime time = TemporalTime(dateTime);
24+
dateTime = dateTime.toUtc();
2525

2626
expect(time.getOffset(), null);
2727
expect(
2828
time.getDateTime(),
29-
DateTime.utc(1970, 1, 1, now.hour, now.minute, now.second,
30-
now.millisecond, now.microsecond));
31-
expect(time.format(), now.toIso8601String().substring(11, 26) + "000");
29+
DateTime.utc(1970, 1, 1, dateTime.hour, dateTime.minute,
30+
dateTime.second, dateTime.millisecond, dateTime.microsecond));
31+
expect(time.format(), dateTime.toIso8601String().substring(11, 26) + "000");
3232
});
3333

3434
test('AWSTime from DateTime with offset success', () async {
35-
DateTime now = DateTime.now();
35+
DateTime dateTime = DateTime.parse("2021-11-09T18:53:12.183540Z");
3636
Duration offset = Duration(hours: 3, minutes: 30);
3737

38-
TemporalTime time = TemporalTime.withOffset(now, offset);
39-
now = now.toUtc();
38+
TemporalTime time = TemporalTime.withOffset(dateTime, offset);
39+
dateTime = dateTime.toUtc();
4040

4141
expect(time.getOffset(), offset);
4242
expect(
4343
time.getDateTime(),
44-
DateTime.utc(1970, 1, 1, now.hour, now.minute, now.second,
45-
now.millisecond, now.microsecond));
44+
DateTime.utc(1970, 1, 1, dateTime.hour, dateTime.minute,
45+
dateTime.second, dateTime.millisecond, dateTime.microsecond));
4646
expect(time.format(),
47-
now.toIso8601String().substring(11, 26) + "000" + "+03:30");
47+
dateTime.toIso8601String().substring(11, 26) + "000" + "+03:30");
4848
});
4949

5050
test('AWSDate from string hh:mm success', () async {

packages/amplify_datastore_plugin_interface/test/query_snapshot_test.dart

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import 'testData/ModelProvider.dart';
2020

2121
void main() {
2222
group('QuerySnapshot', () {
23+
TemporalDateTime _temporalDateTime =
24+
TemporalDateTime.fromString("2021-11-09T18:53:12.183540Z");
2325
group('withSubscriptionEvent()', () {
2426
group('with no query predicate or sort order', () {
2527
late List<Blog> blogs;
@@ -325,7 +327,7 @@ void main() {
325327
(index) => Post(
326328
title: 'post $index',
327329
rating: index * 10,
328-
created: TemporalDateTime.now(),
330+
created: _temporalDateTime,
329331
),
330332
);
331333
snapshot = QuerySnapshot(
@@ -341,7 +343,7 @@ void main() {
341343
Post newPost = Post(
342344
title: 'new post',
343345
rating: 25,
344-
created: TemporalDateTime.now(),
346+
created: _temporalDateTime,
345347
);
346348

347349
SubscriptionEvent<Post> subscriptionEvent = SubscriptionEvent(
@@ -401,7 +403,7 @@ void main() {
401403
Post updatedPost = Post(
402404
title: 'new post',
403405
rating: 25,
404-
created: TemporalDateTime.now(),
406+
created: _temporalDateTime,
405407
);
406408

407409
SubscriptionEvent<Post> subscriptionEvent = SubscriptionEvent(
@@ -435,7 +437,7 @@ void main() {
435437
(index) => Post(
436438
title: 'post $index',
437439
rating: index * 10,
438-
created: TemporalDateTime.now(),
440+
created: _temporalDateTime,
439441
),
440442
);
441443
snapshot = QuerySnapshot(
@@ -451,25 +453,25 @@ void main() {
451453
Post newPost1 = Post(
452454
title: 'new post a',
453455
rating: 25,
454-
created: TemporalDateTime.now(),
456+
created: _temporalDateTime,
455457
);
456458

457459
Post newPost2 = Post(
458460
title: 'new post a',
459461
rating: 40,
460-
created: TemporalDateTime.now(),
462+
created: _temporalDateTime,
461463
);
462464

463465
Post newPost3 = Post(
464466
title: 'new post b',
465467
rating: 25,
466-
created: TemporalDateTime.now(),
468+
created: _temporalDateTime,
467469
);
468470

469471
Post newPost4 = Post(
470472
title: 'new post b',
471473
rating: 40,
472-
created: TemporalDateTime.now(),
474+
created: _temporalDateTime,
473475
);
474476

475477
SubscriptionEvent<Post> subscriptionEvent1 = SubscriptionEvent(

0 commit comments

Comments
 (0)