62 lines
1.7 KiB
Swift
62 lines
1.7 KiB
Swift
//
|
|
// LocationServiceTests.swift
|
|
// AutoCatCoreTests
|
|
//
|
|
// Created by Selim Mustafaev on 01.08.2024.
|
|
// Copyright © 2024 Selim Mustafaev. All rights reserved.
|
|
//
|
|
|
|
import Testing
|
|
import CoreLocation
|
|
import AutoCatCore
|
|
|
|
@MainActor
|
|
struct LocationServiceTests {
|
|
|
|
let latitude: CLLocationDegrees = 10
|
|
let longitude: CLLocationDegrees = 10
|
|
let address = "Test Address"
|
|
|
|
let geocoder = GeocoderMock()
|
|
let locationService: LocationService
|
|
|
|
init() {
|
|
self.locationService = LocationService(geocoder: geocoder)
|
|
}
|
|
|
|
@Test
|
|
func getValidAddress() async throws {
|
|
|
|
geocoder.addLocation(latitude: latitude,
|
|
longitude: longitude,
|
|
address: address)
|
|
|
|
let result = try await locationService.getAddressForLocation(latitude: latitude,
|
|
longitude: longitude)
|
|
|
|
#expect(result == address)
|
|
}
|
|
|
|
@Test
|
|
func getNilAddress() async throws {
|
|
|
|
geocoder.addLocation(latitude: latitude,
|
|
longitude: longitude,
|
|
address: nil)
|
|
|
|
await #expect(throws: LocationError.reverseGeocode) {
|
|
_ = try await locationService.getAddressForLocation(latitude: latitude,
|
|
longitude: longitude)
|
|
}
|
|
}
|
|
|
|
@Test
|
|
func addressNotFound() async throws {
|
|
|
|
await #expect(throws: LocationError.reverseGeocode) {
|
|
_ = try await locationService.getAddressForLocation(latitude: latitude,
|
|
longitude: longitude)
|
|
}
|
|
}
|
|
}
|