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_r240405776
 
 

 ##########
 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:
   I agree that probably there is no much benefits in that concrete example.
   But writing tests is still writing code. Usually you address to 
documentation or source code when you met something unknown in "normal" code. 
For example, 
[json_response/2](https://hexdocs.pm/phoenix/1.4.0/Phoenix.ConnTest.html#json_response/2).
   I believe it works for tests too. I wrote a lot of tests for my phoenix code 
using these helpers. You stop asking yourself what they mean after a couple of 
tests.
   
   Real example from basics_test.exs:
   ```elixir
   resp = Couch.get("/#{db_name}/_design/foo/_view/baz")
   assert resp.body["total_rows"] == 1
   assert hd(resp.body["rows"])["value"] == 16
   ```
   I have to compile `hd(resp.body["rows"])["value"]` in my mind and not to 
miss for which part of body `hd` is applied. IMO, too messy.
   
   Compare to:
   ```elixir
   resp = Couch.get("/#{db_name}/_design/foo/_view/baz")
   assert %{
            "total_rows" => 1,
            "rows" => [%{"value" => 16} | _]
          } = json_response(resp, 200)
   ```
   I see the pattern of the expected body right away.
   And I know from docs that it asserts the status code 200.
   IMO, the second peace of code is simplier and more readable.
   
   BTW, phoenix helpers support not only integer status codes but also 
[atoms](https://hexdocs.pm/plug/Plug.Conn.Status.html#code/1-known-status-codes).

----------------------------------------------------------------
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