From 1cde3347926c9af63a1704211223d959743e7e0d Mon Sep 17 00:00:00 2001 From: Rick Carlino Date: Mon, 17 Feb 2020 16:26:06 -0600 Subject: [PATCH] (44.4%) Finish tests FarmbotOS.SysCalls.ResourceUpdate --- farmbot_os/coveralls.json | 2 +- .../syscalls/resource_update_test.exs | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/farmbot_os/coveralls.json b/farmbot_os/coveralls.json index 40e1a31d..6226191a 100644 --- a/farmbot_os/coveralls.json +++ b/farmbot_os/coveralls.json @@ -1,6 +1,6 @@ { "coverage_options": { "treat_no_relevant_lines_as_covered": true, - "minimum_coverage": 39 + "minimum_coverage": 44 } } diff --git a/farmbot_os/test/farmbot_os/syscalls/resource_update_test.exs b/farmbot_os/test/farmbot_os/syscalls/resource_update_test.exs index dfa179e2..d51b7d1b 100644 --- a/farmbot_os/test/farmbot_os/syscalls/resource_update_test.exs +++ b/farmbot_os/test/farmbot_os/syscalls/resource_update_test.exs @@ -2,10 +2,38 @@ defmodule FarmbotOS.SysCalls.ResourceUpdateTest do use ExUnit.Case alias FarmbotOS.SysCalls.ResourceUpdate + alias FarmbotOS.SysCalls.PointLookup + alias FarmbotCore.Asset.{ + Point, + Repo, + } test "resource_update/3 - Device" do params = %{name: "X is {{ x }}"} assert :ok == ResourceUpdate.resource_update("Device", 0, params) assert "X is -1" == FarmbotCore.Asset.device().name end + + test "resource_update/3 - Point" do + Repo.delete_all(Point) + + %Point{id: 555, pointer_type: "Plant"} + |> Point.changeset() + |> Repo.insert!() + + params = %{name: "Updated to {{ x }}"} + assert :ok == ResourceUpdate.resource_update("Plant", 555, params) + next_plant = PointLookup.point("Plant", 555) + assert "Updated to -1" == next_plant.name + + bad_result1 = ResourceUpdate.resource_update("Plant", 0, params) + error = "Plant.0 is not currently synced, so it could not be updated" + assert {:error, error} == bad_result1 + end + + test "resource_update/3 - unknown" do + params = %{name: "never called"} + {:error, error } = ResourceUpdate.resource_update("Foo", 0, nil) + assert error == "Unknown resource: Foo.0\n" + end end