Skip to content

Commit

Permalink
Merge pull request #5 from karhoo/MOB-2652
Browse files Browse the repository at this point in the history
MOB-2652 [Cancel / Track Follow Code support]
  • Loading branch information
airlacodes authored Apr 28, 2020
2 parents 7e021df + 165b6e6 commit a984054
Show file tree
Hide file tree
Showing 20 changed files with 113 additions and 67 deletions.
16 changes: 8 additions & 8 deletions KarhooSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
09928D2B20EFAABA00B9F462 /* KarhooQuoteInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09928D2020EFAABA00B9F462 /* KarhooQuoteInteractor.swift */; };
09928D2C20EFAABA00B9F462 /* QuoteInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09928D2120EFAABA00B9F462 /* QuoteInteractor.swift */; };
09928D3720EFAAEE00B9F462 /* KarhooQuoteServiceSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09928D3220EFAAEE00B9F462 /* KarhooQuoteServiceSpec.swift */; };
09928D3820EFAAEE00B9F462 /* KarhooQuoteInteractorSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09928D3420EFAAEE00B9F462 /* KarhooQuoteInteractorSpec.swift */; };
09928D4520EFAB1300B9F462 /* MockQuoteInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09928D4120EFAB1300B9F462 /* MockQuoteInteractor.swift */; };
09928D4720EFAB3000B9F462 /* QuoteSearch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09928D4620EFAB3000B9F462 /* QuoteSearch.swift */; };
09928D4920EFAB9300B9F462 /* Quotes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09928D4820EFAB9300B9F462 /* Quotes.swift */; };
Expand Down Expand Up @@ -285,7 +284,6 @@
43F939A31F3C85A300914E18 /* JsonHttpRequestBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43F9399A1F3C85A300914E18 /* JsonHttpRequestBuilder.swift */; };
43F939A41F3C85A300914E18 /* KarhooEnvironmentDetails.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43F9399B1F3C85A300914E18 /* KarhooEnvironmentDetails.swift */; };
43F939A51F3C85A300914E18 /* URLSessionSender.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43F9399C1F3C85A300914E18 /* URLSessionSender.swift */; };
43F939B51F3CD33200914E18 /* JsonHttpClientSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43F939B01F3CD33200914E18 /* JsonHttpClientSpec.swift */; };
43F939B61F3CD33200914E18 /* JsonHttpRequestBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43F939B11F3CD33200914E18 /* JsonHttpRequestBuilderSpec.swift */; };
5C076FFF20F23B5F00A35537 /* CategoryQuoteMapperSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C076FFE20F23B5F00A35537 /* CategoryQuoteMapperSpec.swift */; };
5C08DFB120E5A8D7002203CB /* MockContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C08DFB020E5A8D7002203CB /* MockContext.swift */; };
Expand All @@ -306,6 +304,8 @@
5C2856E220E3B184009B9464 /* KarhooReverseGeocodeProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C2856DD20E3B183009B9464 /* KarhooReverseGeocodeProviderSpec.swift */; };
5C2856F220E3B1DD009B9464 /* LocationInfoMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C2856F120E3B1DC009B9464 /* LocationInfoMock.swift */; };
5C2E265024282B0400B1FF0C /* KarhooAddPaymentDetailsSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 090E0164223FAB6E005D1CB7 /* KarhooAddPaymentDetailsSpec.swift */; };
5C3C66D8245718BE00C736E9 /* JsonHttpClientSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43F939B01F3CD33200914E18 /* JsonHttpClientSpec.swift */; };
5C3C66DA24571A5600C736E9 /* KarhooQuoteInteractorSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C3C66D924571A5600C736E9 /* KarhooQuoteInteractorSpec.swift */; };
5C5BE90D2411A513005DD14E /* AuthenticationMethod.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C5BE90C2411A513005DD14E /* AuthenticationMethod.swift */; };
5C75D6572080E4E60065133B /* KarhooCodableModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C75D6562080E4E60065133B /* KarhooCodableModel.swift */; };
5C75D65D208CC84E0065133B /* LocationDetailsAddress.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C75D65C208CC84E0065133B /* LocationDetailsAddress.swift */; };
Expand Down Expand Up @@ -508,7 +508,6 @@
09928D2020EFAABA00B9F462 /* KarhooQuoteInteractor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KarhooQuoteInteractor.swift; sourceTree = "<group>"; };
09928D2120EFAABA00B9F462 /* QuoteInteractor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QuoteInteractor.swift; sourceTree = "<group>"; };
09928D3220EFAAEE00B9F462 /* KarhooQuoteServiceSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KarhooQuoteServiceSpec.swift; sourceTree = "<group>"; };
09928D3420EFAAEE00B9F462 /* KarhooQuoteInteractorSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KarhooQuoteInteractorSpec.swift; sourceTree = "<group>"; };
09928D4120EFAB1300B9F462 /* MockQuoteInteractor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MockQuoteInteractor.swift; sourceTree = "<group>"; };
09928D4620EFAB3000B9F462 /* QuoteSearch.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QuoteSearch.swift; sourceTree = "<group>"; };
09928D4820EFAB9300B9F462 /* Quotes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Quotes.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -726,6 +725,7 @@
5C2856CC20E3B127009B9464 /* ReverseGeocodeInteractor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReverseGeocodeInteractor.swift; sourceTree = "<group>"; };
5C2856DD20E3B183009B9464 /* KarhooReverseGeocodeProviderSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KarhooReverseGeocodeProviderSpec.swift; sourceTree = "<group>"; };
5C2856F120E3B1DC009B9464 /* LocationInfoMock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocationInfoMock.swift; sourceTree = "<group>"; };
5C3C66D924571A5600C736E9 /* KarhooQuoteInteractorSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KarhooQuoteInteractorSpec.swift; sourceTree = "<group>"; };
5C5BE90C2411A513005DD14E /* AuthenticationMethod.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthenticationMethod.swift; sourceTree = "<group>"; };
5C75D6562080E4E60065133B /* KarhooCodableModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KarhooCodableModel.swift; sourceTree = "<group>"; };
5C75D65C208CC84E0065133B /* LocationDetailsAddress.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationDetailsAddress.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1169,7 +1169,7 @@
09928D3320EFAAEE00B9F462 /* Interactor */ = {
isa = PBXGroup;
children = (
09928D3420EFAAEE00B9F462 /* KarhooQuoteInteractorSpec.swift */,
5C3C66D924571A5600C736E9 /* KarhooQuoteInteractorSpec.swift */,
);
path = Interactor;
sourceTree = "<group>";
Expand Down Expand Up @@ -3034,15 +3034,15 @@
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-KarhooSDKIntegrationTests/Pods-KarhooSDKIntegrationTests-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/OHHTTPStubs/OHHTTPStubs.framework",
"${BUILT_PRODUCTS_DIR}/KeychainSwift/KeychainSwift.framework",
"${BUILT_PRODUCTS_DIR}/ReachabilitySwift/Reachability.framework",
"${BUILT_PRODUCTS_DIR}/OHHTTPStubs/OHHTTPStubs.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/OHHTTPStubs.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/KeychainSwift.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Reachability.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/OHHTTPStubs.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
Expand Down Expand Up @@ -3341,11 +3341,11 @@
5C2856E220E3B184009B9464 /* KarhooReverseGeocodeProviderSpec.swift in Sources */,
4032BD1423FC5B2300C2409B /* KarhooAuthLoginInteractorSpec.swift in Sources */,
43588C661EBB675100D03765 /* TestUtil.swift in Sources */,
5C3C66DA24571A5600C736E9 /* KarhooQuoteInteractorSpec.swift in Sources */,
31A1AD631F39E1E200BFE24B /* MockHttpClient.swift in Sources */,
0970BA7E211464C40015A170 /* MockExecutable.swift in Sources */,
31005DA71FCEE699006D2A7D /* RequestTesting.swift in Sources */,
43584E931EE5993700B4DFAB /* KarhooTripServiceSpec.swift in Sources */,
09928D3820EFAAEE00B9F462 /* KarhooQuoteInteractorSpec.swift in Sources */,
31904CDA200380A400BA7402 /* MockAccessTokenProvider.swift in Sources */,
4371C5BE1EB0E8070059429D /* KarhooAddressServiceSpec.swift in Sources */,
317610EE1FD84CD200D2DB75 /* KarhooNetworkDateFormatterSpec.swift in Sources */,
Expand Down Expand Up @@ -3391,10 +3391,10 @@
09F79E47223AAA6600D5B0B8 /* MockGetNonceInteractor.swift in Sources */,
31904CD82003800000BA7402 /* TokenRefreshingHttpClientSpec.swift in Sources */,
43584E9F1EE6A3D400B4DFAB /* MockUserDefaults.swift in Sources */,
43F939B51F3CD33200914E18 /* JsonHttpClientSpec.swift in Sources */,
310D44AE1FA1F8890038BFDA /* TimestampFormatterSpec.swift in Sources */,
095A03CD2333B3F8007D805E /* KarhooUIConfigInteractorSpec.swift in Sources */,
2742197A13ACCCDBAE32D13A /* HeaderProviderSpec.swift in Sources */,
5C3C66D8245718BE00C736E9 /* JsonHttpClientSpec.swift in Sources */,
09F79E3F2239723200D5B0B8 /* KarhooGetNonceInteractorSpec.swift in Sources */,
5C2E265024282B0400B1FF0C /* KarhooAddPaymentDetailsSpec.swift in Sources */,
5C08DFB420E5A92A002203CB /* MockAnalyticsProvider.swift in Sources */,
Expand Down
6 changes: 6 additions & 0 deletions KarhooSDK/Api/Response/TripInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Foundation
public struct TripInfo: KarhooCodableModel {

public let tripId: String
public var followCode: String
public let displayId: String
public let state: TripState
public let vehicle: Vehicle
Expand All @@ -29,6 +30,7 @@ public struct TripInfo: KarhooCodableModel {

public init(tripId: String = "",
displayId: String = "",
followCode: String = "",
origin: TripLocationDetails = TripLocationDetails(),
destination: TripLocationDetails? = nil,
dateScheduled: Date? = nil,
Expand All @@ -41,6 +43,7 @@ public struct TripInfo: KarhooCodableModel {
fare: TripFare = TripFare()) {
self.tripId = tripId
self.displayId = displayId
self.followCode = followCode
self.state = state
self.vehicle = vehicle
self.tripQuote = quote
Expand All @@ -57,6 +60,7 @@ public struct TripInfo: KarhooCodableModel {
let container = try decoder.container(keyedBy: CodingKeys.self)

self.tripId = (try? container.decode(String.self, forKey: .tripId)) ?? ""
self.followCode = (try? container.decode(String.self, forKey: .followCode)) ?? ""
self.displayId = (try? container.decode(String.self, forKey: .displayId)) ?? ""
self.origin = (try? container.decode(TripLocationDetails.self, forKey: .origin)) ?? TripLocationDetails()
self.destination = (try? container.decode(TripLocationDetails.self,
Expand All @@ -82,6 +86,7 @@ public struct TripInfo: KarhooCodableModel {
var container = encoder.container(keyedBy: CodingKeys.self)

try container.encode(tripId, forKey: .tripId)
try container.encode(followCode, forKey: .followCode)
try container.encode(displayId, forKey: .displayId)
try container.encode(dateScheduled, forKey: .dateScheduled)
try container.encode(origin, forKey: .origin)
Expand All @@ -98,6 +103,7 @@ public struct TripInfo: KarhooCodableModel {
enum CodingKeys: String, CodingKey {
case tripId = "id"
case displayId = "display_trip_id"
case followCode = "follow_code"
case state = "status"
case origin
case destination = "destination"
Expand Down
4 changes: 4 additions & 0 deletions KarhooSDK/Api/SDKConfiguration/AuthenticationMethod.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ public enum AuthenticationMethod {
default: return nil
}
}

public func isGuest() -> Bool {
return guestSettings != nil
}
}
8 changes: 8 additions & 0 deletions KarhooSDK/Network/APIEndpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ enum APIEndpoint {
case bookTrip
case bookTripWithNonce
case cancelTrip(identifier: String)
case cancelTripFollowCode(followCode: String)
case trackDriver(identifier: String)
case trackTrip(identifier: String)
case trackTripFollowCode(followCode: String)
case tripSearch
case tripStatus(identifier: String)
case getFareDetails(identifier: String)
Expand Down Expand Up @@ -53,10 +55,14 @@ enum APIEndpoint {
return "/bookings/with-nonce"
case .cancelTrip(let identifier):
return "/bookings/\(identifier)/cancel"
case .cancelTripFollowCode(let followCode):
return "/bookings/follow/\(followCode)/cancel"
case .trackDriver(let identifier):
return "/bookings/\(identifier)/track"
case .trackTrip(let identifier):
return "/bookings/\(identifier)"
case .trackTripFollowCode(let followCode):
return "/bookings/follow/\(followCode)"
case .tripSearch:
return "/bookings/search"
case .tripStatus(let identifier):
Expand Down Expand Up @@ -109,8 +115,10 @@ enum APIEndpoint {
case .bookTrip: return .post
case .bookTripWithNonce: return .post
case .cancelTrip: return .post
case .cancelTripFollowCode: return .post
case .trackDriver: return .get
case .trackTrip: return .get
case .trackTripFollowCode: return .get
case .tripSearch: return .post
case .tripStatus: return .get
case .getFareDetails: return .get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class KarhooCancelTripInteractor: CancelTripInteractor {
let payload = CancelTripRequestPayload(reason: tripCancellation.cancelReason)

requestSender.request(payload: payload,
endpoint: .cancelTrip(identifier: tripCancellation.tripId),
endpoint: endpoint(identifier: tripCancellation.tripId),
callback: { result in
guard result.successValue(orErrorCallback: callback) != nil,
let resultValue = KarhooVoid() as? T else { return }
Expand All @@ -45,4 +45,12 @@ final class KarhooCancelTripInteractor: CancelTripInteractor {
func cancel() {
requestSender.cancelNetworkRequest()
}

private func endpoint(identifier: String) -> APIEndpoint {
if Karhoo.configuration.authenticationMethod().isGuest() {
return .cancelTripFollowCode(followCode: identifier)
}

return .cancelTrip(identifier: identifier)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,18 @@ final class KarhooTripUpdateInteractor: TripUpdateInteractor {

func execute<T: KarhooCodableModel>(callback: @escaping CallbackClosure<T>) {
requestSender.requestAndDecode(payload: nil,
endpoint: .trackTrip(identifier: tripId),
endpoint: endpoint(),
callback: callback)
}

func cancel() {
requestSender.cancelNetworkRequest()
}

private func endpoint() -> APIEndpoint {
if Karhoo.configuration.authenticationMethod().isGuest() {
return .trackTripFollowCode(followCode: tripId)
}
return .trackTrip(identifier: tripId)
}
}
1 change: 1 addition & 0 deletions KarhooSDKIntegrationTests/JSON/Trip/TripInfo.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"id": "b6a5f9dc-9066-4252-9013-be85dfa563bc",
"follow_code": "1234",
"passengers": {
"additional_passengers": 0,
"passenger_details": [
Expand Down
10 changes: 5 additions & 5 deletions KarhooSDKIntegrationTests/Service/Auth/AuthLoginMethodSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ final class AuthLoginMethodSpec: XCTestCase {

override func setUp() {
super.setUp()
MockSDKConfig.authenticationMethod = .tokenExchange(settings: MockSDKConfig.tokenExchangeSettings)
authService = Karhoo.getAuthService()

call = authService.login(token: "aasdasdadqdqwd")
}

Expand All @@ -38,7 +38,7 @@ final class AuthLoginMethodSpec: XCTestCase {
expectation.fulfill()
})

waitForExpectations(timeout: 1)
waitForExpectations(timeout: 0.5)
}

/**
Expand Down Expand Up @@ -68,7 +68,7 @@ final class AuthLoginMethodSpec: XCTestCase {

let expectation = self.expectation(description: "Calls callback with expected result")
call.execute(callback: { result in
XCTAssertFalse(result.isSuccess())
XCTAssertNil(result.successValue()?.userId)
expectation.fulfill()
})

Expand Down Expand Up @@ -102,15 +102,15 @@ final class AuthLoginMethodSpec: XCTestCase {
*/
func testUserLoginAuthTokenInvalid() {
NetworkStub.successResponse(jsonFile: "AuthExchangeToken.json", path: exchangeTokenPath)
NetworkStub.responseWithInvalidData(path: exchangeTokenPath, statusCode: 200)
NetworkStub.responseWithInvalidData(path: exchangeTokenPath, statusCode: 401)

let expectation = self.expectation(description: "Calls callback with expected result")
call.execute(callback: { result in
XCTAssertFalse(result.isSuccess())
expectation.fulfill()
})

waitForExpectations(timeout: 1)
waitForExpectations(timeout: 0.5)
}

/**
Expand Down
15 changes: 8 additions & 7 deletions KarhooSDKIntegrationTests/Service/Auth/RevokeMethodSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,24 @@ final class AuthRevokeMethodSpec: XCTestCase {

override func setUp() {
super.setUp()
MockSDKConfig.authenticationMethod = .tokenExchange(settings: MockSDKConfig.tokenExchangeSettings)
authenticate()
authService = Karhoo.getAuthService()

call = authService.revoke()
}

private func authenticate() {
NetworkStub.successResponse(jsonFile: "AuthToken.json", path: "/v1/auth/token")
NetworkStub.successResponse(jsonFile: "AuthorisedUserInfo.json", path: "/v1/directory/users/me")
NetworkStub.successResponse(jsonFile: "AuthToken.json", path: "/karhoo/anonymous/token-exchange")
NetworkStub.successResponse(jsonFile: "AuthorisedUserInfo.json", path: "/oauth/v2/userinfo")

let expectation = self.expectation(description: "calls the callback with success")

Karhoo.getUserService().login(userLogin: UserLogin(username: "mock",
password: "mock")).execute(callback: { _ in
expectation.fulfill()
})
waitForExpectations(timeout: 1)
Karhoo.getAuthService().login(token: "123").execute(callback: { _ in
expectation.fulfill()
})

waitForExpectations(timeout: 2)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ final class BookTripMethodSpec: XCTestCase {
return
}
XCTAssertEqual("b6a5f9dc-9066-4252-9013-be85dfa563bc", trip.tripId)
XCTAssertEqual("1234", trip.followCode)
XCTAssertEqual(.requested, trip.state)
XCTAssertEqual("EhpCcm93bmVsbCBTdCwgU2hlZmZpZWxkLCBVSw", trip.origin.placeId)
XCTAssertEqual("EhpCcm93bmVsbCBTdCwgU2hlZmZpZWxkLCBVSw", trip.destination!.placeId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,6 @@ final class TripStatusMethodSpec: XCTestCase {
}
}
pollCall.observable(pollTime: 0.1).subscribe(observer: observer)
waitForExpectations(timeout: 1)
waitForExpectations(timeout: 2)
}
}
5 changes: 3 additions & 2 deletions KarhooSDKIntegrationTests/Service/User/LoginMethodSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ final class LoginMethodSpec: XCTestCase {

override func setUp() {
super.setUp()

MockSDKConfig.authenticationMethod = .karhooUser

userService = Karhoo.getUserService()
tearDown()

Expand Down Expand Up @@ -124,7 +125,7 @@ final class LoginMethodSpec: XCTestCase {
expectation.fulfill()
})

waitForExpectations(timeout: 1)
waitForExpectations(timeout: 0.5)
}

/**
Expand Down
Loading

0 comments on commit a984054

Please sign in to comment.