Skip to content

Commit 06ea02f

Browse files
committed
test: extend mango_database.exs
path open_doc delete_doc ddoc_info delete_index bulk_delete
1 parent 25f1f55 commit 06ea02f

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

test/elixir/test/support/mango_database.ex

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ defmodule MangoDatabase do
1717
"search" in resp.body["features"]
1818
end
1919

20+
def path(db, parts) do
21+
parts_list =
22+
case parts do
23+
p when is_binary(p) -> [p]
24+
p when is_list(p) -> p
25+
end
26+
27+
Path.join(["/#{db}" | parts_list])
28+
end
29+
2030
def recreate(db, opts \\ []) do
2131
resp = Couch.get("/#{db}")
2232
if resp.status_code == 200 do
@@ -48,6 +58,23 @@ defmodule MangoDatabase do
4858
Couch.post("/#{db}/_bulk_docs", body: body)
4959
end
5060

61+
def open_doc(db, docid) do
62+
response = Couch.get("/#{db}/#{docid}")
63+
response.body
64+
end
65+
66+
def delete_doc(db, docid) do
67+
path = "/#{db}/#{URI.encode(docid)}"
68+
doc = Couch.get(path)
69+
original_rev = doc.body["_rev"]
70+
Couch.delete(path, query: %{"rev" => original_rev})
71+
end
72+
73+
def ddoc_info(db, ddocid) do
74+
response = Couch.get("/#{db}/#{ddocid}/_info")
75+
response.body
76+
end
77+
5178
# If a certain keyword like sort or field is passed in the options,
5279
# then it is added to the request body.
5380
defp put_if_set(map, key, opts, opts_key) do
@@ -157,6 +184,17 @@ defmodule MangoDatabase do
157184
end
158185
end
159186

187+
def delete_index(db, ddocid, name, idx_type \\ "json") do
188+
path = Path.join(["_index", ddocid, idx_type, name])
189+
Couch.delete("/#{db}/#{path}", params: %{"w" => "3"})
190+
end
191+
192+
def bulk_delete(db, docs) do
193+
body = %{"docids" => docs, "w" => 3}
194+
resp = Couch.post("/#{db}/_index/_bulk_delete", body: body)
195+
resp.body
196+
end
197+
160198
def find(db, selector, opts \\ []) do
161199
defaults = [
162200
use_index: nil,

0 commit comments

Comments
 (0)