Skip to content

Commit

Permalink
fix: Broken Auth Unit Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fjnoyp committed Jun 2, 2021
1 parent ec7fab7 commit 015cecf
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 14 deletions.
4 changes: 4 additions & 0 deletions packages/amplify_api/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import 'package:amplify_api_example/rest_api_view.dart';
import 'package:amplify_flutter/amplify.dart';
import 'package:flutter/material.dart';
import 'amplifyconfiguration.dart';
import 'package:amplify_auth_cognito/amplify_auth_cognito.dart';


void main() {
runApp(MyApp());
Expand All @@ -45,6 +47,8 @@ class _MyAppState extends State<MyApp> {
apiRest = AmplifyAPI();

Amplify.addPlugin(apiRest);
Amplify.addPlugin(AmplifyAuthCognito());

try {
await Amplify.configure(amplifyconfig);
} on AmplifyAlreadyConfiguredException {
Expand Down
3 changes: 3 additions & 0 deletions packages/amplify_api/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ dependencies:
flutter:
sdk: flutter

amplify_auth_cognito:
path: ../../amplify_auth_cognito

amplify_api:
# When depending on this package from a real application you should use:
# amplify_api: ^x.y.z
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,18 @@ class AmplifyAuthCognitoMethodChannel extends AmplifyAuthCognito {

UpdateUserAttributeResult _formatUpdateUserAttributeResponse(
Map<String, dynamic> res) {
var codeDeliveryDetails = res["nextStep"]["codeDeliveryDetails"];
return UpdateUserAttributeResult(
isUpdated: res["isUpdated"],
nextStep: AuthNextUpdateAttributeStep(
updateAttributeStep: res["nextStep"]["updateAttributeStep"],
codeDeliveryDetails: res["nextStep"]["codeDeliveryDetails"],
codeDeliveryDetails: codeDeliveryDetails != null
? AuthCodeDeliveryDetails(
attributeName: codeDeliveryDetails["attributeName"] ?? null,
deliveryMedium:
codeDeliveryDetails["deliveryMedium"] ?? null,
destination: codeDeliveryDetails["destination"])
: null,
additionalInfo: res["nextStep"]["additionalInfo"] is String
? jsonDecode(res["nextStep"]["additionalInfo"])
: {}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ void main() {
return true;
}
});
late AuthException err;
try {
await auth.confirmSignIn(
request: ConfirmSignInRequest(confirmationValue: "iAmNotLegit"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ void main() {
test('confirmUserAttribute thrown PlatFormException results in AuthError',
() async {
testCode = 2;
AuthException err;
try {
await auth.confirmUserAttribute(
request: ConfirmUserAttributeRequest(
Expand All @@ -71,8 +70,7 @@ void main() {
),
);
} on AuthException catch (e) {
err = e;
expect(e.message, "I am an exception");
}
expect(err.message, "I am an exception");
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,15 @@ void main() {
'resendUserAttributeConfirmationCode thrown PlatFormException results in AuthError',
() async {
testCode = 2;
AuthException err;
try {
await auth.resendUserAttributeConfirmationCode(
request: ResendUserAttributeConfirmationCodeRequest(
userAttributeKey: 'email',
),
);
} on AuthException catch (e) {
err = e;
expect(e.message, "I am an exception");
}
expect(err.message, "I am an exception");

});
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ void main() {
"isUpdated": true,
"nextStep": {
"updateAttributeStep": "DONE",
"codeDeliveryDetails": {"attributeName": "email"}
"codeDeliveryDetails": {
"attributeName": "email",
"destination": "[email protected]"
}
}
});
case 2:
Expand Down Expand Up @@ -82,7 +85,6 @@ void main() {
test('updateUserAttribute thrown PlatFormException results in AuthError',
() async {
testCode = 2;
AuthException err;
try {
await auth.updateUserAttribute(
request: UpdateUserAttributeRequest(
Expand All @@ -91,8 +93,7 @@ void main() {
),
);
} on AuthException catch (e) {
err = e;
expect(e.message, "I am an exception");
}
expect(err.message, "I am an exception");
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class AuthCodeDeliveryDetails {
String? attributeName;
String? deliveryMedium;
String destination;
late String destination;
AuthCodeDeliveryDetails(
{this.attributeName, this.deliveryMedium, required this.destination});
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class S3ListOptions extends ListOptions {
Map<String, dynamic> serializeAsMap() {
final Map<String, dynamic> optionsMap = <String, dynamic>{
'accessLevel': describeEnum(accessLevel),
'targetIdentifyId': targetIdentityId
'targetIdentityId': targetIdentityId
};
optionsMap.removeWhere((_, v) => v == null);
return optionsMap;
Expand Down

0 comments on commit 015cecf

Please sign in to comment.