Skip to content

Commit

Permalink
chore(datastore): refactor integration tests with v2 schema models (#…
Browse files Browse the repository at this point in the history
…1246)

* Commit changes automatically made by IDE

* chore(datastore): refactor integration tests with v2 schema models

* Apply suggestions from code review to fix typos

Co-authored-by: Chris F <[email protected]>

* Resolve comments

* Remove redundant tests

Co-authored-by: Chris F <[email protected]>
  • Loading branch information
HuiSF and cshfang authored Jan 14, 2022
1 parent ee357c1 commit ce28ad7
Show file tree
Hide file tree
Showing 66 changed files with 6,481 additions and 5,461 deletions.
253 changes: 82 additions & 171 deletions packages/amplify_datastore/example/integration_test/model_type_test.dart

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import '../../utils/setup_utils.dart';
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

group('type AWS Date', () {
group('type AWSDate', () {
// dates users for all tests
var dates = [
DateTime.fromMillisecondsSinceEpoch(0),
Expand All @@ -38,11 +38,13 @@ void main() {
];

// models used for all tests
var models =
dates.map((date) => DateTypeModel(value: TemporalDate(date))).toList();
var models = dates
.map((date) =>
ModelWithAppsyncScalarTypes(awsDateValue: TemporalDate(date)))
.toList();

// distinct list of values in the test models
var values = models.map((e) => e.value!).toSet().toList();
var values = models.map((e) => e.awsDateValue!).toSet().toList();

setUpAll(() async {
await configureDataStore();
Expand All @@ -55,9 +57,9 @@ void main() {
// test against all values
for (var value in values) {
var expectedModels =
models.where((model) => model.value == value).toList();
await testQueryPredicate<DateTypeModel>(
queryPredicate: DateTypeModel.VALUE.eq(value),
models.where((model) => model.awsDateValue == value).toList();
await testQueryPredicate<ModelWithAppsyncScalarTypes>(
queryPredicate: ModelWithAppsyncScalarTypes.AWSDATEVALUE.eq(value),
expectedModels: expectedModels,
);
}
Expand All @@ -67,9 +69,9 @@ void main() {
// test against all values
for (var value in values) {
var expectedModels =
models.where((model) => model.value != value).toList();
await testQueryPredicate<DateTypeModel>(
queryPredicate: DateTypeModel.VALUE.ne(value),
models.where((model) => model.awsDateValue != value).toList();
await testQueryPredicate<ModelWithAppsyncScalarTypes>(
queryPredicate: ModelWithAppsyncScalarTypes.AWSDATEVALUE.ne(value),
expectedModels: expectedModels,
);
}
Expand All @@ -78,10 +80,11 @@ void main() {
testWidgets('lt()', (WidgetTester tester) async {
// test against all values
for (var value in values) {
var expectedModels =
models.where((model) => model.value!.compareTo(value) < 0).toList();
await testQueryPredicate<DateTypeModel>(
queryPredicate: DateTypeModel.VALUE.lt(value),
var expectedModels = models
.where((model) => model.awsDateValue!.compareTo(value) < 0)
.toList();
await testQueryPredicate<ModelWithAppsyncScalarTypes>(
queryPredicate: ModelWithAppsyncScalarTypes.AWSDATEVALUE.lt(value),
expectedModels: expectedModels,
);
}
Expand All @@ -91,10 +94,10 @@ void main() {
// test against all values
for (var value in values) {
var expectedModels = models
.where((model) => model.value!.compareTo(value) <= 0)
.where((model) => model.awsDateValue!.compareTo(value) <= 0)
.toList();
await testQueryPredicate<DateTypeModel>(
queryPredicate: DateTypeModel.VALUE.le(value),
await testQueryPredicate<ModelWithAppsyncScalarTypes>(
queryPredicate: ModelWithAppsyncScalarTypes.AWSDATEVALUE.le(value),
expectedModels: expectedModels,
);
}
Expand All @@ -103,10 +106,11 @@ void main() {
testWidgets('gt()', (WidgetTester tester) async {
// test against all values
for (var value in values) {
var expectedModels =
models.where((model) => model.value!.compareTo(value) > 0).toList();
await testQueryPredicate<DateTypeModel>(
queryPredicate: DateTypeModel.VALUE.gt(value),
var expectedModels = models
.where((model) => model.awsDateValue!.compareTo(value) > 0)
.toList();
await testQueryPredicate<ModelWithAppsyncScalarTypes>(
queryPredicate: ModelWithAppsyncScalarTypes.AWSDATEVALUE.gt(value),
expectedModels: expectedModels,
);
}
Expand All @@ -116,28 +120,29 @@ void main() {
// test against all values
for (var value in values) {
var expectedModels = models
.where((model) => model.value!.compareTo(value) >= 0)
.where((model) => model.awsDateValue!.compareTo(value) >= 0)
.toList();
await testQueryPredicate<DateTypeModel>(
queryPredicate: DateTypeModel.VALUE.ge(value),
await testQueryPredicate<ModelWithAppsyncScalarTypes>(
queryPredicate: ModelWithAppsyncScalarTypes.AWSDATEVALUE.ge(value),
expectedModels: expectedModels,
);
}
});

testWidgets('between()', (WidgetTester tester) async {
// test with partial match
var partialMatchStart = models[1].value!;
var partialMatchEnd = models[3].value!;
var partialMatchStart = models[1].awsDateValue!;
var partialMatchEnd = models[3].awsDateValue!;
var rangeMatchModels = models
.where((model) => model.value!.compareTo(partialMatchStart) >= 0)
.where((model) => model.value!.compareTo(partialMatchEnd) <= 0)
.where(
(model) => model.awsDateValue!.compareTo(partialMatchStart) >= 0)
.where((model) => model.awsDateValue!.compareTo(partialMatchEnd) <= 0)
.toList();

// verify that the test is testing a partial match
expect(rangeMatchModels.length, greaterThanOrEqualTo(1));
await testQueryPredicate<DateTypeModel>(
queryPredicate: DateTypeModel.VALUE.between(
await testQueryPredicate<ModelWithAppsyncScalarTypes>(
queryPredicate: ModelWithAppsyncScalarTypes.AWSDATEVALUE.between(
partialMatchStart,
partialMatchEnd,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import '../../utils/setup_utils.dart';
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

group('type AWS DateTime', () {
group('type AWSDateTime', () {
// dates users for all tests
var dates = [
DateTime.fromMillisecondsSinceEpoch(0),
Expand All @@ -44,11 +44,12 @@ void main() {

// models used for all tests
var models = dates
.map((date) => DateTimeTypeModel(value: TemporalDateTime(date)))
.map((date) => ModelWithAppsyncScalarTypes(
awsDateTimeValue: TemporalDateTime(date)))
.toList();

// distinct list of values in the test models
var values = models.map((e) => e.value!).toSet().toList();
var values = models.map((e) => e.awsDateTimeValue!).toSet().toList();

setUpAll(() async {
await configureDataStore();
Expand All @@ -57,13 +58,15 @@ void main() {
await Amplify.DataStore.save(model);
}
});

testWidgets('eq()', (WidgetTester tester) async {
// test against all values
for (var value in values) {
var expectedModels =
models.where((model) => model.value == value).toList();
await testQueryPredicate<DateTimeTypeModel>(
queryPredicate: DateTimeTypeModel.VALUE.eq(value),
models.where((model) => model.awsDateTimeValue == value).toList();
await testQueryPredicate<ModelWithAppsyncScalarTypes>(
queryPredicate:
ModelWithAppsyncScalarTypes.AWSDATETIMEVALUE.eq(value),
expectedModels: expectedModels,
);
}
Expand All @@ -73,9 +76,10 @@ void main() {
// test against all values
for (var value in values) {
var expectedModels =
models.where((model) => model.value != value).toList();
await testQueryPredicate<DateTimeTypeModel>(
queryPredicate: DateTimeTypeModel.VALUE.ne(value),
models.where((model) => model.awsDateTimeValue != value).toList();
await testQueryPredicate<ModelWithAppsyncScalarTypes>(
queryPredicate:
ModelWithAppsyncScalarTypes.AWSDATETIMEVALUE.ne(value),
expectedModels: expectedModels,
);
}
Expand All @@ -84,10 +88,12 @@ void main() {
testWidgets('lt()', (WidgetTester tester) async {
// test against all values
for (var value in values) {
var expectedModels =
models.where((model) => model.value!.compareTo(value) < 0).toList();
await testQueryPredicate<DateTimeTypeModel>(
queryPredicate: DateTimeTypeModel.VALUE.lt(value),
var expectedModels = models
.where((model) => model.awsDateTimeValue!.compareTo(value) < 0)
.toList();
await testQueryPredicate<ModelWithAppsyncScalarTypes>(
queryPredicate:
ModelWithAppsyncScalarTypes.AWSDATETIMEVALUE.lt(value),
expectedModels: expectedModels,
);
}
Expand All @@ -97,10 +103,11 @@ void main() {
// test against all values
for (var value in values) {
var expectedModels = models
.where((model) => model.value!.compareTo(value) <= 0)
.where((model) => model.awsDateTimeValue!.compareTo(value) <= 0)
.toList();
await testQueryPredicate<DateTimeTypeModel>(
queryPredicate: DateTimeTypeModel.VALUE.le(value),
await testQueryPredicate<ModelWithAppsyncScalarTypes>(
queryPredicate:
ModelWithAppsyncScalarTypes.AWSDATETIMEVALUE.le(value),
expectedModels: expectedModels,
);
}
Expand All @@ -109,10 +116,12 @@ void main() {
testWidgets('gt()', (WidgetTester tester) async {
// test against all values
for (var value in values) {
var expectedModels =
models.where((model) => model.value!.compareTo(value) > 0).toList();
await testQueryPredicate<DateTimeTypeModel>(
queryPredicate: DateTimeTypeModel.VALUE.gt(value),
var expectedModels = models
.where((model) => model.awsDateTimeValue!.compareTo(value) > 0)
.toList();
await testQueryPredicate<ModelWithAppsyncScalarTypes>(
queryPredicate:
ModelWithAppsyncScalarTypes.AWSDATETIMEVALUE.gt(value),
expectedModels: expectedModels,
);
}
Expand All @@ -122,28 +131,31 @@ void main() {
// test against all values
for (var value in values) {
var expectedModels = models
.where((model) => model.value!.compareTo(value) >= 0)
.where((model) => model.awsDateTimeValue!.compareTo(value) >= 0)
.toList();
await testQueryPredicate<DateTimeTypeModel>(
queryPredicate: DateTimeTypeModel.VALUE.ge(value),
await testQueryPredicate<ModelWithAppsyncScalarTypes>(
queryPredicate:
ModelWithAppsyncScalarTypes.AWSDATETIMEVALUE.ge(value),
expectedModels: expectedModels,
);
}
});

testWidgets('between()', (WidgetTester tester) async {
// test with partial match
var partialMatchStart = models[1].value!;
var partialMatchEnd = models[3].value!;
var partialMatchStart = models[1].awsDateTimeValue!;
var partialMatchEnd = models[3].awsDateTimeValue!;
var rangeMatchModels = models
.where((model) => model.value!.compareTo(partialMatchStart) >= 0)
.where((model) => model.value!.compareTo(partialMatchEnd) <= 0)
.where((model) =>
model.awsDateTimeValue!.compareTo(partialMatchStart) >= 0)
.where((model) =>
model.awsDateTimeValue!.compareTo(partialMatchEnd) <= 0)
.toList();

// verify that the test is testing a partial match
expect(rangeMatchModels.length, greaterThanOrEqualTo(1));
await testQueryPredicate<DateTimeTypeModel>(
queryPredicate: DateTimeTypeModel.VALUE.between(
await testQueryPredicate<ModelWithAppsyncScalarTypes>(
queryPredicate: ModelWithAppsyncScalarTypes.AWSDATETIMEVALUE.between(
partialMatchStart,
partialMatchEnd,
),
Expand Down
Loading

0 comments on commit ce28ad7

Please sign in to comment.