Add test suite for handling errors from fabric

COUCHDB-3195
diff --git a/test/couchdb_mrview_tests.erl b/test/couchdb_mrview_tests.erl
index fa9ba70..9a4cc03 100644
--- a/test/couchdb_mrview_tests.erl
+++ b/test/couchdb_mrview_tests.erl
@@ -27,6 +27,11 @@
             "var data = JSON.parse(req.body); "
             "return ['test', data];"
         "}">>}
+    ]}},
+    {<<"views">>, {[
+        {<<"view1">>, {[
+            {<<"map">>, <<"function(doc){emit(doc._id, doc._rev)}">>}
+        ]}}
     ]}}
 ]}).
 
@@ -60,7 +65,7 @@
     delete_db(PortType, ?l2b(DbName)),
     ok.
 
-mrview_update_test_() ->
+mrview_show_test_() ->
     {
         "Check show functionality",
         {
@@ -73,6 +78,19 @@
         }
     }.
 
+mrview_query_test_() ->
+    {
+        "Check view query functionality",
+        {
+            setup,
+            fun start/0, fun teardown/1,
+            [
+                make_test_case(clustered, [fun should_return_400_for_wrong_order_of_keys/2]),
+                make_test_case(backdoor, [fun should_return_400_for_wrong_order_of_keys/2])
+            ]
+        }
+    }.
+
 make_test_case(Mod, Funs) ->
     {
         lists:flatten(io_lib:format("~s", [Mod])),
@@ -94,6 +112,22 @@
          ok
     end).
 
+should_return_400_for_wrong_order_of_keys(_PortType, {Host, DbName}) ->
+    Args = [{start_key, "\"bbb\""}, {end_key, "\"aaa\""}],
+    ?_test(begin
+         ReqUrl = Host ++ "/" ++ DbName
+              ++ "/_design/foo/_view/view1?" ++ mochiweb_util:urlencode(Args),
+         {ok, Status, _Headers, Body} = test_request:get(ReqUrl, [?AUTH]),
+         {Props} = jiffy:decode(Body),
+         ?assertEqual(
+            <<"query_parse_error">>, couch_util:get_value(<<"error">>, Props)),
+         ?assertEqual(
+            <<"No rows can match your key range, reverse your start_key and end_key or set descending=true">>,
+            couch_util:get_value(<<"reason">>, Props)),
+         ?assertEqual(400, Status),
+         ok
+    end).
+
 create_doc(backdoor, DbName, Id, Body) ->
     JsonDoc = couch_util:json_apply_field({<<"_id">>, Id}, Body),
     Doc = couch_doc:from_json_obj(JsonDoc),