Files
purchases-ios/Tests/UnitTests/Networking/Responses/PaywallComponentsDataTests.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

95 lines
4.4 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
//
// PaywallComponentsDecodingTests.swift
//
// Created by Antonio Pallares on 13/2/25.
import Nimble
@testable import RevenueCat
import XCTest
class PaywallComponentsDecodingTests: BaseHTTPResponseTest {
private var response: OfferingsResponse!
override func setUpWithError() throws {
try super.setUpWithError()
self.response = try Self.decodeFixture("OfferingsWithPaywallComponents")
}
func testDecodesPaywallComponentsNoDraftPaywallComponents() throws {
let offering = try XCTUnwrap(self.response.offerings[safe: 0])
expect(offering.identifier) == "paywall_components"
expect(offering.description) == "Offering with paywall components"
expect(offering.metadata) == [:]
expect(offering.packages).to(haveCount(1))
let components = try XCTUnwrap(offering.paywallComponents)
expect(components.templateName) == "componentsTEST"
expect(components.revision) == 3
expect(components.componentsConfig.base.background) == .color(.init(light: .hex("#220000ff"), dark: nil))
expect(components.componentsConfig.base.stickyFooter) == nil
expect(components.componentsConfig.base.stack.spacing) == 16
expect(components.componentsConfig.base.stack.dimension) == .vertical(.center, .center)
expect(components.componentsConfig.base.stack.components).to(haveCount(0))
expect(offering.draftPaywallComponents) == nil
}
func testDecodesPaywallComponentsWithDraftPaywallComponents() throws {
let offering = try XCTUnwrap(self.response.offerings[safe: 1])
expect(offering.identifier) == "paywall_components_with_draft"
expect(offering.description) == "Offering with paywall components + draft paywall"
expect(offering.metadata) == [:]
expect(offering.packages).to(haveCount(1))
let components = try XCTUnwrap(offering.paywallComponents)
expect(components.templateName) == "componentsTEST"
expect(components.revision) == 3
expect(components.componentsConfig.base.background) == .color(.init(light: .hex("#220000ff"), dark: nil))
expect(components.componentsConfig.base.stickyFooter) == nil
expect(components.componentsConfig.base.stack.spacing) == 16
expect(components.componentsConfig.base.stack.dimension) == .vertical(.center, .center)
expect(components.componentsConfig.base.stack.components).to(haveCount(1))
let draftComponents = try XCTUnwrap(offering.draftPaywallComponents)
expect(draftComponents.templateName) == "newComponentsTEST"
expect(draftComponents.revision) == 4
expect(draftComponents.componentsConfig.base.background) == .color(.init(light: .hex("#110000ff"), dark: nil))
expect(draftComponents.componentsConfig.base.stickyFooter) == nil
expect(draftComponents.componentsConfig.base.stack.spacing) == 0
expect(draftComponents.componentsConfig.base.stack.dimension) == .vertical(.leading, .end)
expect(draftComponents.componentsConfig.base.stack.components).to(haveCount(1))
}
func testDecodesPaywallComponentsWithOnlyDraftPaywallComponents() throws {
let offering = try XCTUnwrap(self.response.offerings[safe: 2])
expect(offering.identifier) == "only_draft_paywall_components"
expect(offering.description) == "Offering with only draft paywall"
expect(offering.metadata) == [:]
expect(offering.packages).to(haveCount(1))
XCTAssertNil(offering.paywallComponents)
let draftComponents = try XCTUnwrap(offering.draftPaywallComponents)
expect(draftComponents.templateName) == "newComponentsTEST"
expect(draftComponents.revision) == 4
expect(draftComponents.componentsConfig.base.background) == .color(.init(light: .hex("#110000ff"), dark: nil))
expect(draftComponents.componentsConfig.base.stickyFooter) == nil
expect(draftComponents.componentsConfig.base.stack.spacing) == 0
expect(draftComponents.componentsConfig.base.stack.dimension) == .vertical(.leading, .end)
expect(draftComponents.componentsConfig.base.stack.components).to(haveCount(1))
}
}