Skip to content

Commit

Permalink
Offline Entitlements: created ProductEntitlementMappingResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
NachoSoto committed Mar 21, 2023
1 parent d9c4969 commit 762079a
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 0 deletions.
8 changes: 8 additions & 0 deletions RevenueCat.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
37E35C8515C5E2D01B0AF5C1 /* Strings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37E3507939634ED5A9280544 /* Strings.swift */; };
42F1DF385E3C1F9903A07FBF /* ProductsFetcherSK1.swift in Sources */ = {isa = PBXBuildFile; fileRef = EFB3CBAA73855779FE828CE2 /* ProductsFetcherSK1.swift */; };
57032ABF28C13CE4004FF47A /* StoreKit2SettingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57032ABE28C13CE4004FF47A /* StoreKit2SettingTests.swift */; };
57045B3829C514A8001A5417 /* ProductEntitlementMappingDecodingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57045B3729C514A8001A5417 /* ProductEntitlementMappingDecodingTests.swift */; };
57057FF828B0048900995F21 /* TestLogHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57057FF728B0048900995F21 /* TestLogHandler.swift */; };
57057FF928B0048900995F21 /* TestLogHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57057FF728B0048900995F21 /* TestLogHandler.swift */; };
57069A5428E3918400B86355 /* AsyncExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57069A5328E3918400B86355 /* AsyncExtensions.swift */; };
Expand Down Expand Up @@ -230,6 +231,7 @@
5746508C27586B2E0053AB09 /* Result+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5746508B27586B2E0053AB09 /* Result+Extensions.swift */; };
5746508E275949F20053AB09 /* DispatchTimeInterval+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5746508D275949F20053AB09 /* DispatchTimeInterval+Extensions.swift */; };
5748008C29BFC6660032F001 /* SignatureVerificationHTTPClientTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5748008B29BFC6660032F001 /* SignatureVerificationHTTPClientTests.swift */; };
57488A7F29CA145B0000EE7E /* ProductEntitlementMappingResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57488A7E29CA145B0000EE7E /* ProductEntitlementMappingResponse.swift */; };
574A2EE7282C3F0800150D40 /* AnyDecodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 574A2EE6282C3F0800150D40 /* AnyDecodable.swift */; };
574A2EE9282C403800150D40 /* AnyDecodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 574A2EE8282C403800150D40 /* AnyDecodableTests.swift */; };
574A2F3F282D75E300150D40 /* OfferingsDecodingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 574A2F3E282D75E300150D40 /* OfferingsDecodingTests.swift */; };
Expand Down Expand Up @@ -819,6 +821,7 @@
37E35F783903362B65FB7AF3 /* MockProductsRequestFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MockProductsRequestFactory.swift; sourceTree = "<group>"; };
37E35FDA0A44EA03EA12DAA2 /* DateFormatter+ExtensionsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DateFormatter+ExtensionsTests.swift"; sourceTree = "<group>"; };
57032ABE28C13CE4004FF47A /* StoreKit2SettingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoreKit2SettingTests.swift; sourceTree = "<group>"; };
57045B3729C514A8001A5417 /* ProductEntitlementMappingDecodingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductEntitlementMappingDecodingTests.swift; sourceTree = "<group>"; };
57057FF728B0048900995F21 /* TestLogHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestLogHandler.swift; sourceTree = "<group>"; };
57069A5328E3918400B86355 /* AsyncExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AsyncExtensions.swift; sourceTree = "<group>"; };
57069A5D28E398E100B86355 /* AsyncExtensionsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AsyncExtensionsTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -854,6 +857,7 @@
5746508B27586B2E0053AB09 /* Result+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Result+Extensions.swift"; sourceTree = "<group>"; };
5746508D275949F20053AB09 /* DispatchTimeInterval+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DispatchTimeInterval+Extensions.swift"; sourceTree = "<group>"; };
5748008B29BFC6660032F001 /* SignatureVerificationHTTPClientTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignatureVerificationHTTPClientTests.swift; sourceTree = "<group>"; };
57488A7E29CA145B0000EE7E /* ProductEntitlementMappingResponse.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProductEntitlementMappingResponse.swift; sourceTree = "<group>"; };
574A2EE6282C3F0800150D40 /* AnyDecodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnyDecodable.swift; sourceTree = "<group>"; };
574A2EE8282C403800150D40 /* AnyDecodableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnyDecodableTests.swift; sourceTree = "<group>"; };
574A2F3E282D75E300150D40 /* OfferingsDecodingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OfferingsDecodingTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2000,6 +2004,7 @@
574A2F3E282D75E300150D40 /* OfferingsDecodingTests.swift */,
574A2F4E282D7B9E00150D40 /* PostOfferDecodingTests.swift */,
5766C61F282DA3D50067D886 /* GetIntroEligibilityDecodingTests.swift */,
57045B3729C514A8001A5417 /* ProductEntitlementMappingDecodingTests.swift */,
);
path = Responses;
sourceTree = "<group>";
Expand Down Expand Up @@ -2066,6 +2071,7 @@
5766C621282DAA700067D886 /* GetIntroEligibilityResponse.swift */,
57D5412D27F6311C004CC35C /* OfferingsResponse.swift */,
574A2F4A282D7AEA00150D40 /* PostOfferResponse.swift */,
57488A7E29CA145B0000EE7E /* ProductEntitlementMappingResponse.swift */,
);
path = Responses;
sourceTree = "<group>";
Expand Down Expand Up @@ -2856,6 +2862,7 @@
B3F3E8DA277158FE0047A5B9 /* DNSChecker.swift in Sources */,
A525BF4B26C320D100C354C4 /* SubscriberAttributesManager.swift in Sources */,
2D1015DA275959840086173F /* StoreTransaction.swift in Sources */,
57488A7F29CA145B0000EE7E /* ProductEntitlementMappingResponse.swift in Sources */,
B34605BC279A6E380031CA74 /* CallbackCache.swift in Sources */,
B3E26A4A26BE0A8E003ACCF3 /* Error+Extensions.swift in Sources */,
57EAE52D274468900060EB74 /* RawDataContainer.swift in Sources */,
Expand Down Expand Up @@ -3004,6 +3011,7 @@
2D4D6AF524F717B800B656BE /* ContainerFactory.swift in Sources */,
57E9CF11290B2ADC00EE12D1 /* CachingTrialOrIntroPriceEligibilityCheckerTests.swift in Sources */,
57E415FF28469EAB00EA5460 /* PurchasesGetProductsTests.swift in Sources */,
57045B3829C514A8001A5417 /* ProductEntitlementMappingDecodingTests.swift in Sources */,
351B514726D44A0D00BD2BD7 /* MockSystemInfo.swift in Sources */,
B300E4C226D439B700B22262 /* IntroEligibilityCalculatorTests.swift in Sources */,
57554C62282ABFD9009A7E58 /* StoreTests.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// 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
//
// ProductEntitlementMappingResponse.swift
//
// Created by Nacho Soto on 3/17/23.

import Foundation

struct ProductEntitlementMappingResponse {

var products: [Product]

}

extension ProductEntitlementMappingResponse {

struct Product {

var identifier: String
var entitlements: [String]

}

}

// MARK: - Codable

extension ProductEntitlementMappingResponse.Product: Codable {

private enum CodingKeys: String, CodingKey {

case identifier = "id"
case entitlements

}

}

extension ProductEntitlementMappingResponse: Codable {}
extension ProductEntitlementMappingResponse: HTTPResponseBody {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"products": [
{
"id": "com.revenuecat.foo_1",
"entitlements": [
"pro_1"
]
},
{
"id": "com.revenuecat.foo_2",
"entitlements": [
"pro_1",
"pro_2"
]
},
{
"id": "com.revenuecat.foo_3",
"entitlements": [
"pro_2"
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// 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[0].identifier) == "com.revenuecat.foo_1"
expect(products[0].entitlements) == ["pro_1"]

expect(products[1].identifier) == "com.revenuecat.foo_2"
expect(products[1].entitlements) == ["pro_1", "pro_2"]

expect(products[2].identifier) == "com.revenuecat.foo_3"
expect(products[2].entitlements) == ["pro_2"]
}

}

0 comments on commit 762079a

Please sign in to comment.