Skip to content

Commit

Permalink
Integration Tests: added tests for purchasing consumable products
Browse files Browse the repository at this point in the history
The second test reproduces #1964.
  • Loading branch information
NachoSoto committed Oct 11, 2022
1 parent 36dff60 commit bd3404b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
33 changes: 33 additions & 0 deletions Tests/BackendIntegrationTests/StoreKitIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,27 @@ class StoreKit1IntegrationTests: BaseBackendIntegrationTests {
try await self.purchaseMonthlyProduct()
}

func testCanPurchaseConsumable() async throws {
let info = try await self.purchaseConsumablePackage().customerInfo

expect(info.allPurchasedProductIdentifiers).to(contain(Self.consumable10Coins))
}

func testCanPurchaseConsumableMultipleTimes() async throws {
let count = 2

for _ in 0..<count {
try await self.purchaseConsumablePackage()
}

let info = try await Purchases.shared.customerInfo()
expect(info.nonSubscriptions).to(haveCount(count))
expect(info.nonSubscriptions.map(\.productIdentifier)) == [
Self.consumable10Coins,
Self.consumable10Coins
]
}

func testSubscriptionIsSandbox() async throws {
let info = try await self.purchaseMonthlyOffering().customerInfo

Expand Down Expand Up @@ -394,6 +415,7 @@ class StoreKit1IntegrationTests: BaseBackendIntegrationTests {
private extension StoreKit1IntegrationTests {

static let entitlementIdentifier = "premium"
static let consumable10Coins = "consumable.10_coins"

private var currentOffering: Offering {
get async throws {
Expand Down Expand Up @@ -466,6 +488,17 @@ private extension StoreKit1IntegrationTests {
return data
}

@discardableResult
func purchaseConsumablePackage(
file: FileString = #file,
line: UInt = #line
) async throws -> PurchaseResultData {
let offering = try await XCTAsyncUnwrap(try await Purchases.shared.offerings().offering(identifier: "coins"))
let package = try XCTUnwrap(offering.package(identifier: "10.coins"))

return try await Purchases.shared.purchase(package: package)
}

@discardableResult
func verifyEntitlementWentThrough(
_ customerInfo: CustomerInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@
"productID" : "lifetime",
"referenceName" : "lifetime",
"type" : "NonConsumable"
},
{
"displayPrice" : "0.99",
"familyShareable" : false,
"internalID" : "67E2FE0B",
"localizations" : [
{
"description" : "10 Coins",
"displayName" : "10 Coins",
"locale" : "en_US"
}
],
"productID" : "consumable.10_coins",
"referenceName" : "10 coins",
"type" : "Consumable"
}
],
"settings" : {
Expand Down

0 comments on commit bd3404b

Please sign in to comment.