82 lines
2.8 KiB
Swift
82 lines
2.8 KiB
Swift
//
|
|
// StorageServiceTests+Events.swift
|
|
// AutoCatCoreTests
|
|
//
|
|
// Created by Selim Mustafaev on 13.12.2024.
|
|
// Copyright © 2024 Selim Mustafaev. All rights reserved.
|
|
//
|
|
|
|
import Testing
|
|
import AutoCatCore
|
|
|
|
extension StorageServiceTests {
|
|
|
|
@Test("Add event")
|
|
func addEvent() async throws {
|
|
|
|
let event = VehicleEventDto(lat: testLat, lon: testLon)
|
|
|
|
let vehicle = try await storageService.add(event: event, to: existingVehicleNumber)
|
|
|
|
#expect(vehicle.events.count == 1)
|
|
#expect(vehicle.events.first?.latitude == testLat)
|
|
#expect(vehicle.events.first?.longitude == testLon)
|
|
#expect(vehicle.updatedDate != 0)
|
|
}
|
|
|
|
@Test("Add event to non-existent vehicle")
|
|
func addEventToNonExistentVehicle() async throws {
|
|
|
|
let event = VehicleEventDto(lat: testLat, lon: testLon)
|
|
|
|
await #expect(throws: StorageError.vehicleNotFound) {
|
|
_ = try await storageService.add(event: event, to: nonExistingVehicleNumber)
|
|
}
|
|
}
|
|
|
|
@Test("Remove event")
|
|
func removeEvent() async throws {
|
|
|
|
let event = VehicleEventDto(lat: testLat, lon: testLon)
|
|
var vehicle = try await storageService.add(event: event, to: existingVehicleNumber)
|
|
let id = try #require(vehicle.events.first { $0.latitude == testLat && $0.longitude == testLon }?.id)
|
|
|
|
vehicle = try await storageService.remove(event: id, from: existingVehicleNumber)
|
|
|
|
#expect(vehicle.events.isEmpty)
|
|
#expect(vehicle.updatedDate != 0)
|
|
}
|
|
|
|
@Test("Remove event from non-existent vehicle")
|
|
func removeEventFromNonExistentVehicle() async throws {
|
|
|
|
await #expect(throws: StorageError.vehicleNotFound) {
|
|
_ = try await storageService.remove(event: "", from: nonExistingVehicleNumber)
|
|
}
|
|
}
|
|
|
|
@Test("Remove non-existent event")
|
|
func removeNonExistentEvent() async throws {
|
|
|
|
await #expect(throws: StorageError.eventNotFound) {
|
|
_ = try await storageService.remove(event: "", from: existingVehicleNumber)
|
|
}
|
|
}
|
|
|
|
@Test("Edit event")
|
|
func editEvent() async throws {
|
|
|
|
let event = VehicleEventDto(lat: 0, lon: 0)
|
|
var vehicle = try await storageService.add(event: event, to: existingVehicleNumber)
|
|
let id = try #require(vehicle.events.first?.id)
|
|
|
|
let editedEvent = VehicleEventDto(lat: testLat, lon: testLon)
|
|
vehicle = try await storageService.edit(event: editedEvent, for: existingVehicleNumber)
|
|
|
|
let resultEcent = try #require(vehicle.events.first { $0.id == id }!)
|
|
#expect(resultEcent.latitude == testLat && resultEcent.longitude == testLon)
|
|
#expect(vehicle.events.count == 1)
|
|
#expect(vehicle.updatedDate != 0)
|
|
}
|
|
}
|