Commit cd1e845f authored by Jose Blaya's avatar Jose Blaya
Browse files

Unit tests

parent fddd00bb
......@@ -57,5 +57,9 @@ extension Client {
public static func useMockInAppProviderWithoutReceipt() {
store = MockInAppProvider(with: nil)
}
public static func useMockInAppProviderWithReceipt() {
store = MockInAppProvider(with: "abcdefg".data(using: .utf8))
}
#endif
}
......@@ -112,6 +112,15 @@ public class MockAccountProvider: AccountProvider, WebServicesConsumer {
isTrialPeriod: false,
trialsEnabled: true)
}
webServices.appstoreInformationEligibleButDisabledFromBackend = {
return AppStoreInformation(products: [Product(identifier: "com.product.monthly",
plan: .monthly,
price: "3.99",
legacy: false)],
isInIntroOfferPeriod: false,
isTrialPeriod: false,
trialsEnabled: false)
}
webServices.appstoreInformationNotEligible = {
return AppStoreInformation(products: [Product(identifier: "com.product.monthly",
plan: .monthly,
......
......@@ -19,6 +19,8 @@ class MockWebServices: WebServices {
var appstoreInformationNotEligible: (() -> AppStoreInformation)?
var appstoreInformationEligibleButDisabledFromBackend: (() -> AppStoreInformation)?
var serversBundle: (() -> ServersBundle)?
func token(credentials: Credentials, _ callback: ((String?, Error?) -> Void)?) {
......@@ -73,8 +75,12 @@ class MockWebServices: WebServices {
func subscriptionInformation(with receipt: Data?, _ callback: LibraryCallback<AppStoreInformation>?) {
let result = { () -> AppStoreInformation? in
if let _ = receipt {
return self.appstoreInformationNotEligible?()
if let receipt = receipt {
if receipt.count == 0 {
return self.appstoreInformationNotEligible?()
} else {
return self.appstoreInformationEligibleButDisabledFromBackend?()
}
} else {
return self.appstoreInformationEligible?()
}
......
......@@ -95,6 +95,31 @@ class ProductTests: XCTestCase {
}
func testMockTrialsUserEligibleButTrialsDisabledOnBackend() {
Client.useMockInAppProviderWithReceipt()
let expUpdate = expectation(description: "trials_disabled_from_backend")
mock.accountProvider.subscriptionInformation { subscriptionInfo, error in
if let _ = error {
print("error found: \(error!)")
expUpdate.fulfill()
XCTAssert(false)
return
}
guard let _ = subscriptionInfo else {
print("testMockTrials: \(error!)")
expUpdate.fulfill()
XCTAssert(false)
return
}
XCTAssertFalse(Client.configuration.eligibleForTrial)
expUpdate.fulfill()
}
waitForExpectations(timeout: 5.0, handler: nil)
}
private func __testRetrieveSubscriptionPlans(webServices: PIAWebServices) {
let exp = expectation(description: "subscription.plans")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment