52 lines
1.4 KiB
Swift
52 lines
1.4 KiB
Swift
//
|
|
// GeocoderMock.swift
|
|
// AutoCatCoreTests
|
|
//
|
|
// Created by Selim Mustafaev on 31.07.2024.
|
|
// Copyright © 2024 Selim Mustafaev. All rights reserved.
|
|
//
|
|
|
|
import CoreLocation
|
|
import AutoCatCore
|
|
import Intents
|
|
import Contacts
|
|
|
|
final class GeocoderMock {
|
|
|
|
struct Location {
|
|
|
|
let latitude: CLLocationDegrees
|
|
let longitude: CLLocationDegrees
|
|
let address: String?
|
|
}
|
|
|
|
var locations: [Location] = []
|
|
|
|
func addLocation(latitude: CLLocationDegrees, longitude: CLLocationDegrees, address: String?) {
|
|
|
|
locations.append(Location(latitude: latitude,
|
|
longitude: longitude,
|
|
address: address))
|
|
}
|
|
}
|
|
|
|
extension GeocoderMock: GeocoderProtocol {
|
|
|
|
func reverseGeocodeLocation(_ location: CLLocation) async throws -> [CLPlacemark] {
|
|
|
|
let first = locations.first {
|
|
$0.latitude == location.coordinate.latitude && $0.longitude == location.coordinate.longitude
|
|
}
|
|
|
|
guard let first else {
|
|
return []
|
|
}
|
|
|
|
let placemark = CLPlacemark(location: CLLocation(latitude: first.latitude, longitude: first.longitude),
|
|
name: first.address,
|
|
postalAddress: nil)
|
|
|
|
return [placemark]
|
|
}
|
|
}
|