Files
purchases-ios/Tests/UnitTests/Networking/Responses/ProductEntitlementMappingDecodingTests.swift
T
Antonio Pallares 81aaf6a051 Offering hasPaywall getter (#4847)
* feat: add `hasPaywall` getter to `Offering`

Returns `true` if the offering has either a v1 or a v2 paywall

* docs: update some methods references changing `PaywallData` with "paywall", as `PaywallData` only refers to v1 paywalls

* docs: improve reference of `Offering`'s `paywall` and `paywallComponents` to mention the new `hasPaywall` property

* lint

* tests: add unit tests that check the `hasPaywall` property of `Offering`

* api tests: add `paywallComponents` and `hasPaywall` to SwiftAPITester
2025-03-04 12:09:53 +01:00

61 lines
1.7 KiB
Swift

//
// Copyright RevenueCat Inc. All Rights Reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// ProductEntitlementMappingDecodingTests.swift
//
// Created by Nacho Soto on 3/17/23.
import Nimble
@testable import RevenueCat
import XCTest
class ProductEntitlementMappingDecodingTests: BaseHTTPResponseTest {
private var response: ProductEntitlementMappingResponse!
override func setUpWithError() throws {
try super.setUpWithError()
self.response = try Self.decodeFixture("ProductsEntitlements")
}
func testDataIsCorrect() {
let products = self.response.products
expect(products).to(haveCount(3))
expect(products["com.revenuecat.foo_1"]?.identifier) == "com.revenuecat.foo_1"
expect(products["com.revenuecat.foo_1"]?.entitlements) == ["pro_1"]
expect(products["com.revenuecat.foo_2"]?.identifier) == "com.revenuecat.foo_2"
expect(products["com.revenuecat.foo_2"]?.entitlements) == ["pro_1", "pro_2"]
expect(products["com.revenuecat.foo_3"]?.identifier) == "com.revenuecat.foo_3"
expect(products["com.revenuecat.foo_3"]?.entitlements) == ["pro_2"]
}
func testConversionToMapping() {
let mapping = self.response.toMapping()
expect(mapping.entitlementsByProduct) == [
"com.revenuecat.foo_1": [
"pro_1"
],
"com.revenuecat.foo_2": [
"pro_1",
"pro_2"
],
"com.revenuecat.foo_3": [
"pro_2"
]
]
}
}