-
Notifications
You must be signed in to change notification settings - Fork 70
Closed
Description
Currently find_one_and_delete type spec doesn't allow {:ok, nil}
, even though it is a valid result. Here is a test patch to prove such (also adds coverage for find_one_and_replace). It'd be great if the type spec could get updated for find_one_and_delete. Thanks.
diff --git a/test/mongo_test.exs b/test/mongo_test.exs
index d0241fb..6637321 100644
--- a/test/mongo_test.exs
+++ b/test/mongo_test.exs
@@ -298,6 +298,10 @@ defmodule Mongo.Test do
assert {:ok, %Mongo.FindAndModifyResult{value: value}} = Mongo.find_one_and_replace(c.pid, coll, %{"upsertedDocument" => true}, %{"upsertedDocument" => true}, upsert: true, return_document: :after)
assert %{"upsertedDocument" => true} = value, "Should upsert"
assert [%{"upsertedDocument" => true}] = Mongo.find(c.pid, coll, %{upsertedDocument: true}) |> Enum.to_list()
+
+ # missing
+ assert {:ok, %Mongo.FindAndModifyResult{matched_count: 0, updated_existing: false, value: nil}} == Mongo.find_one_and_replace(c.pid, coll, %{"never" => "matching"}, %{})
+ assert {:ok, %Mongo.FindAndModifyResult{matched_count: 0, updated_existing: false, value: nil}} == Mongo.find_one_and_replace(c.pid, "coll_that_doesnt_exist", %{"never" => "matching"}, %{})
end
test "find_one_and_delete", c do
@@ -320,6 +324,9 @@ defmodule Mongo.Test do
assert {:ok, %{"note" => "delete"}} = Mongo.find_one_and_delete(c.pid, coll, %{foo: 50}, sort: %{bar: -1})
assert [%{"note" => "keep"}] = Mongo.find(c.pid, coll, %{note: "keep"}) |> Enum.to_list()
+
+ # missing
+ assert {:ok, nil} = Mongo.find_one_and_delete(c.pid, coll, %{"never" => "matching"})
end
test "insert_one", c do
Metadata
Metadata
Assignees
Labels
No labels