-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(datastore): Add multi auth integration tests (#5204)
- Loading branch information
Showing
33 changed files
with
2,047 additions
and
485 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
195 changes: 195 additions & 0 deletions
195
.../example/integration_test/separate_integration_tests/basic_auth_model_operation_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import 'package:amplify_flutter/amplify_flutter.dart'; | ||
import 'package:amplify_integration_test/amplify_integration_test.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:integration_test/integration_test.dart'; | ||
|
||
import '../utils/setup_utils.dart'; | ||
import '../utils/test_cloud_synced_model_operation.dart'; | ||
import 'models/auth/ModelProvider.dart'; | ||
|
||
void main() { | ||
IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | ||
|
||
final enableCloudSync = shouldEnableCloudSync(); | ||
group( | ||
'Basic auth model operation${enableCloudSync ? ' with API sync 🌩 enabled' : ''} -', | ||
() { | ||
setUpAll(() async { | ||
await configureDataStore( | ||
enableCloudSync: enableCloudSync, | ||
modelProvider: ModelProvider.instance); | ||
}); | ||
tearDownAll(() async { | ||
if (enableCloudSync) { | ||
await deleteTestUser(testUser); | ||
} | ||
}); | ||
|
||
group("owner only auth model", () { | ||
PrivateTodo testPrivateTodo = PrivateTodo(content: 'test content'); | ||
testWidgets( | ||
'should save a new model ${enableCloudSync ? 'and sync to cloud' : ''}', | ||
(WidgetTester tester) async { | ||
if (enableCloudSync) { | ||
await testCloudSyncedModelOperation( | ||
rootModels: [testPrivateTodo], | ||
expectedRootModelVersion: 1, | ||
rootModelOperator: Amplify.DataStore.save, | ||
rootModelEventsAssertor: (events) { | ||
events.forEach((event) { | ||
expect(event.element.deleted, isFalse); | ||
}); | ||
}, | ||
); | ||
} else { | ||
await Amplify.DataStore.save(testPrivateTodo); | ||
} | ||
|
||
var queriedTodos = await Amplify.DataStore.query(PrivateTodo.classType); | ||
expect(queriedTodos, contains(testPrivateTodo)); | ||
}); | ||
|
||
testWidgets( | ||
'should update existing model ${enableCloudSync ? 'and sync to cloud' : ''}', | ||
(WidgetTester tester) async { | ||
var updatedTestTodo = | ||
testPrivateTodo.copyWith(content: "updated test todo"); | ||
|
||
if (enableCloudSync) { | ||
await testCloudSyncedModelOperation( | ||
rootModels: [updatedTestTodo], | ||
expectedRootModelVersion: 2, | ||
rootModelOperator: Amplify.DataStore.save, | ||
rootModelEventsAssertor: (events) { | ||
events.forEach((event) { | ||
expect(event.element.deleted, isFalse); | ||
}); | ||
}, | ||
); | ||
} else { | ||
await Amplify.DataStore.save(updatedTestTodo); | ||
} | ||
|
||
var queriedTodos = await Amplify.DataStore.query( | ||
PrivateTodo.classType, | ||
where: PrivateTodo.ID.eq(updatedTestTodo.id), | ||
); | ||
|
||
expect(queriedTodos, contains(updatedTestTodo)); | ||
}, | ||
); | ||
|
||
testWidgets( | ||
'should delete existing model ${enableCloudSync ? 'and sync to cloud' : ''}', | ||
(WidgetTester tester) async { | ||
if (enableCloudSync) { | ||
await testCloudSyncedModelOperation( | ||
rootModels: [testPrivateTodo], | ||
expectedRootModelVersion: 3, | ||
rootModelOperator: Amplify.DataStore.delete, | ||
rootModelEventsAssertor: (events) { | ||
events.forEach((event) { | ||
expect(event.element.deleted, isTrue); | ||
}); | ||
}, | ||
); | ||
} else { | ||
await Amplify.DataStore.delete(testPrivateTodo); | ||
} | ||
|
||
var queriedTodos = | ||
await Amplify.DataStore.query(PrivateTodo.classType); | ||
|
||
// verify Todo was deleted | ||
expect(queriedTodos, isNot(contains(testPrivateTodo))); | ||
}, | ||
); | ||
}); | ||
|
||
group("multi auth model", () { | ||
MultiAuthTodo testMultiAuthTodo = MultiAuthTodo(content: 'test content'); | ||
|
||
testWidgets( | ||
'should save a new model ${enableCloudSync ? 'and sync to cloud' : ''}', | ||
(WidgetTester tester) async { | ||
if (enableCloudSync) { | ||
await testCloudSyncedModelOperation( | ||
rootModels: [testMultiAuthTodo], | ||
expectedRootModelVersion: 1, | ||
rootModelOperator: Amplify.DataStore.save, | ||
rootModelEventsAssertor: (events) { | ||
events.forEach((event) { | ||
expect(event.element.deleted, isFalse); | ||
}); | ||
}, | ||
); | ||
} else { | ||
await Amplify.DataStore.save(testMultiAuthTodo); | ||
} | ||
|
||
var queriedTodos = | ||
await Amplify.DataStore.query(MultiAuthTodo.classType); | ||
expect(queriedTodos, contains(testMultiAuthTodo)); | ||
}); | ||
|
||
testWidgets( | ||
'should update existing model ${enableCloudSync ? 'and sync to cloud' : ''}', | ||
(WidgetTester tester) async { | ||
var updatedTestTodo = | ||
testMultiAuthTodo.copyWith(content: "updated test todo"); | ||
|
||
if (enableCloudSync) { | ||
await testCloudSyncedModelOperation( | ||
rootModels: [updatedTestTodo], | ||
expectedRootModelVersion: 2, | ||
rootModelOperator: Amplify.DataStore.save, | ||
rootModelEventsAssertor: (events) { | ||
events.forEach((event) { | ||
expect(event.element.deleted, isFalse); | ||
}); | ||
}, | ||
); | ||
} else { | ||
await Amplify.DataStore.save(updatedTestTodo); | ||
} | ||
|
||
var queriedTodos = await Amplify.DataStore.query( | ||
MultiAuthTodo.classType, | ||
where: MultiAuthTodo.ID.eq(updatedTestTodo.id), | ||
); | ||
|
||
expect(queriedTodos, contains(updatedTestTodo)); | ||
}, | ||
); | ||
|
||
testWidgets( | ||
'should delete existing model ${enableCloudSync ? 'and sync to cloud' : ''}', | ||
(WidgetTester tester) async { | ||
if (enableCloudSync) { | ||
await testCloudSyncedModelOperation( | ||
rootModels: [testMultiAuthTodo], | ||
expectedRootModelVersion: 3, | ||
rootModelOperator: Amplify.DataStore.delete, | ||
rootModelEventsAssertor: (events) { | ||
events.forEach((event) { | ||
expect(event.element.deleted, isTrue); | ||
}); | ||
}, | ||
); | ||
} else { | ||
await Amplify.DataStore.delete(testMultiAuthTodo); | ||
} | ||
|
||
var queriedTodos = | ||
await Amplify.DataStore.query(MultiAuthTodo.classType); | ||
|
||
// verify Todo was deleted | ||
expect(queriedTodos, isNot(contains(testMultiAuthTodo))); | ||
}, | ||
); | ||
}); | ||
}); | ||
} |
62 changes: 62 additions & 0 deletions
62
...astore/example/integration_test/separate_integration_tests/models/auth/ModelProvider.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
// NOTE: This file is generated and may not follow lint rules defined in your app | ||
// Generated files can be excluded from analysis in analysis_options.yaml | ||
// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis | ||
|
||
// ignore_for_file: public_member_api_docs, annotate_overrides, dead_code, dead_codepublic_member_api_docs, depend_on_referenced_packages, file_names, library_private_types_in_public_api, no_leading_underscores_for_library_prefixes, no_leading_underscores_for_local_identifiers, non_constant_identifier_names, null_check_on_nullable_type_parameter, override_on_non_overriding_member, prefer_adjacent_string_concatenation, prefer_const_constructors, prefer_if_null_operators, prefer_interpolation_to_compose_strings, slash_for_doc_comments, sort_child_properties_last, unnecessary_const, unnecessary_constructor_name, unnecessary_late, unnecessary_new, unnecessary_null_aware_assignments, unnecessary_nullable_for_final_variable_declarations, unnecessary_string_interpolations, use_build_context_synchronously | ||
|
||
import 'package:amplify_core/amplify_core.dart' as amplify_core; | ||
|
||
import '../../../../lib/models/MultiAuthTodo.dart'; | ||
import '../../../../lib/models/PrivateTodo.dart'; | ||
|
||
export '../../../../lib/models/MultiAuthTodo.dart'; | ||
export '../../../../lib/models/PrivateTodo.dart'; | ||
|
||
class ModelProvider implements amplify_core.ModelProviderInterface { | ||
@override | ||
String version = "44ab790c924e12028850f0fe58e4adb4"; | ||
@override | ||
List<amplify_core.ModelSchema> modelSchemas = [ | ||
MultiAuthTodo.schema, | ||
PrivateTodo.schema, | ||
]; | ||
@override | ||
List<amplify_core.ModelSchema> customTypeSchemas = []; | ||
static final ModelProvider _instance = ModelProvider(); | ||
|
||
static ModelProvider get instance => _instance; | ||
|
||
amplify_core.ModelType getModelTypeByModelName(String modelName) { | ||
switch (modelName) { | ||
case "MultiAuthTodo": | ||
return MultiAuthTodo.classType; | ||
case "PrivateTodo": | ||
return PrivateTodo.classType; | ||
default: | ||
throw Exception( | ||
"Failed to find model in model provider for model name: " + | ||
modelName); | ||
} | ||
} | ||
} | ||
|
||
class ModelFieldValue<T> { | ||
const ModelFieldValue.value(this.value); | ||
|
||
final T value; | ||
} |
Oops, something went wrong.