Skip to content

Commit

Permalink
small refactor to configure method
Browse files Browse the repository at this point in the history
  • Loading branch information
Equartey committed Jul 18, 2024
1 parent ddc5cee commit d9e68a2
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,14 @@ import 'package:integration_test/integration_test.dart';

import '../util.dart';

void main({bool useExistingTestUser = false, bool useGen2 = false}) {
void main({bool useExistingTestUser = false, bool useGen1 = false}) {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

group(
'GraphQL API key',
() {
setUpAll(() async {
if (useGen2) {
await configureAmplifyGen2();
} else {
await configureAmplify();
}
await configureAmplify(useGen1: useGen1);
await signOutTestUser();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,12 @@ const _limit = 10000;

const _max = 10000;

void main({bool useExistingTestUser = false, bool useGen2 = false}) {
void main({bool useExistingTestUser = false, bool useGen1 = false}) {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

group('GraphQL IAM', () {
setUpAll(() async {
if (useGen2) {
await configureAmplifyGen2();
} else {
await configureAmplify();
}
await configureAmplify(useGen1: useGen1);

if (!useExistingTestUser) {
await signUpTestUser();
Expand Down Expand Up @@ -361,7 +357,6 @@ void main({bool useExistingTestUser = false, bool useGen2 = false}) {
testWidgets(
'should GET a child and include parent with complex identifier and custom primary key',
(WidgetTester tester) async {
// TODO(equartey): remove when test is reliably skipped
const name = 'Integration Test CpkParent to fetch w child';
const explicitChildName = 'Explicit child name fetch test';
const implicitChildName = 'Implicit child name fetch test';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ import 'package:integration_test/integration_test.dart';

import '../util.dart';

void main({bool useExistingTestUser = false, bool useGen2 = false}) {
void main({bool useExistingTestUser = false, bool useGen1 = false}) {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

group('GraphQL Cognito User Pools', () {
setUpAll(() async {
if (useGen2) {
await configureAmplifyGen2();
} else {
await configureAmplify();
}
await configureAmplify(useGen1: useGen1);

if (!useExistingTestUser) {
await signUpTestUser();
}
Expand Down
22 changes: 14 additions & 8 deletions packages/api/amplify_api/example/integration_test/main_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void main() async {

group('amplify_api gen 1 config', () {
setUpAll(() async {
await configureAmplify();
await configureAmplify(useGen1: true);
await signUpTestUser();
await signInTestUser();
});
Expand All @@ -26,14 +26,23 @@ void main() async {
await Amplify.reset();
});

graph_api_key_test.main(useExistingTestUser: true);
graph_iam_test.main(useExistingTestUser: true);
graph_user_pools_test.main(useExistingTestUser: true);
graph_api_key_test.main(
useExistingTestUser: true,
useGen1: true,
);
graph_iam_test.main(
useExistingTestUser: true,
useGen1: true,
);
graph_user_pools_test.main(
useExistingTestUser: true,
useGen1: true,
);
});

group('amplify_api gen 2 config', () {
setUpAll(() async {
await configureAmplifyGen2();
await configureAmplify();
await signUpTestUser();
await signInTestUser();
});
Expand All @@ -45,15 +54,12 @@ void main() async {

graph_api_key_test.main(
useExistingTestUser: true,
useGen2: true,
);
graph_iam_test.main(
useExistingTestUser: true,
useGen2: true,
);
graph_user_pools_test.main(
useExistingTestUser: true,
useGen2: true,
);

rest_test.main(useExistingTestUser: true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void main({bool useExistingTestUser = false}) {

group('REST', () {
setUpAll(() async {
await configureAmplifyGen2();
await configureAmplify();

if (!useExistingTestUser) {
await signUpTestUser();
Expand Down
26 changes: 7 additions & 19 deletions packages/api/amplify_api/example/integration_test/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,7 @@ class TestUser {
}
}

Future<void> configureAmplify() async {
if (!Amplify.isConfigured) {
await Amplify.addPlugins([
AmplifyAuthCognito(
secureStorageFactory: AmplifySecureStorage.factoryFrom(
macOSOptions: MacOSSecureStorageOptions(useDataProtection: false),
),
),
AmplifyAPI(
options: APIPluginOptions(modelProvider: ModelProvider.instance),
),
]);
await Amplify.configure(gen1.amplifyConfig);
}
}

Future<void> configureAmplifyGen2() async {
Future<void> configureAmplify({bool useGen1 = false}) async {
if (!Amplify.isConfigured) {
await Amplify.addPlugins([
AmplifyAuthCognito(
Expand All @@ -105,8 +89,12 @@ Future<void> configureAmplifyGen2() async {
),
),
]);
final config = _addRestConfig(gen2.amplifyConfig);
await Amplify.configure(config);
if (useGen1) {
await Amplify.configure(gen1.amplifyConfig);
} else {
final config = _addRestConfig(gen2.amplifyConfig);
await Amplify.configure(config);
}
}
}

Expand Down

0 comments on commit d9e68a2

Please sign in to comment.