diff options
-rw-r--r-- | test/elixir/test/config/nouveau.elixir | 4 | ||||
-rw-r--r-- | test/elixir/test/nouveau_test.exs | 46 |
2 files changed, 49 insertions, 1 deletions
diff --git a/test/elixir/test/config/nouveau.elixir b/test/elixir/test/config/nouveau.elixir index 90390a9d6..fdcc66de2 100644 --- a/test/elixir/test/config/nouveau.elixir +++ b/test/elixir/test/config/nouveau.elixir @@ -12,6 +12,8 @@ "sort by numeric field (desc)", "counts", "ranges", - "ranges (open)" + "ranges (open)", + "mango search by number", + "mango search by string" ] } diff --git a/test/elixir/test/nouveau_test.exs b/test/elixir/test/nouveau_test.exs index ee5d20542..357dcbba7 100644 --- a/test/elixir/test/nouveau_test.exs +++ b/test/elixir/test/nouveau_test.exs @@ -42,11 +42,31 @@ defmodule NouveauTest do assert Map.has_key?(resp.body, "ok") == true end + def create_mango_index(db_name) do + body = %{ + type: "nouveau", + index: %{ + fields: [ + %{name: "foo", type: "string"}, + %{name: "bar", type: "number"} + ] + } + } + + resp = Couch.post("/#{db_name}/_index", body: body) + assert resp.status_code in [200] + end + def get_ids(resp) do %{:body => %{"hits" => hits}} = resp Enum.map(hits, fn hit -> hit["doc"]["_id"] end) end + def get_mango_ids(resp) do + %{:body => %{"docs" => docs}} = resp + Enum.map(docs, fn doc -> doc["_id"] end) + end + def get_bookmark(resp) do %{:body => %{"bookmark" => bookmark}} = resp bookmark @@ -239,4 +259,30 @@ defmodule NouveauTest do assert ranges == %{"bar" => %{"cheap" => 3, "expensive" => 1}} end + @tag :with_db + test "mango search by number", context do + db_name = context[:db_name] + create_search_docs(db_name) + create_mango_index(db_name) + + url = "/#{db_name}/_find" + resp = Couch.post(url, body: %{selector: %{bar: %{"$gt": 5}}}) + assert resp.status_code == 200, "error #{resp.status_code} #{:jiffy.encode(resp.body)}" + ids = get_mango_ids(resp) + assert ids == ["doc2", "doc3", "doc4"] + end + + @tag :with_db + test "mango search by string", context do + db_name = context[:db_name] + create_search_docs(db_name) + create_mango_index(db_name) + + url = "/#{db_name}/_find" + resp = Couch.post(url, body: %{selector: %{foo: %{"$eq": "foo"}}}) + assert resp.status_code == 200, "error #{db_name} #{resp.status_code} #{:jiffy.encode(resp.body)}" + ids = get_mango_ids(resp) + assert ids == ["doc4"] + end + end |