Skip to content

Commit

Permalink
Static schema on payloads
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelBCarter committed Nov 22, 2024
1 parent 937b820 commit 09e3cd9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import CoreLocation

open class LocationPayload: Payload {

public static let schema: String = "network.xyo.location"

var location: CLLocation

public init(_ location: CLLocation) {
self.location = location
super.init("network.xyo.location")
super.init(LocationPayload.schema)
}

enum CodingKeys: String, CodingKey {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import CoreLocation

open class IosLocationPayload: Payload {

public static let schema: String = "network.xyo.location.ios"

var location: CLLocation

public init(_ location: CLLocation) {
self.location = location
super.init("network.xyo.location.ios")
super.init(IosLocationPayload.schema)
}

enum CodingKeys: String, CodingKey {
Expand Down
12 changes: 9 additions & 3 deletions Tests/XyoClientTests/Witness/LocationWitness.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,22 @@ final class LocationWitnessTests: XCTestCase {
@available(iOS 15, *)
func testLocationWitness_observe_returnsMultipleLocationPayloads() async throws {
let locationServiceMock = MockLocationService()
locationServiceMock.simulatedResult = .success(CLLocation(latitude: 1, longitude: 2))
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, "network.xyo.location")
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, "network.xyo.location.ios")
XCTAssertEqual(iosLocationPayload.schema, IosLocationPayload.schema)
XCTAssertEqual(iosLocationPayload.location.coordinate.latitude, lattitiude)
XCTAssertEqual(iosLocationPayload.location.coordinate.longitude, longitude)

}
}

0 comments on commit 09e3cd9

Please sign in to comment.