Added some tests
This commit is contained in:
parent
991af4a48f
commit
883df92484
@ -21,6 +21,7 @@ struct EventsTests {
|
||||
var viewModel: EventsViewModel
|
||||
|
||||
lazy var vehicleWithEvent: VehicleDto = .normal.addEvent(.valid)
|
||||
lazy var unrecognizedVehicleWithEvent: VehicleDto = .unrecognized.addEvent(.valid)
|
||||
|
||||
init() {
|
||||
|
||||
@ -38,26 +39,37 @@ struct EventsTests {
|
||||
.user.willReturn(User())
|
||||
}
|
||||
|
||||
@Test("Add event")
|
||||
mutating func addEvent() async throws {
|
||||
@Test("Add event", arguments: [true, false])
|
||||
mutating func addEvent(isUnrecognized: Bool) async throws {
|
||||
|
||||
let updatedVehicle: VehicleDto = isUnrecognized ? unrecognizedVehicleWithEvent : vehicleWithEvent
|
||||
|
||||
given(apiServiceMock)
|
||||
.add(event: .value(.valid), to: .value(VehicleDto.validNumber))
|
||||
.willReturn(vehicleWithEvent)
|
||||
|
||||
given(storageServiceMock)
|
||||
.updateVehicleIfExists(dto: .value(vehicleWithEvent))
|
||||
.updateVehicleIfExists(dto: .value(updatedVehicle))
|
||||
.willReturn()
|
||||
|
||||
viewModel = EventsViewModel(vehicle: .normal)
|
||||
given(storageServiceMock)
|
||||
.add(event: .value(.valid), to: .value(VehicleDto.validNumber))
|
||||
.willReturn(unrecognizedVehicleWithEvent)
|
||||
|
||||
viewModel = EventsViewModel(vehicle: isUnrecognized ? .unrecognized : .normal)
|
||||
await viewModel.addEvent(.valid)
|
||||
|
||||
verify(apiServiceMock)
|
||||
.add(event: .any, to: .any).called(.once)
|
||||
.add(event: .any, to: .any)
|
||||
.called(isUnrecognized ? .never : .once)
|
||||
|
||||
verify(storageServiceMock)
|
||||
.updateVehicleIfExists(dto: .any).called(.once)
|
||||
.updateVehicleIfExists(dto: .any)
|
||||
.called(isUnrecognized ? .never : .once)
|
||||
|
||||
verify(storageServiceMock)
|
||||
.add(event: .any, to: .any)
|
||||
.called(isUnrecognized ? .once : .never)
|
||||
|
||||
#expect(viewModel.vehicle.events.count == 1)
|
||||
#expect(viewModel.vehicle.events.first?.id == VehicleEventDto.validId)
|
||||
@ -65,5 +77,4 @@ struct EventsTests {
|
||||
#expect(viewModel.events.first?.id == VehicleEventDto.validId)
|
||||
#expect(viewModel.hud == nil)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user