Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"file_system": {:hex, :file_system, "1.1.0", "08d232062284546c6c34426997dd7ef6ec9f8bbd090eb91780283c9016840e8f", [:mix], [], "hexpm", "bfcf81244f416871f2a2e15c1b515287faa5db9c6bcf290222206d120b3d43f6"},
"floki": {:hex, :floki, "0.37.0", "b83e0280bbc6372f2a403b2848013650b16640cd2470aea6701f0632223d719e", [:mix], [], "hexpm", "516a0c15a69f78c47dc8e0b9b3724b29608aa6619379f91b1ffa47109b5d0dd3"},
"hackney": {:hex, :hackney, "1.20.1", "8d97aec62ddddd757d128bfd1df6c5861093419f8f7a4223823537bad5d064e2", [:rebar3], [{:certifi, "~> 2.12.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~> 6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~> 1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~> 1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.4.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~> 1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "fe9094e5f1a2a2c0a7d10918fee36bfec0ec2a979994cff8cfe8058cd9af38e3"},
"heroicons": {:git, "https://github.com/tailwindlabs/heroicons.git", "88ab3a0d790e6a47404cba02800a6b25d2afae50", [tag: "v2.1.1", sparse: "optimized"]},
"heroicons": {:git, "https://github.com/tailwindlabs/heroicons.git", "88ab3a0d790e6a47404cba02800a6b25d2afae50", [tag: "v2.1.1", sparse: "optimized", depth: 1]},
"hpax": {:hex, :hpax, "1.0.2", "762df951b0c399ff67cc57c3995ec3cf46d696e41f0bba17da0518d94acd4aac", [:mix], [], "hexpm", "2f09b4c1074e0abd846747329eaa26d535be0eb3d189fa69d812bfb8bfefd32f"},
"httpoison": {:hex, :httpoison, "2.2.1", "87b7ed6d95db0389f7df02779644171d7319d319178f6680438167d7b69b1f3d", [:mix], [{:hackney, "~> 1.17", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "51364e6d2f429d80e14fe4b5f8e39719cacd03eb3f9a9286e61e216feac2d2df"},
"idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"},
Expand Down
4 changes: 3 additions & 1 deletion test/support/fixtures/inventory_fixtures.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ defmodule Trmnl.InventoryFixtures do
@doc """
Generate a unique device mac_address.
"""
def unique_device_mac_address, do: "some mac_address#{System.unique_integer([:positive])}"
def unique_device_mac_address,
do:
Enum.take(0..6, 6) |> Enum.map(fn _x -> Base.encode16(:rand.bytes(1)) end) |> Enum.join(":")

@doc """
Generate a device.
Expand Down
35 changes: 28 additions & 7 deletions test/trmnl/inventory_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ defmodule Trmnl.InventoryTest do

import Trmnl.InventoryFixtures

@invalid_attrs %{name: nil, api_key: nil, mac_address: nil, friendly_id: nil, refresh_interval: nil}
@invalid_attrs %{
name: "",
api_key: "",
mac_address: "-:-:-",
friendly_id: ".",
refresh_interval: 0
}

test "list_devices/0 returns all devices" do
device = device_fixture()
Expand All @@ -21,13 +27,19 @@ defmodule Trmnl.InventoryTest do
end

test "create_device/1 with valid data creates a device" do
valid_attrs = %{name: "some name", api_key: "some api_key", mac_address: "some mac_address", friendly_id: "some friendly_id", refresh_interval: 42}
valid_attrs = %{
name: "some name",
api_key: "some api_key",
mac_address: "11:11:11:11:11:11",
friendly_id: "some friendly_id",
refresh_interval: 42
}

assert {:ok, %Device{} = device} = Inventory.create_device(valid_attrs)
assert device.name == "some name"
assert device.api_key == "some api_key"
assert device.mac_address == "some mac_address"
assert device.friendly_id == "some friendly_id"
assert device.mac_address == "11:11:11:11:11:11"
assert device.friendly_id == "SOME FRIENDLY_ID"
assert device.refresh_interval == 42
end

Expand All @@ -37,19 +49,28 @@ defmodule Trmnl.InventoryTest do

test "update_device/2 with valid data updates the device" do
device = device_fixture()
update_attrs = %{name: "some updated name", api_key: "some updated api_key", mac_address: "some updated mac_address", friendly_id: "some updated friendly_id", refresh_interval: 43}

update_attrs = %{
name: "some updated name",
api_key: "some updated api_key",
mac_address: "11:11:11:11:11:11",
friendly_id: "some updated friendly_id",
refresh_interval: 43
}

assert {:ok, %Device{} = device} = Inventory.update_device(device, update_attrs)
assert device.name == "some updated name"
assert device.api_key == "some updated api_key"
assert device.mac_address == "some updated mac_address"
assert device.friendly_id == "some updated friendly_id"
assert device.mac_address == "11:11:11:11:11:11"
assert device.friendly_id == "SOME UPDATED FRIENDLY_ID"
assert device.refresh_interval == 43
end

test "update_device/2 with invalid data returns error changeset" do
device = device_fixture()

assert {:error, %Ecto.Changeset{}} = Inventory.update_device(device, @invalid_attrs)

assert device == Inventory.get_device!(device.id)
end

Expand Down
2 changes: 1 addition & 1 deletion test/trmnl_web/controllers/page_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ defmodule TrmnlWeb.PageControllerTest do

test "GET /", %{conn: conn} do
conn = get(conn, ~p"/")
assert html_response(conn, 200) =~ "Peace of mind from prototype to production"
assert html_response(conn, 302) =~ "You are being"
end
end
24 changes: 21 additions & 3 deletions test/trmnl_web/live/device_live_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,27 @@ defmodule TrmnlWeb.DeviceLiveTest do
import Phoenix.LiveViewTest
import Trmnl.InventoryFixtures

@create_attrs %{name: "some name", api_key: "some api_key", mac_address: "some mac_address", friendly_id: "some friendly_id", refresh_interval: 42}
@update_attrs %{name: "some updated name", api_key: "some updated api_key", mac_address: "some updated mac_address", friendly_id: "some updated friendly_id", refresh_interval: 43}
@invalid_attrs %{name: nil, api_key: nil, mac_address: nil, friendly_id: nil, refresh_interval: nil}
@create_attrs %{
name: "some name",
api_key: "some_api_key",
mac_address: "11:11:11:11:11:11",
friendly_id: "some friendly_id",
refresh_interval: 42
}
@update_attrs %{
name: "some updated name",
api_key: "some updated api_key",
mac_address: "11:11:11:11:11:11",
friendly_id: "some updated friendly_id",
refresh_interval: 43
}
@invalid_attrs %{
name: nil,
api_key: nil,
mac_address: ".",
friendly_id: ".",
refresh_interval: nil
}

defp create_device(_) do
device = device_fixture()
Expand Down