You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2018/11/28 08:08:25 UTC

[GitHub] garrensmith closed pull request #1760: test: port coffee.js to Elixir test suite

garrensmith closed pull request #1760: test: port coffee.js to Elixir test suite
URL: https://github.com/apache/couchdb/pull/1760
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/test/elixir/README.md b/test/elixir/README.md
index 48f936fcbd..1b515c2da3 100644
--- a/test/elixir/README.md
+++ b/test/elixir/README.md
@@ -27,7 +27,7 @@ X means done, - means partially
   - [ ] Port batch_save.js
   - [ ] Port bulk_docs.js
   - [X] Port changes.js
-  - [ ] Port coffee.js
+  - [X] Port coffee.js
   - [ ] Port compact.js
   - [X] Port config.js
   - [ ] Port conflicts.js
diff --git a/test/elixir/test/coffee_test.exs b/test/elixir/test/coffee_test.exs
new file mode 100644
index 0000000000..19b1e6987f
--- /dev/null
+++ b/test/elixir/test/coffee_test.exs
@@ -0,0 +1,68 @@
+defmodule CoffeeTest do
+  use CouchTestCase
+
+  @moduletag :coffee
+
+  @moduledoc """
+  Test basic coffeescript functionality.
+  This is a port of the coffee.js test suite.
+  """
+
+  @tag :with_db
+  test "CoffeeScript basic functionality", context do
+    db_name = context[:db_name]
+
+    docs = [
+      %{:_id => "a", :foo => 100},
+      %{:foo => 1},
+      %{:foo => 1},
+      %{:foo => 2},
+      %{:foo => 2},
+      %{:bar => 1},
+      %{:bar => 1},
+      %{:bar => 2},
+      %{:bar => 2}
+    ]
+
+    resp = Couch.post("/#{db_name}/_bulk_docs", body: %{docs: docs})
+
+    design_doc = %{
+      :_id => "_design/coffee",
+      :language => "coffeescript",
+      :views => %{
+        :myview => %{
+          :map => "(doc) -> if doc.foo\n  emit(doc.foo, 1)",
+          :reduce => "(keys, values, rereduce) ->\n  sum = 0\n  for x in values\n    sum = sum + x\n  sum"
+        }
+      },
+      :shows => %{
+        :myshow => "(doc) ->\n  \"Foo #\{doc.foo}\""
+      },
+      :lists => %{
+        :mylist =>
+          "(head, req) ->\n  while row = getRow()\n    send(toJSON({\"resp\": \"Foo #\{row.value}\"}))\n  return"
+      },
+      :filters => %{
+        :filter => "(doc) ->\n  doc.foo"
+      }
+    }
+
+    design_resp = Couch.put("/#{db_name}/_design/coffee", body: design_doc)
+    assert design_resp.status_code === 201
+
+    assert resp.status_code === 201 and length(resp.body) === length(docs)
+
+    %{"rows" => values} = Couch.get("/#{db_name}/_design/coffee/_view/myview").body
+
+    assert 5 === hd(values)["value"]
+
+    assert Couch.get("/#{db_name}/_design/coffee/_show/myshow/a").body === "Foo 100"
+
+    %{"resp" => list_output} = Couch.get("/#{db_name}/_design/coffee/_list/mylist/myview").body
+    assert list_output === "Foo 5"
+
+    %{"results" => changes_results} = Couch.get("/#{db_name}/_changes", query: %{"filter" => "coffee/filter"}).body
+
+    assert length(changes_results) === 5
+  end
+end


 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services