Test car name changes

This commit is contained in:
Adrian Kumpf
2019-10-16 22:09:35 +02:00
parent 7630b3780d
commit 68d3181c7a
2 changed files with 66 additions and 10 deletions
-10
View File
@@ -49,10 +49,6 @@ defmodule LogMock do
GenServer.call(name, {:get_positions_without_elevation, min_id, opts})
end
def create_or_update_car(name, attrs) do
GenServer.call(name, {:create_or_update_car, attrs})
end
def update_car(name, car, attrs) do
GenServer.call(name, {:update_car, car, attrs})
end
@@ -123,12 +119,6 @@ defmodule LogMock do
{:reply, {[], nil}, state}
end
def handle_call({:create_or_update_car, attrs} = _action, _from, %State{pid: _pid} = state) do
# send(pid, action)
%Car{} = car = Ecto.Changeset.apply_changes(attrs)
{:reply, {:ok, car}, state}
end
def handle_call({:update_car, car, attrs} = _action, _from, %State{pid: _pid} = state) do
result =
car
@@ -0,0 +1,66 @@
defmodule TeslaMate.Vehicles.Vehicle.IdentificationTest do
use TeslaMate.VehicleCase, async: false
use TeslaMateWeb.ConnCase
alias TeslaMate.Log.Car
alias TeslaMate.Log
test "identifies the vehicle" do
events = [
{:ok,
online_event(
display_name: "FooBar",
vehicle_config: %{car_type: "models", trim_badging: "p100d"}
)}
]
:ok = start_vehicles(events)
TestHelper.eventually(fn ->
assert %Car{name: "FooBar", model: "S", trim_badging: "P100D"} = Log.get_car_by(vid: 90211)
end)
end
test "changes the car name" do
events = [
{:ok, online_event(display_name: "FooBar")},
{:ok, online_event(display_name: "FooBar")},
{:ok, %TeslaApi.Vehicle{state: "offline"}},
{:ok, %TeslaApi.Vehicle{state: "offline"}},
{:ok, online_event(display_name: "Bar")},
{:ok, online_event(display_name: "Bar")}
]
:ok = start_vehicles(events)
TestHelper.eventually(fn -> assert %Car{name: "FooBar"} = Log.get_car_by(vid: 90211) end,
delay: 10,
attempts: 50
)
TestHelper.eventually(fn -> assert %Car{name: "Bar"} = Log.get_car_by(vid: 90211) end,
delay: 50,
attempts: 20
)
end
def start_vehicles(events \\ []) do
{:ok, _pid} = start_supervised({ApiMock, name: :api_vehicle, events: events, pid: self()})
{:ok, _pid} =
start_supervised(
{TeslaMate.Vehicles,
vehicle: VehicleMock,
vehicles: [
%TeslaApi.Vehicle{
display_name: "Foo",
id: 11243,
vehicle_id: 90211,
vin: "absadkalfs"
}
]}
)
:ok
end
end