80 lines
2.2 KiB
Swift
80 lines
2.2 KiB
Swift
//
|
|
// VehicleRecordServiceTests.swift
|
|
// AutoCatCoreTests
|
|
//
|
|
// Created by Selim Mustafaev on 16.03.2025.
|
|
// Copyright © 2025 Selim Mustafaev. All rights reserved.
|
|
//
|
|
|
|
import Testing
|
|
import Mockable
|
|
@testable import AutoCatCore
|
|
import Foundation
|
|
|
|
struct VehicleRecordServiceTests {
|
|
|
|
let locationServiceMock: MockLocationServiceProtocol
|
|
let audioRecordServiceMock = MockAudioRecordServiceProtocol()
|
|
let settingsServiceMock = MockSettingsServiceProtocol()
|
|
|
|
let vehicleRecordService: VehicleRecordService
|
|
init() async {
|
|
|
|
self.locationServiceMock = await .init()
|
|
|
|
self.vehicleRecordService = .init(
|
|
recordService: audioRecordServiceMock,
|
|
locationService: locationServiceMock,
|
|
settingsService: settingsServiceMock
|
|
)
|
|
}
|
|
|
|
@Test("Requesting permissions")
|
|
func requestPermissions() async throws {
|
|
|
|
given(audioRecordServiceMock)
|
|
.requestRecordPermissions()
|
|
.willReturn(true)
|
|
|
|
given(audioRecordServiceMock)
|
|
.requestRecognitionAuthorization()
|
|
.willReturn(.authorized)
|
|
|
|
await vehicleRecordService.requestPermissionsIfNeeded()
|
|
|
|
verify(audioRecordServiceMock)
|
|
.requestRecordPermissions()
|
|
.called(.once)
|
|
|
|
verify(audioRecordServiceMock)
|
|
.requestRecognitionAuthorization()
|
|
.called(.once)
|
|
}
|
|
|
|
@Test("Start recording")
|
|
func startRecording() async throws {
|
|
|
|
given(audioRecordServiceMock)
|
|
.startRecording(to: .any)
|
|
.willReturn()
|
|
|
|
given(locationServiceMock)
|
|
.getRecentLocation()
|
|
.willReturn(.valid)
|
|
|
|
try await vehicleRecordService.startRecording()
|
|
|
|
verify(audioRecordServiceMock)
|
|
.startRecording(to: .any)
|
|
.called(.once)
|
|
|
|
verify(locationServiceMock)
|
|
.getRecentLocation()
|
|
.called(.once)
|
|
|
|
await #expect(vehicleRecordService.url != nil)
|
|
await #expect(vehicleRecordService.location != nil)
|
|
await #expect(vehicleRecordService.locationTask != nil)
|
|
}
|
|
}
|