diff --git a/Sources/XyoClient/Witness/Location/LocationService.swift b/Sources/XyoClient/Witness/Location/LocationService.swift index 75931b1..3308ed3 100644 --- a/Sources/XyoClient/Witness/Location/LocationService.swift +++ b/Sources/XyoClient/Witness/Location/LocationService.swift @@ -1,7 +1,7 @@ import CoreLocation import Foundation -public class LocationService: NSObject, CLLocationManagerDelegate, LocationServiceProtocol { +public class LocationService: NSObject, CLLocationManagerDelegate { private let locationManager = CLLocationManager() private var locationCompletion: ((Result) -> Void)? @@ -23,7 +23,7 @@ public class LocationService: NSObject, CLLocationManagerDelegate, LocationServi } // CLLocationManagerDelegate methods - @objc public func locationManager( + public func locationManager( _ manager: CLLocationManager, didUpdateLocations locations: [CLLocation] ) { if let location = locations.last { @@ -31,7 +31,7 @@ public class LocationService: NSObject, CLLocationManagerDelegate, LocationServi } } - @objc public func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) { + public func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) { locationCompletion?(.failure(error)) } } diff --git a/Sources/XyoClient/Witness/Location/LocationServiceProtocol.swift b/Sources/XyoClient/Witness/Location/LocationServiceProtocol.swift deleted file mode 100644 index 81ee22d..0000000 --- a/Sources/XyoClient/Witness/Location/LocationServiceProtocol.swift +++ /dev/null @@ -1,7 +0,0 @@ -import CoreLocation -import Foundation - -public protocol LocationServiceProtocol { - func requestAuthorization() - func requestLocation(completion: @escaping (Result) -> Void) -} diff --git a/Sources/XyoClient/Witness/Location/LocationWitness.swift b/Sources/XyoClient/Witness/Location/LocationWitness.swift index 3a531cb..6a66d99 100644 --- a/Sources/XyoClient/Witness/Location/LocationWitness.swift +++ b/Sources/XyoClient/Witness/Location/LocationWitness.swift @@ -2,26 +2,8 @@ import CoreLocation import Foundation open class LocationWitness: WitnessModuleAsync { - private var _locationService: LocationServiceProtocol? - private var locationService: LocationServiceProtocol { - if let service = _locationService { - return service - } else { - let initialized = LocationService() - self._locationService = initialized - return initialized - } - } - - override public init(account: AccountInstance? = nil) { - super.init(account: account) - } - - public convenience init(locationService: LocationServiceProtocol) { - self.init(account: nil) - self._locationService = locationService - } + private var locationService = LocationService() override open func observe(completion: @escaping ([Payload]?, Error?) -> Void) { locationService.requestAuthorization() diff --git a/Tests/XyoClientTests/Witness/LocationWitness.swift b/Tests/XyoClientTests/Witness/LocationWitness.swift deleted file mode 100644 index 1d52e58..0000000 --- a/Tests/XyoClientTests/Witness/LocationWitness.swift +++ /dev/null @@ -1,52 +0,0 @@ -import CoreLocation -import XCTest - -@testable import XyoClient - -private class MockLocationService: LocationServiceProtocol { - var didRequestAuthorization = false - var simulatedResult: Result? - - func requestAuthorization() { - didRequestAuthorization = true - } - - func requestLocation(completion: @escaping (Result) -> Void) { - if let result = simulatedResult { - completion(result) - } - } -} - -@available(iOS 13.0, *) -final class LocationWitnessTests: XCTestCase { - static var allTests = [ - ( - "observe:returnsMultipleLocationPayloads", - testLocationWitness_observe_returnsMultipleLocationPayloads - ) - ] - - @available(iOS 15, *) - func testLocationWitness_observe_returnsMultipleLocationPayloads() async throws { - let locationServiceMock = MockLocationService() - let lattitiude: Double = 1 - let longitude: Double = 2 - locationServiceMock.simulatedResult = .success( - CLLocation(latitude: lattitiude, longitude: longitude)) - let sut = LocationWitness(locationService: locationServiceMock) - let results = try await sut.observe() - XCTAssertEqual(results.count, 2) - let locationPayload = try XCTUnwrap( - results.compactMap { $0 as? LocationPayload }.first, "Missing location payload.") - XCTAssertEqual(locationPayload.schema, LocationPayload.schema) - XCTAssertEqual(locationPayload.location.coordinate.latitude, lattitiude) - XCTAssertEqual(locationPayload.location.coordinate.longitude, longitude) - let iosLocationPayload = try XCTUnwrap( - results.compactMap { $0 as? IosLocationPayload }.first, "Missing iOS location payload.") - XCTAssertEqual(iosLocationPayload.schema, IosLocationPayload.schema) - XCTAssertEqual(iosLocationPayload.location.coordinate.latitude, lattitiude) - XCTAssertEqual(iosLocationPayload.location.coordinate.longitude, longitude) - - } -}