summaryrefslogtreecommitdiff
path: root/test/elixir/test/nouveau_test.exs
diff options
context:
space:
mode:
Diffstat (limited to 'test/elixir/test/nouveau_test.exs')
-rw-r--r--test/elixir/test/nouveau_test.exs46
1 files changed, 46 insertions, 0 deletions
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