-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Offline Entitlements
: created ProductEntitlementMappingResponse
- Loading branch information
Showing
4 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
Sources/Networking/Responses/ProductEntitlementMappingResponse.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
23 changes: 23 additions & 0 deletions
23
Tests/UnitTests/Networking/Responses/Fixtures/ProductsEntitlements.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} | ||
] | ||
} |
43 changes: 43 additions & 0 deletions
43
Tests/UnitTests/Networking/Responses/ProductEntitlementMappingDecodingTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} | ||
|
||
} |