Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(amplify_auth_cognito): interface changes, logs, tests #27

Merged
merged 24 commits into from
Aug 15, 2020

Conversation

haverchuck
Copy link
Member

Description of changes:
This PR introduces interface changes, flutter sdk version bump, platform logging, and android unit tests

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Comment on lines 68 to 76
doAnswer { invocation: InvocationOnMock ->
plugin.prepareSignUpResult(mockResult, mockSignUpResult)
null as Void?
}.`when`(mockAuth).confirmSignUp(anyString(), anyString(), ArgumentMatchers.any<Consumer<AuthSignUpResult>>(), ArgumentMatchers.any<Consumer<AuthException>>())

doAnswer { invocation: InvocationOnMock ->
plugin.prepareSignUpResult(mockResult, mockSignUpResult)
null as Void?
}.`when`(mockAuth).resendSignUpCode(anyString(), ArgumentMatchers.any<Consumer<AuthSignUpResult>>(), ArgumentMatchers.any<Consumer<AuthException>>())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of making all of these arrangements in the single seutp call, split these down into the individual @Test.

Each test should read like:

// Arrange
doAnswer { ...

// Act:
callYourChannelBindingStuff();

// Assert:
verify( /* a call was made on the amplify android mock object */);

One more note: it looks like mockAuth is an AuthCategory instance -- like Amplify Android's AuthCategory, right? While it may be technically possible to mock that, I would not. I would either:

  1. Use an AuthCategoryBehavior in your source code, which is an interface. Then, use a mock(AuthCategoryBeahvior::class.java) in your test code, to run mockito verify(...) calls on.
  2. **Use a real AuthCategory(), and do authCateogory.addPlugin(mockPlugin), where mockPlugin is a mock(AuthPlugin::class.java). Reason being: the AuthCategory is not designed to be extended, in fact I think it's a final class isnt' it? Whereas the AuthCategoryBehavior and AuthPlugin are deliberately designed to be extended, so creating a mock extension fits 100% with the source design.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to speak with the team about this larger change with the mocks, but the general organization suggestions you've made here I've completed.

Copy link
Contributor

@jamesonwilliams jamesonwilliams Aug 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, yea! Also, I believe you can factor away from the Amplify.StaticGizmo calls in a non-breaking way, after release.

By playing one of these games:

final class SomeClass {
    private final GizmoBehaviorInterface gizmo;

    // This is used in source code.
    SomeClass() {
        this(Amplify.StaticGizmo);
    }

    // This is used in test code.
    SomeClass(GizmoBehaviorInterface gizmo) {
        this.gizmo = gizmo;
    }
}

Comment on lines 28 to 30
import java.lang.Exception
import java.lang.reflect.Field
import java.lang.reflect.Modifier
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get rid of the reflection stuff. Don't set field state or anything like that. Respect the final keyword on our classes. I discuss approaches to ingest mock objects, below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to talk to the team about this, not gonna make this change right now. It'll impact other tests.

Copy link
Contributor

@skywardpixel skywardpixel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left two comments on gradle configs. I'll leave the other changes for @fjnoyp and @Ashish-Nanda to review.

@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.11-all.zip
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean 6.1.1? 6.1.11 doesn't seem to exist.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the error in circle ci told me to use this version

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just use the latest version, which right now is 6.6. Amplify Android just always uses the latest stable version.

README.md Show resolved Hide resolved
Comment on lines +329 to +336
let errorCode = error != nil ? "\(error!)" : "signedOut"
logErrorContents(messages: [localizedError, recoverySuggestion, errorCode])
formatError(flutterResult: flutterResult, errorCode: errorCode, msg: msg, localizedError: localizedError, recoverySuggestion: recoverySuggestion)
}
if case .sessionExpired(let localizedError, let recoverySuggestion, let error) = error {
let errorCode = error != nil ? "\(error!)" : "sessionExpired"
formatError(flutterResult: flutterResult, errorCode: errorCode, msg: msg, localizedError: localizedError, recoverySuggestion: recoverySuggestion)
let errorCode = error != nil ? "\(error!)" : "sessionExpired"
logErrorContents(messages: [localizedError, recoverySuggestion, errorCode])
formatError(flutterResult: flutterResult, errorCode: errorCode, msg: msg, localizedError: localizedError, recoverySuggestion: recoverySuggestion)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can call localizedError and recoverySuggestion on the underlying error right?

So can you do something like this:

var localizedError = error.localizedError;
var recoverySuggestion = error.recoverySuggestion;
var errorCode;
var messages = [ localizedError, recoverySuggestion ]

if case .signedOut(let localizedError, let recoverySuggestion, let error) = error {
errorCode = " ..... " : "SignedOut";
messages.Append(errorCode)
}
if case .sessionExpired(let localizedError, let recoverySuggestion, let error) = error {
...
}
....

logErrorContents(messages: messages)
formatError(flutterResult: ....... recoverySuggestion: recoverySuggestion)

Copy link
Contributor

@jamesonwilliams jamesonwilliams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@@ -18,21 +18,25 @@ package com.amazonaws.amplify.amplify_auth_cognito.types
import com.amplifyframework.auth.result.AuthSignUpResult
import com.google.gson.Gson

data class FlutterSignUpResult(private val raw: AuthSignUpResult) {
data class FlutterSignUpResult(private var raw: AuthSignUpResult) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you keep it as val?

@@ -0,0 +1,303 @@
package com.amazonaws.amplify.amplify_auth_cognito
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
package com.amazonaws.amplify.amplify_auth_cognito
package com.amazonaws.amplify.amplify_auth_cognito

@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.11-all.zip
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just use the latest version, which right now is 6.6. Amplify Android just always uses the latest stable version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants