From 0503ad0367f243cae4fe99010836e9cdd93fe662 Mon Sep 17 00:00:00 2001 From: Jeevan Thandi Date: Mon, 4 May 2020 11:17:23 +0100 Subject: [PATCH] MOB-xxxx [Retain follow code] (#6) * followCode persisted * add tests * update parameter * bump version --- KarhooSDK.podspec | 2 +- KarhooSDK.xcodeproj/project.pbxproj | 4 +-- .../Service/Trip/KarhooTripService.swift | 6 ++-- KarhooSDK/Service/Trip/TripService.swift | 2 +- .../KarhooTripUpdateInteractor.swift | 31 +++++++++++++++---- .../Service/Auth/AuthLoginMethodSpec.swift | 2 +- .../Service/Trip/TrackTripMethodSpec.swift | 2 +- .../Service/Trips/KarhooTripServiceSpec.swift | 2 +- .../KarhooTripUpdateInteractortSpec.swift | 11 +++++-- Podfile.lock | 2 +- 10 files changed, 45 insertions(+), 19 deletions(-) diff --git a/KarhooSDK.podspec b/KarhooSDK.podspec index 5907ae5f..e097b3bb 100644 --- a/KarhooSDK.podspec +++ b/KarhooSDK.podspec @@ -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' diff --git a/KarhooSDK.xcodeproj/project.pbxproj b/KarhooSDK.xcodeproj/project.pbxproj index 239de9cc..1bece6e6 100644 --- a/KarhooSDK.xcodeproj/project.pbxproj +++ b/KarhooSDK.xcodeproj/project.pbxproj @@ -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)"; @@ -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)"; diff --git a/KarhooSDK/Service/Trip/KarhooTripService.swift b/KarhooSDK/Service/Trip/KarhooTripService.swift index ca623f28..d885200e 100644 --- a/KarhooSDK/Service/Trip/KarhooTripService.swift +++ b/KarhooSDK/Service/Trip/KarhooTripService.swift @@ -46,9 +46,9 @@ final class KarhooTripService: TripService { return Call(executable: tripSearchInteractor) } - func trackTrip(tripId: String) -> PollCall { - let interactor = KarhooTripUpdateInteractor(tripId: tripId) - return tripPollFactory.shared(identifier: tripId, + func trackTrip(identifier: String) -> PollCall { + let interactor = KarhooTripUpdateInteractor(identifier: identifier) + return tripPollFactory.shared(identifier: identifier, executable: interactor) } diff --git a/KarhooSDK/Service/Trip/TripService.swift b/KarhooSDK/Service/Trip/TripService.swift index 55bfad6b..c1bd52bb 100644 --- a/KarhooSDK/Service/Trip/TripService.swift +++ b/KarhooSDK/Service/Trip/TripService.swift @@ -15,7 +15,7 @@ public protocol TripService { func search(tripSearch: TripSearch) -> Call<[TripInfo]> - func trackTrip(tripId: String) -> PollCall + func trackTrip(identifier: String) -> PollCall func status(tripId: String) -> PollCall } diff --git a/KarhooSDK/Service/Trip/TripUpdate/KarhooTripUpdateInteractor.swift b/KarhooSDK/Service/Trip/TripUpdate/KarhooTripUpdateInteractor.swift index 1f00a88c..51b5b0a4 100644 --- a/KarhooSDK/Service/Trip/TripUpdate/KarhooTripUpdateInteractor.swift +++ b/KarhooSDK/Service/Trip/TripUpdate/KarhooTripUpdateInteractor.swift @@ -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(callback: @escaping CallbackClosure) { requestSender.requestAndDecode(payload: nil, endpoint: endpoint(), - callback: callback) + callback: { [weak self] (result: Result) 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() { @@ -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) } } diff --git a/KarhooSDKIntegrationTests/Service/Auth/AuthLoginMethodSpec.swift b/KarhooSDKIntegrationTests/Service/Auth/AuthLoginMethodSpec.swift index 8fef4c54..276b65a5 100644 --- a/KarhooSDKIntegrationTests/Service/Auth/AuthLoginMethodSpec.swift +++ b/KarhooSDKIntegrationTests/Service/Auth/AuthLoginMethodSpec.swift @@ -72,7 +72,7 @@ final class AuthLoginMethodSpec: XCTestCase { expectation.fulfill() }) - waitForExpectations(timeout: 1) + waitForExpectations(timeout: 5) } /** diff --git a/KarhooSDKIntegrationTests/Service/Trip/TrackTripMethodSpec.swift b/KarhooSDKIntegrationTests/Service/Trip/TrackTripMethodSpec.swift index ad5e3350..98a1e753 100644 --- a/KarhooSDKIntegrationTests/Service/Trip/TrackTripMethodSpec.swift +++ b/KarhooSDKIntegrationTests/Service/Trip/TrackTripMethodSpec.swift @@ -22,7 +22,7 @@ final class TrackTripMethodSpec: XCTestCase { tripService = Karhoo.getTripService() - pollCall = tripService.trackTrip(tripId: "123") + pollCall = tripService.trackTrip(identifier: "123") } /** diff --git a/KarhooSDKTests/TestCases/Service/Trips/KarhooTripServiceSpec.swift b/KarhooSDKTests/TestCases/Service/Trips/KarhooTripServiceSpec.swift index 2b2b116c..d383beb4 100644 --- a/KarhooSDKTests/TestCases/Service/Trips/KarhooTripServiceSpec.swift +++ b/KarhooSDKTests/TestCases/Service/Trips/KarhooTripServiceSpec.swift @@ -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) diff --git a/KarhooSDKTests/TestCases/Service/Trips/TripUpdate/KarhooTripUpdateInteractortSpec.swift b/KarhooSDKTests/TestCases/Service/Trips/TripUpdate/KarhooTripUpdateInteractortSpec.swift index 30b7184c..4c95d870 100644 --- a/KarhooSDKTests/TestCases/Service/Trips/TripUpdate/KarhooTripUpdateInteractortSpec.swift +++ b/KarhooSDKTests/TestCases/Service/Trips/TripUpdate/KarhooTripUpdateInteractortSpec.swift @@ -22,7 +22,7 @@ class KarhooTripUpdateInteractortSpec: XCTestCase { super.setUp() MockSDKConfig.authenticationMethod = .karhooUser mockTripUpdateRequest = MockRequestSender() - testObject = KarhooTripUpdateInteractor(tripId: tripId, + testObject = KarhooTripUpdateInteractor(identifier: tripId, requestSender: mockTripUpdateRequest) } @@ -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) in }) + testObject.execute(callback: { (result: Result) 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) } } diff --git a/Podfile.lock b/Podfile.lock index f8399f7f..e48da519 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -37,4 +37,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 347317e030faba7d076fadb56afec484d3618f62 -COCOAPODS: 1.9.0.beta.3 +COCOAPODS: 1.9.1