Skip to content

Commit

Permalink
Integration Tests: add coverage for Purchases.customerInfoStream (#…
Browse files Browse the repository at this point in the history
…3213)

I noticed we had no integration tests for this.
  • Loading branch information
NachoSoto authored Sep 15, 2023
1 parent 9e83946 commit 8bb5482
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
25 changes: 25 additions & 0 deletions Tests/BackendIntegrationTests/StoreKitIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,31 @@ class StoreKit1IntegrationTests: BaseStoreKitIntegrationTests {
expect(transaction.offerType) == .promotional
}

func testCustomerInfoStream() async throws {
let purchases = try self.purchases
let updates: Atomic<[CustomerInfo]> = .init([])

let task = Task {
for await info in purchases.customerInfoStream {
updates.modify { $0.append(info) }
}
}
defer { task.cancel() }

try await asyncWait(timeout: .seconds(1)) {
"Expected only one value initially: \($0 ?? [])"
} until: {
updates.value
} condition: {
$0.count == 1
}

let info = try await self.purchaseMonthlyProduct().customerInfo

expect(updates.value).to(haveCount(2))
expect(updates.value.last) === info
}

}

private extension BaseStoreKitIntegrationTests {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ extension XCTestCase {
line: UInt = #line
) async throws {
try await asyncWait(
description: { "Transaction expectation never met: \($0 ?? [])" },
file: file,
line: line,
description: { "Transaction expectation never met: \($0 ?? [])" },
until: { await Transaction.unfinished.extractValues() },
condition: { condition($0.count) }
)
Expand Down
4 changes: 2 additions & 2 deletions Tests/UnitTests/TestHelpers/AsyncTestHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ func asyncWait(
until condition: @Sendable () async -> Bool
) async throws {
try await asyncWait(
description: { _ in description },
timeout: timeout,
pollInterval: pollInterval,
file: file,
line: line,
description: { _ in description },
until: { () },
condition: { _ in await condition() }
)
Expand All @@ -88,11 +88,11 @@ func asyncWait(
// Fix-me: remove once we can use Quick v6.x:
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, *)
func asyncWait<T>(
description: (T?) -> String?,
timeout: DispatchTimeInterval = defaultTimeout,
pollInterval: DispatchTimeInterval = defaultPollInterval,
file: FileString = #fileID,
line: UInt = #line,
description: @Sendable (T?) -> String?,
until value: @Sendable () async -> T,
condition: @Sendable (T) async -> Bool
) async throws {
Expand Down

0 comments on commit 8bb5482

Please sign in to comment.