Skip to content

Commit

Permalink
chore(datastore): Add multi auth integration tests (#5204)
Browse files Browse the repository at this point in the history
  • Loading branch information
Equartey authored Sep 4, 2024
1 parent 6f7c254 commit 6aaf966
Show file tree
Hide file tree
Showing 33 changed files with 2,047 additions and 485 deletions.
12 changes: 10 additions & 2 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -540,12 +540,16 @@ updates:
- dependency-name: "worker_bee_builder"
- dependency-name: "amplify_datastore"
- dependency-name: "amplify_datastore_plugin_interface"
- dependency-name: "amplify_auth_cognito_dart"
- dependency-name: "amplify_auth_cognito"
- dependency-name: "amplify_analytics_pinpoint"
- dependency-name: "amplify_analytics_pinpoint_dart"
- dependency-name: "amplify_db_common_dart"
- dependency-name: "smithy"
- dependency-name: "smithy_aws"
- dependency-name: "amplify_db_common"
- dependency-name: "amplify_auth_cognito_dart"
- dependency-name: "smithy_codegen"
- dependency-name: "amplify_authenticator"
- package-ecosystem: "pub"
directory: "packages/amplify_datastore/example"
schedule:
Expand All @@ -569,12 +573,16 @@ updates:
- dependency-name: "worker_bee_builder"
- dependency-name: "amplify_datastore"
- dependency-name: "amplify_datastore_plugin_interface"
- dependency-name: "amplify_auth_cognito_dart"
- dependency-name: "amplify_auth_cognito"
- dependency-name: "amplify_analytics_pinpoint"
- dependency-name: "amplify_analytics_pinpoint_dart"
- dependency-name: "amplify_db_common_dart"
- dependency-name: "smithy"
- dependency-name: "smithy_aws"
- dependency-name: "amplify_db_common"
- dependency-name: "amplify_auth_cognito_dart"
- dependency-name: "smithy_codegen"
- dependency-name: "amplify_authenticator"
- package-ecosystem: "pub"
directory: "packages/amplify_datastore_plugin_interface"
schedule:
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/amplify_datastore_example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,34 @@ on:
- 'packages/amplify_datastore_plugin_interface/pubspec.yaml'
- 'packages/amplify_lints/lib/**/*.yaml'
- 'packages/amplify_lints/pubspec.yaml'
- 'packages/analytics/amplify_analytics_pinpoint/android/**/*'
- 'packages/analytics/amplify_analytics_pinpoint/lib/**/*.dart'
- 'packages/analytics/amplify_analytics_pinpoint/pubspec.yaml'
- 'packages/analytics/amplify_analytics_pinpoint_dart/lib/**/*.dart'
- 'packages/analytics/amplify_analytics_pinpoint_dart/pubspec.yaml'
- 'packages/api/amplify_api/lib/**/*.dart'
- 'packages/api/amplify_api/pubspec.yaml'
- 'packages/api/amplify_api_dart/lib/**/*.dart'
- 'packages/api/amplify_api_dart/pubspec.yaml'
- 'packages/auth/amplify_auth_cognito/android/**/*'
- 'packages/auth/amplify_auth_cognito/darwin/**/*'
- 'packages/auth/amplify_auth_cognito/lib/**/*.dart'
- 'packages/auth/amplify_auth_cognito/pubspec.yaml'
- 'packages/auth/amplify_auth_cognito_dart/lib/**/*.dart'
- 'packages/auth/amplify_auth_cognito_dart/pubspec.yaml'
- 'packages/authenticator/amplify_authenticator/lib/**/*.dart'
- 'packages/authenticator/amplify_authenticator/pubspec.yaml'
- 'packages/aws_common/lib/**/*.dart'
- 'packages/aws_common/pubspec.yaml'
- 'packages/aws_signature_v4/lib/**/*.dart'
- 'packages/aws_signature_v4/pubspec.yaml'
- 'packages/common/amplify_db_common/android/**/*'
- 'packages/common/amplify_db_common/ios/**/*'
- 'packages/common/amplify_db_common/lib/**/*.dart'
- 'packages/common/amplify_db_common/linux/**/*'
- 'packages/common/amplify_db_common/macos/**/*'
- 'packages/common/amplify_db_common/pubspec.yaml'
- 'packages/common/amplify_db_common/windows/**/*'
- 'packages/common/amplify_db_common_dart/lib/**/*.dart'
- 'packages/common/amplify_db_common_dart/pubspec.yaml'
- 'packages/secure_storage/amplify_secure_storage/android/**/*'
Expand Down Expand Up @@ -79,18 +95,34 @@ on:
- 'packages/amplify_datastore_plugin_interface/pubspec.yaml'
- 'packages/amplify_lints/lib/**/*.yaml'
- 'packages/amplify_lints/pubspec.yaml'
- 'packages/analytics/amplify_analytics_pinpoint/android/**/*'
- 'packages/analytics/amplify_analytics_pinpoint/lib/**/*.dart'
- 'packages/analytics/amplify_analytics_pinpoint/pubspec.yaml'
- 'packages/analytics/amplify_analytics_pinpoint_dart/lib/**/*.dart'
- 'packages/analytics/amplify_analytics_pinpoint_dart/pubspec.yaml'
- 'packages/api/amplify_api/lib/**/*.dart'
- 'packages/api/amplify_api/pubspec.yaml'
- 'packages/api/amplify_api_dart/lib/**/*.dart'
- 'packages/api/amplify_api_dart/pubspec.yaml'
- 'packages/auth/amplify_auth_cognito/android/**/*'
- 'packages/auth/amplify_auth_cognito/darwin/**/*'
- 'packages/auth/amplify_auth_cognito/lib/**/*.dart'
- 'packages/auth/amplify_auth_cognito/pubspec.yaml'
- 'packages/auth/amplify_auth_cognito_dart/lib/**/*.dart'
- 'packages/auth/amplify_auth_cognito_dart/pubspec.yaml'
- 'packages/authenticator/amplify_authenticator/lib/**/*.dart'
- 'packages/authenticator/amplify_authenticator/pubspec.yaml'
- 'packages/aws_common/lib/**/*.dart'
- 'packages/aws_common/pubspec.yaml'
- 'packages/aws_signature_v4/lib/**/*.dart'
- 'packages/aws_signature_v4/pubspec.yaml'
- 'packages/common/amplify_db_common/android/**/*'
- 'packages/common/amplify_db_common/ios/**/*'
- 'packages/common/amplify_db_common/lib/**/*.dart'
- 'packages/common/amplify_db_common/linux/**/*'
- 'packages/common/amplify_db_common/macos/**/*'
- 'packages/common/amplify_db_common/pubspec.yaml'
- 'packages/common/amplify_db_common/windows/**/*'
- 'packages/common/amplify_db_common_dart/lib/**/*.dart'
- 'packages/common/amplify_db_common_dart/pubspec.yaml'
- 'packages/secure_storage/amplify_secure_storage/android/**/*'
Expand Down
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)));
},
);
});
});
}
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;
}
Loading

0 comments on commit 6aaf966

Please sign in to comment.