Feature: enable validation to be skipped for testing
* fix visibility of shouldSkipForUITests flag * fix visibility of shouldSkipForUITests flag * fix token bypassing * Add improvements from review fix #51
This commit is contained in:
parent
50046bff25
commit
a88fcb9850
|
|
@ -500,7 +500,7 @@
|
|||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
shellPath = /bin/sh;
|
||||
shellScript = "\"${PODS_ROOT}/SwiftLint/swiftlint\" --path \"${PROJECT_DIR}/..\"";
|
||||
shellScript = "\"${PODS_ROOT}/SwiftLint/swiftlint\" --path \"${PROJECT_DIR}/..\"\n";
|
||||
};
|
||||
F28FACA6200E447600E14987 /* ShellScript */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
|
|
|
|||
|
|
@ -39,6 +39,11 @@
|
|||
"idiom" : "iphone",
|
||||
"size" : "60x60",
|
||||
"scale" : "3x"
|
||||
},
|
||||
{
|
||||
"idiom" : "ios-marketing",
|
||||
"size" : "1024x1024",
|
||||
"scale" : "1x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
|
|
|
|||
|
|
@ -5,3 +5,5 @@ disabled_rules:
|
|||
- explicit_top_level_acl
|
||||
- function_body_length
|
||||
- identifier_name
|
||||
- file_length
|
||||
- type_body_length
|
||||
|
|
|
|||
|
|
@ -366,6 +366,22 @@ class ReCaptchaWebViewManager__Tests: XCTestCase {
|
|||
XCTAssertEqual(result?.token, apiKey)
|
||||
}
|
||||
|
||||
func test__Validate__Should_Skip_For_Tests() {
|
||||
let exp = expectation(description: "did skip validation")
|
||||
|
||||
let manager = ReCaptchaWebViewManager()
|
||||
manager.shouldSkipForTests = true
|
||||
|
||||
manager.completion = { result in
|
||||
XCTAssertEqual(result.token, "")
|
||||
exp.fulfill()
|
||||
}
|
||||
|
||||
manager.validate(on: presenterView)
|
||||
|
||||
waitForExpectations(timeout: 1)
|
||||
}
|
||||
|
||||
// MARK: Force Challenge Visible
|
||||
|
||||
func test__Force_Visible_Challenge() {
|
||||
|
|
|
|||
|
|
@ -205,6 +205,12 @@ public class ReCaptcha {
|
|||
get { return manager.forceVisibleChallenge }
|
||||
set { manager.forceVisibleChallenge = newValue }
|
||||
}
|
||||
|
||||
/// Allows validation stubbing for testing
|
||||
public var shouldSkipForTests: Bool {
|
||||
get { return manager.shouldSkipForTests }
|
||||
set { manager.shouldSkipForTests = newValue }
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -114,6 +114,9 @@ internal class ReCaptchaWebViewManager {
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// Allows validation stubbing for testing
|
||||
public var shouldSkipForTests = false
|
||||
#endif
|
||||
|
||||
/// Sends the result message
|
||||
|
|
@ -195,6 +198,12 @@ internal class ReCaptchaWebViewManager {
|
|||
Starts the challenge validation
|
||||
*/
|
||||
func validate(on view: UIView) {
|
||||
#if DEBUG
|
||||
guard !shouldSkipForTests else {
|
||||
completion?(.token(""))
|
||||
return
|
||||
}
|
||||
#endif
|
||||
webView.isHidden = false
|
||||
view.addSubview(webView)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue