From c24be7f88a457bb53f17c7a61301f0507db1e865 Mon Sep 17 00:00:00 2001 From: NachoSoto Date: Thu, 7 Sep 2023 08:57:24 -0700 Subject: [PATCH] Default to 0 and update snapshots --- Sources/Misc/Codable/DefaultDecodable.swift | 6 ++++++ Sources/Paywalls/PaywallData.swift | 14 +++++++++----- .../testCanGetOfferings.1.json | 1 + .../testCanGetOfferings.1.json | 1 + .../PaywallData-missing_current_locale.json | 3 +-- .../Fixtures/PaywallData-missing_localization.json | 3 +-- 6 files changed, 19 insertions(+), 9 deletions(-) diff --git a/Sources/Misc/Codable/DefaultDecodable.swift b/Sources/Misc/Codable/DefaultDecodable.swift index cdbfa4d8ad..67c61cac42 100644 --- a/Sources/Misc/Codable/DefaultDecodable.swift +++ b/Sources/Misc/Codable/DefaultDecodable.swift @@ -199,6 +199,10 @@ enum DefaultDecodable { static var defaultValue: String { "" } } + enum Zero: DefaultValueProvider { + static var defaultValue: Int { 0 } + } + enum EmptyArray: DefaultValueProvider { static var defaultValue: T { [] } } @@ -226,6 +230,7 @@ enum DefaultDecodable { * @DefaultDecodable.EmptyArray var values: [String] * @DefaultDecodable.EmptyDictionary var dictionary: [String: Int] * @DefaultDecodable.Now var date: Date + * @DefaultDecodable.Zero var number: Int * } * ``` */ @@ -237,5 +242,6 @@ extension DefaultDecodable { typealias EmptyArray = DefaultValue> typealias EmptyDictionary = DefaultValue> typealias Now = DefaultValue + typealias Zero = DefaultValue } diff --git a/Sources/Paywalls/PaywallData.swift b/Sources/Paywalls/PaywallData.swift index e37889e22c..564f1afc61 100644 --- a/Sources/Paywalls/PaywallData.swift +++ b/Sources/Paywalls/PaywallData.swift @@ -11,7 +11,7 @@ // // Created by Nacho Soto on 7/10/23. -// swiftlint:disable file_length +// swiftlint:disable file_length identifier_name import Foundation @@ -32,7 +32,13 @@ public struct PaywallData { public var assetBaseURL: URL /// The revision identifier for this paywall. - public var revision: Int + var revision: Int { + get { return self._revision } + set { self._revision = newValue } + } + + @DefaultDecodable.Zero + internal private(set) var _revision: Int = 0 @EnsureNonEmptyCollectionDecodable internal private(set) var localization: [String: LocalizedConfiguration] @@ -63,8 +69,6 @@ public protocol PaywallLocalizedConfiguration { } -// swiftlint:disable identifier_name - extension PaywallData { /// Defines the necessary localized information for a paywall. @@ -435,7 +439,7 @@ extension PaywallData: Codable { case config case localization = "localizedStrings" case assetBaseURL = "assetBaseUrl" - case revision + case _revision = "revision" } } diff --git a/Tests/BackendIntegrationTests/__Snapshots__/LoadShedderIntegrationTests/testCanGetOfferings.1.json b/Tests/BackendIntegrationTests/__Snapshots__/LoadShedderIntegrationTests/testCanGetOfferings.1.json index bd49fb6db3..2520486736 100644 --- a/Tests/BackendIntegrationTests/__Snapshots__/LoadShedderIntegrationTests/testCanGetOfferings.1.json +++ b/Tests/BackendIntegrationTests/__Snapshots__/LoadShedderIntegrationTests/testCanGetOfferings.1.json @@ -56,6 +56,7 @@ "title" : "Ignite your child's curiosity" } }, + "revision" : 1, "template_name" : "1" } }, diff --git a/Tests/BackendIntegrationTests/__Snapshots__/StoreKitIntegrationTests/testCanGetOfferings.1.json b/Tests/BackendIntegrationTests/__Snapshots__/StoreKitIntegrationTests/testCanGetOfferings.1.json index 87b36f4f54..1107850ff8 100644 --- a/Tests/BackendIntegrationTests/__Snapshots__/StoreKitIntegrationTests/testCanGetOfferings.1.json +++ b/Tests/BackendIntegrationTests/__Snapshots__/StoreKitIntegrationTests/testCanGetOfferings.1.json @@ -70,6 +70,7 @@ "title" : "Ignite your child's curiosity" } }, + "revision" : 3, "template_name" : "2" } }, diff --git a/Tests/UnitTests/Networking/Responses/Fixtures/PaywallData-missing_current_locale.json b/Tests/UnitTests/Networking/Responses/Fixtures/PaywallData-missing_current_locale.json index 1a41fe48cf..601c505638 100644 --- a/Tests/UnitTests/Networking/Responses/Fixtures/PaywallData-missing_current_locale.json +++ b/Tests/UnitTests/Networking/Responses/Fixtures/PaywallData-missing_current_locale.json @@ -24,6 +24,5 @@ "dark": null } }, - "asset_base_url": "https://rc-paywalls.s3.amazonaws.com", - "revision": 1 + "asset_base_url": "https://rc-paywalls.s3.amazonaws.com" } diff --git a/Tests/UnitTests/Networking/Responses/Fixtures/PaywallData-missing_localization.json b/Tests/UnitTests/Networking/Responses/Fixtures/PaywallData-missing_localization.json index be1dac183c..1c6882a6b4 100644 --- a/Tests/UnitTests/Networking/Responses/Fixtures/PaywallData-missing_localization.json +++ b/Tests/UnitTests/Networking/Responses/Fixtures/PaywallData-missing_localization.json @@ -15,6 +15,5 @@ "dark": null } }, - "asset_base_url": "https://rc-paywalls.s3.amazonaws.com", - "revision": 1 + "asset_base_url": "https://rc-paywalls.s3.amazonaws.com" }