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

Feature/hw 51305 create pay pal account #12

Merged
merged 17 commits into from
May 10, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions HyperwalletUISDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
98220B8C2265793700055E18 /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = 98220B8B2265793700055E18 /* README.md */; };
98541F152273D72C007D4238 /* CHANGELOG.md in Resources */ = {isa = PBXBuildFile; fileRef = 98541F142273D72C007D4238 /* CHANGELOG.md */; };
98F63E62228255390090101D /* PayPalAccountResponse.json in Resources */ = {isa = PBXBuildFile; fileRef = 98F63E61228255390090101D /* PayPalAccountResponse.json */; };
98F63E6322833FA40090101D /* PayPalAccountResponse.json in Resources */ = {isa = PBXBuildFile; fileRef = 98F63E61228255390090101D /* PayPalAccountResponse.json */; };
C358A9A52272644000E5AE47 /* AddTransferMethod.swift in Sources */ = {isa = PBXBuildFile; fileRef = C358A9A22272644000E5AE47 /* AddTransferMethod.swift */; };
C358A9A62272644000E5AE47 /* ListTransferMethods.swift in Sources */ = {isa = PBXBuildFile; fileRef = C358A9A32272644000E5AE47 /* ListTransferMethods.swift */; };
C358A9A72272644000E5AE47 /* SelectTransferMethodType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C358A9A42272644000E5AE47 /* SelectTransferMethodType.swift */; };
Expand Down Expand Up @@ -812,6 +813,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
98F63E6322833FA40090101D /* PayPalAccountResponse.json in Resources */,
078B45752273895C005B0248 /* StatusTransitionMockedResponseSuccess.json in Resources */,
078B457C2273895C005B0248 /* BankCardResponse.json in Resources */,
078B45782273895C005B0248 /* HyperwalletField.json in Resources */,
Expand Down
8 changes: 2 additions & 6 deletions Sources/TransferMethod/AddTransferMethodPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ final class AddTransferMethodPresenter {
else {
return
}
var hyperwalletTransferMethod: HyperwalletTransferMethod

Choose a reason for hiding this comment

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

I think we still can leave it because for most of the cases we don't need to initialize a hyperwalletTransferMethod.

var hyperwalletTransferMethod = HyperwalletTransferMethod()
switch transferMethodType {
case "BANK_ACCOUNT":
hyperwalletTransferMethod = HyperwalletBankAccount.Builder(transferMethodCountry: country,
Expand All @@ -115,11 +115,7 @@ final class AddTransferMethodPresenter {
.build()

default:
hyperwalletTransferMethod = HyperwalletTransferMethod()

Choose a reason for hiding this comment

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

I think we can keep this line.

hyperwalletTransferMethod.setField(key: "transferMethodCountry", value: country)
hyperwalletTransferMethod.setField(key: "transferMethodCurrency", value: currency)
hyperwalletTransferMethod.setField(key: "type", value: transferMethodType)
hyperwalletTransferMethod.setField(key: "profileType", value: profileType)
return
}
for field in view.fieldValues() {
hyperwalletTransferMethod.setField(key: field.name, value: field.value)
Expand Down
8 changes: 8 additions & 0 deletions Sources/TransferMethod/ListTransferMethodPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ final class ListTransferMethodPresenter {
deactivateBankAccount(token)
case "BANK_CARD":
deactivateBankCard(token)
case "PAYPAL_ACCOUNT":
deactivatePayPalAccount(token)

default:
break
Expand Down Expand Up @@ -117,6 +119,12 @@ final class ListTransferMethodPresenter {
completion: deactivateTransferMethodHandler())
}

private func deactivatePayPalAccount(_ token: String) {
Hyperwallet.shared.deactivatePayPalAccount(transferMethodToken: token,
notes: "Deactivating the PayPal Account",
completion: deactivateTransferMethodHandler())

Choose a reason for hiding this comment

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

indentation.

}

private func deactivateTransferMethodHandler()
-> (HyperwalletStatusTransition?, HyperwalletErrorType?) -> Void {
return { [weak self] (result, error) in
Expand Down
26 changes: 24 additions & 2 deletions Tests/TransferMethod/AddTransferMethodPresenterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class AddTransferMethodPresenterTests: XCTestCase {
mockView.mockFieldStatusReturnResult.append(true)

// press the create transfer method button
let expectation = self.expectation(description: "Create bank account completed")
let expectation = self.expectation(description: "Create PayPal account completed")
mockView.expectation = expectation

presenter.createTransferMethod()
Expand Down Expand Up @@ -162,6 +162,28 @@ class AddTransferMethodPresenterTests: XCTestCase {
XCTAssertFalse(mockView.isNotificationSent, "The notification should not be sent")
}

func testCreateTransferMethod_inlineFailure() {
// Given
let url = String(format: "%@/bank-accounts", HyperwalletTestHelper.userRestURL)
let response = HyperwalletTestHelper
.badRequestHTTPResponse(for: "BankAccountErrorResponseWithMissingFieldAndValidationError")
let request = HyperwalletTestHelper.buildPostResquest(baseUrl: url, response)
HyperwalletTestHelper.setUpMockServer(request: request)

mockView.mockFieldValuesReturnResult.append((name: "bankId", value: ""))
mockView.mockFieldStatusReturnResult.append(false)

// When
presenter.createTransferMethod()

// Then
XCTAssertTrue(mockView.areAllFieldsValidPerformed, "All fields validation should be performed")
XCTAssertFalse(mockView.isFieldValuesPerformed, "The FieldValues should not be performed")
XCTAssertFalse(mockView.isShowErrorPerformed, "The showError should not be performed")
XCTAssertFalse(mockView.isShowConfirmationPerformed, "The showConfirmation should not be performed")
XCTAssertFalse(mockView.isNotificationSent, "The notification should not be sent")
}

private func setupTransferMethodConfigurationFields(_ error: NSError? = nil) -> StubRequest {
let response = HyperwalletTestHelper.setUpMockedResponse(payload: transferMethodConfigurationFieldsResponse,
error: error)
Expand Down Expand Up @@ -230,7 +252,7 @@ class MockAddTransferMethodViewTests: AddTransferMethodView {

func areAllFieldsValid() -> Bool {
areAllFieldsValidPerformed = true
return true
return mockFieldStatusReturnResult.contains(false) ? false : true
}

func updateFooter(for section: Int, description: String?, errorMessage: String?) {
Expand Down
26 changes: 25 additions & 1 deletion Tests/TransferMethod/ListTransferMethodPresenterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,24 @@ class ListTransferMethodPresenterTests: XCTestCase {
XCTAssertTrue(mockView.isShowConfirmationPerformed, "The showConfirmation should be performed")
}

func testDeactivatePayPalAccount_success() {
// Given
loadMockTransfermethods()
HyperwalletTestHelper.setUpMockServer(request: setUpDeactivateTransferMethodRequest("/paypal-accounts/"))

let expectation = self.expectation(description: "deactivate a PayPal account")
mockView.expectation = expectation

// When
presenter.deactivateTransferMethod(at: 2)
wait(for: [expectation], timeout: 1)

// Then
XCTAssertTrue(mockView.isShowProcessingPerformed, "The showProcessing should be performed")
XCTAssertFalse(mockView.isShowErrorPerformed, "The showError should not be performed")
XCTAssertTrue(mockView.isShowConfirmationPerformed, "The showConfirmation should be performed")
}

func testDeactivateBankCard_failureWithError() {
// Given
loadMockTransfermethods()
Expand Down Expand Up @@ -178,7 +196,13 @@ class ListTransferMethodPresenterTests: XCTestCase {
transferMethodProfileType: "INDIVIDUAL")
.build()
bankCard.setField(key: "token", value: "trm-123456789")
let transferMethods = [bankAccount, bankCard]

let payPalAccount = HyperwalletPayPalAccount.Builder(transferMethodCountry: "US",

Choose a reason for hiding this comment

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

We should use HyperwalletPayPalAccount.Builder(token: "trm-123456789").build()

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can't. We need country and currency as well

transferMethodCurrency: "USD")
.build()
payPalAccount.setField(key: "token", value: "trm-123456789")

let transferMethods = [bankAccount, bankCard, payPalAccount]
presenter.transferMethods = transferMethods
}

Expand Down