van-mronov commented on a change in pull request #1796: Port delayed_commits 
test to Elixir
URL: https://github.com/apache/couchdb/pull/1796#discussion_r240314041
 
 

 ##########
 File path: test/elixir/test/delayed_commits_test.exs
 ##########
 @@ -0,0 +1,31 @@
+defmodule DelayedCommitsTest do
+  use CouchTestCase
+
+  @moduledoc """
+  Test CouchDB delayed commits
+  This is a port of the delayed_commits.js suite
+
+  Note that delayed_commits is deprecated in 2.0, so this is a minimal
+  test to show it still works. delayed_commits will be removed in 3.0.
+  """
+
+  @tag config: [
+         {"couchdb", "delayed_commits", "true"}
+       ]
+  @tag :with_db
+  test "delayed commit", context do
+    db_name = context[:db_name]
+    doc_id = "doc-1"
+    resp = Couch.put("/#{db_name}/#{doc_id}", body: %{a: 2, b: 4})
+    assert resp.status_code >= 201
+    assert resp.body["ok"]
+
+    resp = Couch.get("/#{db_name}/#{doc_id}")
+    assert resp.status_code == 200, "The new doc should be in the database"
 
 Review comment:
   Could it be useful to define a bunch of helper functons(`json_response/2`, 
`text_response/2`) like 
[Phoenix](https://github.com/phoenixframework/phoenix/blob/4da40a29f968b6e834ab55849af4a7337815ea50/lib/phoenix/test/conn_test.ex#L417)
 did?
   But pass `%HTTPotion.Response{}` instead of `Plug.Conn`.
   So we can do something like:
   
   ```elixir
   resp = Couch.get("/#{db_name}/#{doc_id}")
   assert %{"ok" => true} = json_response(resp, 200)
   ```
   or
   ```elixir
   resp = Couch.get("/#{db_name}/#{doc_id}")
   assert %{"error" => _error} = json_response(resp, 404)
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to