Skip to content

Commit

Permalink
MOB-xxxx [Retain follow code] (#6)
Browse files Browse the repository at this point in the history
* followCode persisted

* add tests

* update parameter

* bump version
  • Loading branch information
airlacodes committed May 4, 2020
1 parent a984054 commit 0503ad0
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 19 deletions.
2 changes: 1 addition & 1 deletion KarhooSDK.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "KarhooSDK"
s.version = "1.0.1"
s.version = "1.1.0"
s.summary = "Karhoo Network SDK"
s.homepage = "https://docs.stg.karhoo.net/v1/mobilesdk/network"
s.license = 'MIT'
Expand Down
4 changes: 2 additions & 2 deletions KarhooSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3715,7 +3715,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 1.0.0;
MARKETING_VERSION = 1.1.0;
MODULEMAP_PRIVATE_FILE = "";
PRODUCT_BUNDLE_IDENTIFIER = se.bespokecode.KarhooSDK;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down Expand Up @@ -3753,7 +3753,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 1.0.0;
MARKETING_VERSION = 1.1.0;
MODULEMAP_PRIVATE_FILE = "";
PRODUCT_BUNDLE_IDENTIFIER = se.bespokecode.KarhooSDK;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
6 changes: 3 additions & 3 deletions KarhooSDK/Service/Trip/KarhooTripService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ final class KarhooTripService: TripService {
return Call(executable: tripSearchInteractor)
}

func trackTrip(tripId: String) -> PollCall<TripInfo> {
let interactor = KarhooTripUpdateInteractor(tripId: tripId)
return tripPollFactory.shared(identifier: tripId,
func trackTrip(identifier: String) -> PollCall<TripInfo> {
let interactor = KarhooTripUpdateInteractor(identifier: identifier)
return tripPollFactory.shared(identifier: identifier,
executable: interactor)
}

Expand Down
2 changes: 1 addition & 1 deletion KarhooSDK/Service/Trip/TripService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public protocol TripService {

func search(tripSearch: TripSearch) -> Call<[TripInfo]>

func trackTrip(tripId: String) -> PollCall<TripInfo>
func trackTrip(identifier: String) -> PollCall<TripInfo>

func status(tripId: String) -> PollCall<TripState>
}
31 changes: 25 additions & 6 deletions KarhooSDK/Service/Trip/TripUpdate/KarhooTripUpdateInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,32 @@ import Foundation

final class KarhooTripUpdateInteractor: TripUpdateInteractor {

private let tripId: String
private let identifier: String
private let requestSender: RequestSender

init(tripId: String,
init(identifier: String,
requestSender: RequestSender = KarhooRequestSender(httpClient: TokenRefreshingHttpClient.shared)) {
self.tripId = tripId
self.identifier = identifier
self.requestSender = requestSender
}

func execute<T: KarhooCodableModel>(callback: @escaping CallbackClosure<T>) {
requestSender.requestAndDecode(payload: nil,
endpoint: endpoint(),
callback: callback)
callback: { [weak self] (result: Result<TripInfo>) in
switch result {
case .success(var response):
self?.addFollowCodeToResponse(&response)

guard let trip = response as? T else {
return
}

callback(.success(result: trip))
case .failure(let error):
callback(.failure(error: error))
}
})
}

func cancel() {
Expand All @@ -31,8 +44,14 @@ final class KarhooTripUpdateInteractor: TripUpdateInteractor {

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

private func addFollowCodeToResponse(_ trip: inout TripInfo) {
if Karhoo.configuration.authenticationMethod().isGuest() {
trip.followCode = identifier
}
return .trackTrip(identifier: tripId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ final class AuthLoginMethodSpec: XCTestCase {
expectation.fulfill()
})

waitForExpectations(timeout: 1)
waitForExpectations(timeout: 5)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class TrackTripMethodSpec: XCTestCase {

tripService = Karhoo.getTripService()

pollCall = tripService.trackTrip(tripId: "123")
pollCall = tripService.trackTrip(identifier: "123")
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ final class KarhooTripServiceSpec: XCTestCase {
*/
func testTrackTrip() {
let expectedTripId = "12345"
_ = testObject.trackTrip(tripId: expectedTripId)
_ = testObject.trackTrip(identifier: expectedTripId)

XCTAssertNotNil(mocktripPollFactory.executableSet)
XCTAssertEqual(expectedTripId, mocktripPollFactory.identifierSet)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class KarhooTripUpdateInteractortSpec: XCTestCase {
super.setUp()
MockSDKConfig.authenticationMethod = .karhooUser
mockTripUpdateRequest = MockRequestSender()
testObject = KarhooTripUpdateInteractor(tripId: tripId,
testObject = KarhooTripUpdateInteractor(identifier: tripId,
requestSender: mockTripUpdateRequest)
}

Expand Down Expand Up @@ -78,11 +78,18 @@ class KarhooTripUpdateInteractortSpec: XCTestCase {
/**
* When: Tracking as a guest
* Then: Track with follow code endpoint
* And: Follow code is populated
*/
func testGuestTripUpdateUsesFollowCode() {
MockSDKConfig.authenticationMethod = .guest(settings: MockSDKConfig.guestSettings)
testObject.execute(callback: { (_: Result<TripInfo>) in })
testObject.execute(callback: { (result: Result<TripInfo>) in
XCTAssertEqual("TRIP_ID", result.successValue()?.followCode)
})

mockTripUpdateRequest.assertRequestSendAndDecoded(endpoint: .trackTripFollowCode(followCode: tripId),
method: .get)

let mockResponse = TripInfoMock().set(tripId: "123").build()
mockTripUpdateRequest.triggerSuccessWithDecoded(value: mockResponse)
}
}
2 changes: 1 addition & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 347317e030faba7d076fadb56afec484d3618f62

COCOAPODS: 1.9.0.beta.3
COCOAPODS: 1.9.1

0 comments on commit 0503ad0

Please sign in to comment.