Commit 7b00bd19 authored by Jose Blaya's avatar Jose Blaya
Browse files

unit test for friend referral api

parent a92b08e5
......@@ -257,6 +257,8 @@
84D5DA702126CE2900F753F8 /* QRCameraScannerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D5DA6F2126CE2900F753F8 /* QRCameraScannerViewController.swift */; };
DD0AC790218715B8009B576B /* PIAButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD0AC78F218715B8009B576B /* PIAButton.swift */; };
DD0DE85022366090002A6E82 /* GDPRViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD0DE84F22366090002A6E82 /* GDPRViewController.swift */; };
DD22D23B22F4292B00DFFB6C /* FriendReferralTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD22D23A22F4292B00DFFB6C /* FriendReferralTests.swift */; };
DD22D23C22F4292B00DFFB6C /* FriendReferralTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD22D23A22F4292B00DFFB6C /* FriendReferralTests.swift */; };
DD31498F21834B3F008E26E8 /* GetStartedViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD31498E21834B3F008E26E8 /* GetStartedViewController.swift */; };
DD314990218350D1008E26E8 /* SwiftGen+ScenesStoryboards.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDC812472176166500CB290C /* SwiftGen+ScenesStoryboards.swift */; };
DD314991218350D1008E26E8 /* SwiftGen+SeguesStoryboards.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDC81249217617F900CB290C /* SwiftGen+SeguesStoryboards.swift */; };
......@@ -557,6 +559,7 @@
D205D5A277A5CF0016FEABA7 /* Pods-PIALibrary-PIALibraryHost-iOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PIALibrary-PIALibraryHost-iOS.debug.xcconfig"; path = "Pods/Target Support Files/Pods-PIALibrary-PIALibraryHost-iOS/Pods-PIALibrary-PIALibraryHost-iOS.debug.xcconfig"; sourceTree = "<group>"; };
DD0AC78F218715B8009B576B /* PIAButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PIAButton.swift; sourceTree = "<group>"; };
DD0DE84F22366090002A6E82 /* GDPRViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = GDPRViewController.swift; path = PIALibrary/Sources/UI/iOS/GDPRViewController.swift; sourceTree = SOURCE_ROOT; };
DD22D23A22F4292B00DFFB6C /* FriendReferralTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FriendReferralTests.swift; sourceTree = "<group>"; };
DD31498E21834B3F008E26E8 /* GetStartedViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetStartedViewController.swift; sourceTree = "<group>"; };
DD36CB7D21CCFFFB00FC815A /* CAGradientLayer+Image.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CAGradientLayer+Image.swift"; sourceTree = "<group>"; };
DD56E3F3225F5D22002EDFB2 /* GlossProduct.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GlossProduct.swift; sourceTree = "<group>"; };
......@@ -1026,6 +1029,7 @@
841BE60C212AD0F3002EF2D1 /* ValidatorTests.swift */,
841BE611212AFFA7002EF2D1 /* GiftCardUtilTests.swift */,
DDE27E0322E1B1A700503A89 /* ProductTests.swift */,
DD22D23A22F4292B00DFFB6C /* FriendReferralTests.swift */,
0EE78B011F818A20002E4CDD /* Info-iOS.plist */,
0E2ADD201FE13B8600BB170C /* Info-macOS.plist */,
);
......@@ -1597,6 +1601,7 @@
files = (
0E2ADD291FE13C3B00BB170C /* ServerTests.swift in Sources */,
843C67C32122EA13005A3FDA /* AccountInfoTests.swift in Sources */,
DD22D23C22F4292B00DFFB6C /* FriendReferralTests.swift in Sources */,
0E2ADD461FE1583A00BB170C /* VPNTests.swift in Sources */,
0E53A85B1FE5E3CD000C2A18 /* MockProviders.swift in Sources */,
0E2ADD281FE13C3B00BB170C /* AccountTests.swift in Sources */,
......@@ -1885,6 +1890,7 @@
0EB8C0461F9CCB7C005857E4 /* AccountSignupTests.swift in Sources */,
0E2ADD451FE1583A00BB170C /* VPNTests.swift in Sources */,
841BE612212AFFA7002EF2D1 /* GiftCardUtilTests.swift in Sources */,
DD22D23B22F4292B00DFFB6C /* FriendReferralTests.swift in Sources */,
DDE27E0422E1B1A700503A89 /* ProductTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
......
......@@ -56,5 +56,8 @@ public enum ClientError: String, Error {
/// The account is not renewable.
case renewingNonRenewable
/// Invalid parameter
case invalidParameter
#endif
}
......@@ -286,6 +286,11 @@ class PIAWebServices: WebServices, ConfigurationAccess {
401: .unauthorized
]
if email.isEmpty {
callback?(ClientError.invalidParameter)
return
}
let parameters = ["invitee_name": name,
"invitee_email": email]
......
......@@ -72,12 +72,23 @@ class MockWebServices: WebServices {
}
func invitesInformation(_ callback: LibraryCallback<InvitesInformation>?) {
let result = invitesInformation?()
let error: ClientError? = (result == nil) ? .unsupported : nil
callback?(result, error)
let result = InvitesInformation(totalInvitesSent: 10,
totalInvitesRewarded: 2,
totalFreeDaysGiven: 34,
uniqueReferralLink: "http://www.privateinternetaccess.com",
invites: [Invites(rewarded: true, accepted: true, obfuscatedEmail: "a***@***.com", gracePeriodRemaining: ""),
Invites(rewarded: false, accepted: true, obfuscatedEmail: "b***@***.com", gracePeriodRemaining: "")])
callback?(result, nil)
}
func invite(credentials: Credentials, name: String, email: String, _ callback: SuccessLibraryCallback?) {
if email.isEmpty {
callback?(ClientError.invalidParameter)
return
}
callback?(nil)
}
......
......@@ -26,6 +26,7 @@ class AccountInfoTests: XCTestCase {
isRenewable: false,
isRecurring: false,
expirationDate: self.theDate,
canInvite: true,
shouldPresentExpirationAlert: false,
renewUrl: nil)
}
......
//
// FriendReferralTests.swift
// PIALibrary
//
// Created by Jose Antonio Blaya Garcia on 02/08/2019.
// Copyright © 2019 London Trust Media. All rights reserved.
//
import XCTest
@testable import PIALibrary
class FriendReferralTests: XCTestCase {
private let mock = MockProviders()
override func setUp() {
// Put setup code here. This method is called before the invocation of each test method in the class.
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}
func testFriendReferral() {
let expInviteInformation = expectation(description: "invitesInformation")
Client.providers.accountProvider.invitesInformation( { (invites, error) in
guard let _ = invites else {
print("invites information error: \(error!)")
expInviteInformation.fulfill()
XCTAssert(false)
return
}
XCTAssertNotNil(invites?.uniqueReferralLink, "referral link cant be nil")
expInviteInformation.fulfill()
})
waitForExpectations(timeout: 5.0, handler: nil)
}
func testInviteFriends() {
__testLogin(factory: mock)
__testInviteFriend()
__testInviteFriendInvalidEmail()
__testLogout(factory: mock)
}
func __testInviteFriend() {
let expInvite = expectation(description: "inviteFriend")
Client.providers.accountProvider.invite(name: "John", email: "qwerty@keyboard.com", { error in
XCTAssertNil(error, "error should be nil")
expInvite.fulfill()
})
waitForExpectations(timeout: 5.0, handler: nil)
}
func __testInviteFriendInvalidEmail() {
let expInvite = expectation(description: "inviteFriend")
Client.providers.accountProvider.invite(name: "John", email: "", { error in
XCTAssertNotNil(error, "should raise a .invalidParameter error")
expInvite.fulfill()
})
waitForExpectations(timeout: 5.0, handler: nil)
}
private func __testLogin(factory: Client.Providers) {
let expLogin = expectation(description: "login")
let credentials = Credentials(username: "p0000000", password: "foobarbogus")
factory.accountProvider.login(with: LoginRequest(credentials: credentials)) { (user, error) in
guard let _ = user else {
print("Login error: \(error!)")
expLogin.fulfill()
XCTAssert(false)
return
}
XCTAssert(factory.accountProvider.isLoggedIn)
XCTAssertNotNil(factory.accountProvider.currentUser)
print("Logged in with: \(factory.accountProvider.currentUser!)")
expLogin.fulfill()
}
waitForExpectations(timeout: 5.0, handler: nil)
}
private func __testLogout(factory: Client.Providers) {
let expLogout = expectation(description: "logout")
factory.accountProvider.logout { (error) in
if let error = error {
print("Logout error: \(error)")
expLogout.fulfill()
XCTAssert(false)
return
}
XCTAssert(!factory.accountProvider.isLoggedIn)
XCTAssertNil(factory.accountProvider.currentUser)
XCTAssertNil(factory.accountProvider.currentUser?.info)
print("Logged out")
expLogout.fulfill()
}
waitForExpectations(timeout: 5.0, handler: nil)
}
}
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