Skip to content

Commit

Permalink
feat: session is active (#962)
Browse files Browse the repository at this point in the history
* Add checkout session active

* Reset checkoutSessionId when Headless cleans up

* add test for headless cleanup
  • Loading branch information
NQuinn27 authored Aug 6, 2024
1 parent 88122fa commit 459d512
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Sources/PrimerSDK/Classes/Core/Primer/Primer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,11 @@ public class Primer {
public func dismiss() {
PrimerInternal.shared.dismiss()
}

/**
Checkout Session is active?
*/
public func checkoutSessionIsActive() -> Bool {
PrimerInternal.shared.checkoutSessionIsActive()
}
}
4 changes: 4 additions & 0 deletions Sources/PrimerSDK/Classes/Core/Primer/PrimerInternal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,8 @@ internal class PrimerInternal: LogReporter {
}
}
}

internal func checkoutSessionIsActive() -> Bool {
checkoutSessionId != nil
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public class PrimerHeadlessUniversalCheckout: LogReporter {

public func cleanUp() {
PrimerAPIConfigurationModule.resetSession()
PrimerInternal.shared.checkoutSessionId = nil
}

// MARK: - HELPERS
Expand Down
26 changes: 26 additions & 0 deletions Tests/Primer/Utils/CheckoutSessionTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// File.swift
//
//
// Created by Niall Quinn on 06/08/24.
//

import XCTest
@testable import PrimerSDK

final class CheckoutSessionTests: XCTestCase {
func test_headless_cleanup() {
XCTAssertFalse(Primer.shared.checkoutSessionIsActive())

let expectation = self.expectation(description: "Wait for headless load")

PrimerHeadlessUniversalCheckout.current.start(withClientToken: "") { paymentMethods, err in
XCTAssertTrue(Primer.shared.checkoutSessionIsActive())
expectation.fulfill()
}

waitForExpectations(timeout: 30)
PrimerHeadlessUniversalCheckout.current.cleanUp()
XCTAssertFalse(Primer.shared.checkoutSessionIsActive())
}
}

0 comments on commit 459d512

Please sign in to comment.