Skip to content

Commit

Permalink
HUC test fix #2
Browse files Browse the repository at this point in the history
  • Loading branch information
jnewc committed Apr 19, 2024
1 parent e08bbb1 commit d2e9d46
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ final class HUC_TokenizationViewModelTests: XCTestCase {
private var abortPayment = false

var onCreatePaymentWithData: ((PrimerCheckoutPaymentMethodData) -> Void)?
var onUpdateClientSession: ((PrimerClientSession) -> Void?)?

override func tearDown() {
VaultService.apiClient = nil
Expand Down Expand Up @@ -406,20 +407,26 @@ final class HUC_TokenizationViewModelTests: XCTestCase {
}

if self.abortPayment {
onCreatePaymentWithData = { _ in


print(self.eventsCalled)

onUpdateClientSession = { _ in
guard self.eventsCalled.count == 6 else { return }
if isSurchargeIncluded {
XCTAssert(self.eventsCalled.count == 6, "6 events should have been called.")
XCTAssert(self.eventsCalled[0] == "primerHeadlessUniversalCheckoutPreparationDidStart", "'\(self.eventsCalled[0])' called instead if 'primerHeadlessUniversalCheckoutPreparationDidStart'.")
XCTAssert(self.eventsCalled[1] == "primerHeadlessUniversalCheckoutClientSessionWillUpdate", "'\(self.eventsCalled[1])' called instead if 'primerHeadlessUniversalCheckoutClientSessionWillUpdate'.")
XCTAssert(self.eventsCalled[2] == "primerHeadlessUniversalCheckoutClientSessionDidUpdate", "'\(self.eventsCalled[2])' called instead if 'primerHeadlessUniversalCheckoutClientSessionDidUpdate'.")
XCTAssert(self.eventsCalled[3] == "primerHeadlessUniversalCheckoutWillCreatePaymentWithData", "'\(self.eventsCalled[3])' called instead if 'primerHeadlessUniversalCheckoutWillCreatePaymentWithData'.")
XCTAssert(self.eventsCalled[4] == "primerHeadlessUniversalCheckoutClientSessionWillUpdate", "'\(self.eventsCalled[4])' called instead if 'primerHeadlessUniversalCheckoutClientSessionWillUpdate'.")
XCTAssert(self.eventsCalled[5] == "primerHeadlessUniversalCheckoutClientSessionDidUpdate", "'\(self.eventsCalled[5])' called instead if 'primerHeadlessUniversalCheckoutClientSessionDidUpdate'.")

} else {
}
expectation.fulfill()
}

onCreatePaymentWithData = { _ in
if !isSurchargeIncluded {
XCTAssert(self.eventsCalled.count == 2, "2 events should have been called but got \(self.eventsCalled.count).")
XCTAssert(self.eventsCalled[0] == "primerHeadlessUniversalCheckoutPreparationDidStart", "'\(self.eventsCalled[0])' called instead if 'primerHeadlessUniversalCheckoutPreparationDidStart'.")
XCTAssert(self.eventsCalled[1] == "primerHeadlessUniversalCheckoutWillCreatePaymentWithData", "'\(self.eventsCalled[1])' called instead if 'primerHeadlessUniversalCheckoutWillCreatePaymentWithData'.")
Expand Down Expand Up @@ -478,6 +485,7 @@ extension HUC_TokenizationViewModelTests: PrimerHeadlessUniversalCheckoutDelegat

func primerHeadlessUniversalCheckoutDidUpdateClientSession(_ clientSession: PrimerClientSession) {
eventsCalled.append("primerHeadlessUniversalCheckoutClientSessionDidUpdate")
onUpdateClientSession?(clientSession)
}

func primerHeadlessUniversalCheckoutDidReceiveAdditionalInfo(_ additionalInfo: PrimerCheckoutAdditionalInfo?) {
Expand Down

0 comments on commit d2e9d46

Please sign in to comment.