-
Notifications
You must be signed in to change notification settings - Fork 247
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
refactor(amplify_auth_cognito): interface changes, logs, tests #27
Conversation
packages/amplify_auth_cognito/ios/Classes/SwiftAuthCognito.swift
Outdated
Show resolved
Hide resolved
...d/src/test/kotlin/com/amazonaws/amplify/amplify_auth_cognito/AmplifyAuthCognitoPluginTest.kt
Show resolved
Hide resolved
...th_cognito/android/src/main/kotlin/com/amazonaws/amplify/amplify_auth_cognito/AuthCognito.kt
Outdated
Show resolved
Hide resolved
...th_cognito/android/src/main/kotlin/com/amazonaws/amplify/amplify_auth_cognito/AuthCognito.kt
Outdated
Show resolved
Hide resolved
...th_cognito/android/src/main/kotlin/com/amazonaws/amplify/amplify_auth_cognito/AuthCognito.kt
Outdated
Show resolved
Hide resolved
...th_cognito/android/src/main/kotlin/com/amazonaws/amplify/amplify_auth_cognito/AuthCognito.kt
Show resolved
Hide resolved
packages/amplify_auth_cognito/ios/Classes/SwiftAuthCognito.swift
Outdated
Show resolved
Hide resolved
packages/amplify_auth_cognito/ios/Classes/SwiftAuthCognito.swift
Outdated
Show resolved
Hide resolved
...d/src/test/kotlin/com/amazonaws/amplify/amplify_auth_cognito/AmplifyAuthCognitoPluginTest.kt
Outdated
Show resolved
Hide resolved
...d/src/test/kotlin/com/amazonaws/amplify/amplify_auth_cognito/AmplifyAuthCognitoPluginTest.kt
Outdated
Show resolved
Hide resolved
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>>()) |
There was a problem hiding this comment.
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:
- Use an
AuthCategoryBehavior
in your source code, which is an interface. Then, use amock(AuthCategoryBeahvior::class.java)
in your test code, to run mockitoverify(...)
calls on. - **Use a real
AuthCategory()
, and doauthCateogory.addPlugin(mockPlugin)
, wheremockPlugin
is amock(AuthPlugin::class.java)
. Reason being: the AuthCategory is not designed to be extended, in fact I think it's afinal
class isnt' it? Whereas theAuthCategoryBehavior
andAuthPlugin
are deliberately designed to be extended, so creating a mock extension fits 100% with the source design.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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;
}
}
import java.lang.Exception | ||
import java.lang.reflect.Field | ||
import java.lang.reflect.Modifier |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
…mp and android unit tests
…lutter into unitTestsAndLogging
There was a problem hiding this 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
...th_cognito/android/src/main/kotlin/com/amazonaws/amplify/amplify_auth_cognito/AuthCognito.kt
Show resolved
Hide resolved
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) |
There was a problem hiding this comment.
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)
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
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.
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.