summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuanjo Rodriguez <jjrodrig@gmail.com>2019-04-09 14:25:55 +0200
committergarren smith <garren.smith@gmail.com>2019-04-09 14:25:55 +0200
commit52189ee31da91a0c06c7840ba5398e64cb31d1c3 (patch)
tree02b8605e5a21cbcee6b491be9954956eda899733
parent5d199268d4330b80ce54d5dad2fe27db4bb81641 (diff)
downloadcouchdb-52189ee31da91a0c06c7840ba5398e64cb31d1c3.tar.gz
Port copy doc tests into elixir test suite (#2000)
-rw-r--r--test/elixir/README.md2
-rw-r--r--test/elixir/test/copy_doc_test.exs71
2 files changed, 72 insertions, 1 deletions
diff --git a/test/elixir/README.md b/test/elixir/README.md
index 8735e1e71..a59b4df90 100644
--- a/test/elixir/README.md
+++ b/test/elixir/README.md
@@ -41,7 +41,7 @@ X means done, - means partially
- [X] Port config.js
- [X] Port conflicts.js
- [ ] Port cookie_auth.js
- - [ ] Port copy_doc.js
+ - [X] Port copy_doc.js
- [X] Port delayed_commits.js
- [ ] Port design_docs.js
- [ ] Port design_options.js
diff --git a/test/elixir/test/copy_doc_test.exs b/test/elixir/test/copy_doc_test.exs
new file mode 100644
index 000000000..5db85497d
--- /dev/null
+++ b/test/elixir/test/copy_doc_test.exs
@@ -0,0 +1,71 @@
+defmodule CopyDocTest do
+ use CouchTestCase
+
+ @moduletag :copy_doc
+
+ @moduledoc """
+ Test CouchDB Copy Doc
+ This is a port of the copy_doc.js suite
+ """
+ @tag :with_db
+ test "Copy doc tests", context do
+ db_name = context[:db_name]
+ create_doc(db_name, %{_id: "doc_to_be_copied", v: 1})
+
+ resp =
+ Couch.request(
+ :copy,
+ "/#{db_name}/doc_to_be_copied",
+ headers: [Destination: "doc_that_was_copied"]
+ )
+
+ assert resp.body["ok"]
+ assert resp.status_code == 201
+
+ assert Couch.get("/#{db_name}/doc_that_was_copied").body["v"] == 1
+
+ create_doc(db_name, %{_id: "doc_to_be_copied2", v: 1})
+ {_, resp} = create_doc(db_name, %{_id: "doc_to_be_overwritten", v: 2})
+ rev = resp.body["rev"]
+
+ resp =
+ Couch.request(
+ :copy,
+ "/#{db_name}/doc_to_be_copied2",
+ headers: [Destination: "doc_to_be_overwritten"]
+ )
+
+ assert resp.status_code == 409
+
+ resp =
+ Couch.request(
+ :copy,
+ "/#{db_name}/doc_to_be_copied2"
+ )
+
+ assert resp.status_code == 400
+ assert resp.body["reason"] == "Destination header is mandatory for COPY."
+
+ resp =
+ Couch.request(
+ :copy,
+ "/#{db_name}/doc_to_be_copied2",
+ headers: [Destination: "http://localhost:5984/#{db_name}/doc_to_be_written"]
+ )
+
+ assert resp.status_code == 400
+ assert resp.body["reason"] == "Destination URL must be relative."
+
+ resp =
+ Couch.request(
+ :copy,
+ "/#{db_name}/doc_to_be_copied2",
+ headers: [Destination: "doc_to_be_overwritten?rev=#{rev}"]
+ )
+
+ assert resp.status_code == 201
+ resp = Couch.get("/#{db_name}/doc_to_be_overwritten")
+ assert resp.body["_rev"] != rev
+ assert resp.body["v"] == 1
+ end
+end