Fixing tests

This commit is contained in:
Selim Mustafaev 2024-12-20 22:12:25 +03:00
parent 2481045a9c
commit 991af4a48f
2 changed files with 13 additions and 0 deletions

View File

@ -8,6 +8,7 @@
import Testing import Testing
import CoreLocation import CoreLocation
import Mockable
@testable import AutoCatCore @testable import AutoCatCore
@MainActor @MainActor
@ -19,14 +20,19 @@ struct LocationServiceTests {
let geocoder = GeocoderMock() let geocoder = GeocoderMock()
let locationManager = SwiftLocationMock() let locationManager = SwiftLocationMock()
let settingsServiceMock = MockSettingsServiceProtocol()
let locationService: LocationService let locationService: LocationService
init() { init() {
ServiceContainer.shared.register(GeocoderProtocol.self, instance: geocoder) ServiceContainer.shared.register(GeocoderProtocol.self, instance: geocoder)
ServiceContainer.shared.register(SwiftLocationProtocol.self, instance: locationManager) ServiceContainer.shared.register(SwiftLocationProtocol.self, instance: locationManager)
ServiceContainer.shared.register(SettingsServiceProtocol.self, instance: settingsServiceMock)
self.locationService = LocationService() self.locationService = LocationService()
given(settingsServiceMock)
.user.willReturn(User())
} }
@Test @Test

View File

@ -9,6 +9,7 @@
import Testing import Testing
import RealmSwift import RealmSwift
import Foundation import Foundation
import Mockable
@testable import AutoCatCore @testable import AutoCatCore
@ -20,6 +21,7 @@ struct StorageServiceTests {
let testLat: Double = 42 let testLat: Double = 42
let testLon: Double = 24 let testLon: Double = 24
let settingsServiceMock = MockSettingsServiceProtocol()
let storageService: StorageService let storageService: StorageService
init() async throws { init() async throws {
@ -27,9 +29,14 @@ struct StorageServiceTests {
var config: Realm.Configuration = .defaultConfiguration var config: Realm.Configuration = .defaultConfiguration
config.inMemoryIdentifier = UUID().uuidString config.inMemoryIdentifier = UUID().uuidString
await ServiceContainer.shared.register(SettingsServiceProtocol.self, instance: settingsServiceMock)
self.storageService = try await StorageService(config: config) self.storageService = try await StorageService(config: config)
try addTestVehicle(config: config) try addTestVehicle(config: config)
given(settingsServiceMock)
.user.willReturn(User())
} }
func addTestVehicle(config: Realm.Configuration) throws { func addTestVehicle(config: Realm.Configuration) throws {