Skip to content

Commit 93f32d3

Browse files
committed
Add new tests when patch error was provided
1 parent 12f6550 commit 93f32d3

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

test/jsonpatch/operation/add_test.exs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,11 @@ defmodule Jsonpatch.Operation.AddTest do
7373

7474
assert %{"a" => [0, 1, 2, 3]} = Operation.apply_op(patch, target)
7575
end
76+
77+
test "Return error when patch error was provided to add operation" do
78+
patch = %Add{path: "/a", value: false}
79+
error = {:error, :invalid_index, "4"}
80+
81+
assert ^error = Operation.apply_op(patch, error)
82+
end
7683
end

test/jsonpatch/operation/remove_test.exs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,11 @@ defmodule RemoveTest do
8383
remove_patch = %Remove{path: "/hobbies/1/description"}
8484
assert {:error, :invalid_index, "1"} = Jsonpatch.apply_patch(remove_patch, target)
8585
end
86+
87+
test "Return error when patch error was provided to remove operation" do
88+
patch = %Remove{path: "/a"}
89+
error = {:error, :invalid_index, "4"}
90+
91+
assert ^error = Operation.apply_op(patch, error)
92+
end
8693
end

test/jsonpatch/operation/replace_test.exs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,11 @@ defmodule Jsonpatch.Operation.ReplaceTest do
8181

8282
assert {:error, :invalid_index, "c"} = patched_target
8383
end
84+
85+
test "Return error when patch error was provided to replace operation" do
86+
patch = %Replace{path: "/a", value: true}
87+
error = {:error, :invalid_index, "4"}
88+
89+
assert ^error = Operation.apply_op(patch, error)
90+
end
8491
end

0 commit comments

Comments
 (0)