mirror of
https://github.com/teslamate-org/teslamate.git
synced 2026-01-24 21:06:08 +08:00
Test car name changes
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user