-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from XYOracleNetwork/feature/location-serializ…
…ation Location Serialization
- Loading branch information
Showing
4 changed files
with
79 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
Sources/XyoClient/Witness/Location/LocationServiceProtocol.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import CoreLocation | ||
import Foundation | ||
|
||
public protocol LocationServiceProtocol { | ||
func requestAuthorization() | ||
func requestLocation(completion: @escaping (Result<CLLocation, Error>) -> Void) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import CoreLocation | ||
import XCTest | ||
|
||
@testable import XyoClient | ||
|
||
private class MockLocationService: LocationServiceProtocol { | ||
var didRequestAuthorization = false | ||
var simulatedResult: Result<CLLocation, Error>? | ||
|
||
func requestAuthorization() { | ||
didRequestAuthorization = true | ||
} | ||
|
||
func requestLocation(completion: @escaping (Result<CLLocation, Error>) -> 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 latitude: Double = 1 | ||
let longitude: Double = 2 | ||
locationServiceMock.simulatedResult = .success( | ||
CLLocation(latitude: latitude, 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) | ||
|
||
} | ||
} |