blob: 6b904fbefa5270df904a510ad04a457457d7c981 [file]
'use strict';
var should = require('chai').should();
var PouchDB = require('../../packages/pouchdb-for-coverage');
var getErrorTypeByProp = PouchDB.utils.getErrorTypeByProp;
var generateErrorFromResponse = PouchDB.utils.generateErrorFromResponse;
//
// TODO: a lot of these errors are kind of misleading, or the error
// message gets stripped out during processing. We should fix that.
// However, these tests represent the state of the code circa 5.3.2, just
// so we can have a record of the expected behavior.
//
describe('test.errors.js', function () {
// These were generated by an actual test run. Many of the errors
// come from CouchDB 1.6.1.
it('test getErrorTypeByProp #1', function () {
var error = getErrorTypeByProp("name", "bad_request",
"Document id must be a string");
error.status.should.equal(400);
error.name.should.equal('bad_request');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #2', function () {
var error = getErrorTypeByProp("name", "bad_request",
"Invalid rev format");
error.status.should.equal(400);
error.name.should.equal('bad_request');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #3', function () {
var error = getErrorTypeByProp("name", "bad_request",
"Only reserved document ids may start with underscore.");
error.status.should.equal(400);
error.name.should.equal('bad_request');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #4', function () {
var error = getErrorTypeByProp("name", "bad_request",
"Referer header required.");
error.status.should.equal(400);
error.name.should.equal('bad_request');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #5', function () {
var error = getErrorTypeByProp("name", "bad_request",
"`view` filter parameter is not provided.");
error.status.should.equal(400);
error.name.should.equal('bad_request');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #6', function () {
var error = getErrorTypeByProp("name", "badarg", "33");
error.status.should.equal(500);
error.name.should.equal('badarg');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #7', function () {
var error = getErrorTypeByProp("name", "conflict",
"Document update conflict.");
error.status.should.equal(409);
error.name.should.equal('conflict');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #8', function () {
var error = getErrorTypeByProp("name", "doc_validation",
"Bad special document member: _zing");
error.status.should.equal(500);
error.name.should.equal('doc_validation');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #9', function () {
var error = getErrorTypeByProp("name", "file_exists",
"The database could not be created, the file already exists.");
error.status.should.equal(412);
error.name.should.equal('file_exists');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #10', function () {
var error = getErrorTypeByProp("name", "forbidden",
"Document foo is string");
error.status.should.equal(403);
error.name.should.equal('forbidden');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #11', function () {
var error = getErrorTypeByProp("name", "forbidden",
"Document must have a foo.");
error.status.should.equal(403);
error.name.should.equal('forbidden');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #12', function () {
var error = getErrorTypeByProp("name", "forbidden",
'{"foo": "is object"}');
error.status.should.equal(403);
error.name.should.equal('forbidden');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #13', function () {
var error = getErrorTypeByProp("name", "missing_stub",
"id:bin_doc, name:bar.txt");
error.status.should.equal(412);
error.name.should.equal('missing_stub');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #14', function () {
var error = getErrorTypeByProp("name", "missing_stub",
"id:stubby, name:foo.txt");
error.status.should.equal(412);
error.name.should.equal('missing_stub');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #15', function () {
var error = getErrorTypeByProp("name", "not_found",
"deleted");
error.status.should.equal(404);
error.name.should.equal('not_found');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #16', function () {
var error = getErrorTypeByProp("name", "not_found",
"missing json key: filters");
error.status.should.equal(404);
error.name.should.equal('not_found');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #17', function () {
var error = getErrorTypeByProp("name", "not_found",
"missing json key: odd");
error.status.should.equal(404);
error.name.should.equal('not_found');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #18', function () {
var error = getErrorTypeByProp("name", "not_found",
"missing json key: views");
error.status.should.equal(404);
error.name.should.equal('not_found');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #19', function () {
var error = getErrorTypeByProp("name", "not_found",
"missing");
error.status.should.equal(404);
error.name.should.equal('not_found');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #20', function () {
var error = getErrorTypeByProp("name", "not_found",
"no_db_file");
error.status.should.equal(404);
error.name.should.equal('not_found');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #21', function () {
var error = getErrorTypeByProp("name", "query_parse_error",
"`keys` is incompatible with `key`, `start_key` and `end_key`");
error.status.should.equal(400);
error.name.should.equal('query_parse_error');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #22', function () {
var error = getErrorTypeByProp("name", "query_parse_error",
"`keys` must be an array of strings.");
error.status.should.equal(400);
error.name.should.equal('query_parse_error');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #23', function () {
var error = getErrorTypeByProp("name", "unauthorized",
"Document foo is string");
error.status.should.equal(401);
error.name.should.equal('unauthorized');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #24', function () {
var error = getErrorTypeByProp("name", "unauthorized",
"Document must have a foo.");
error.status.should.equal(401);
error.name.should.equal('unauthorized');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #25', function () {
var error = getErrorTypeByProp("name", "unauthorized",
"go away, no picture");
error.status.should.equal(401);
error.name.should.equal('unauthorized');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #26', function () {
var error = getErrorTypeByProp("name", "unauthorized",
'{"foo": "is object"}');
error.status.should.equal(401);
error.name.should.equal('unauthorized');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #27', function () {
var error = getErrorTypeByProp("name", "unknown_error",
"function_clause");
error.status.should.equal(500);
error.name.should.equal('unknown_error');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #28', function () {
var error = getErrorTypeByProp("name");
should.not.exist(error);
});
it('test getErrorTypeByProp #29', function () {
var error = getErrorTypeByProp("status", 400);
error.status.should.equal(400);
error.name.should.equal('bad_request');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #30', function () {
var error = getErrorTypeByProp("status");
should.not.exist(error);
});
// these tests came from the map/reduce test suite
it('test getErrorTypeByProp #via map/reduce tests #1', function () {
var error = getErrorTypeByProp("name", "invalid_value",
"builtin _sum function requires map values to be numbers " +
"or lists of numbers");
should.not.exist(error);
});
it('test getErrorTypeByProp #via map/reduce tests #2', function () {
var error = getErrorTypeByProp("name", "not_found",
"deleted");
error.status.should.equal(404);
error.name.should.equal('not_found');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #via map/reduce tests #3', function () {
var error = getErrorTypeByProp("name", "not_found", "missing");
error.status.should.equal(404);
error.name.should.equal('not_found');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #via map/reduce tests #4', function () {
var error = getErrorTypeByProp("name", "not_found", "missing_named_view");
error.status.should.equal(404);
error.name.should.equal('not_found');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #via map/reduce tests #5', function () {
var error = getErrorTypeByProp("name", "not_found", "no_db_file");
error.status.should.equal(404);
error.name.should.equal('not_found');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #via map/reduce tests #6', function () {
var error = getErrorTypeByProp("name", "query_parse_error",
"Invalid value for integer: \"1a\"");
error.status.should.equal(400);
error.name.should.equal('query_parse_error');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #via map/reduce tests #7', function () {
var error = getErrorTypeByProp("name", "query_parse_error",
"Invalid value for integer: \"exact\"");
error.status.should.equal(400);
error.name.should.equal('query_parse_error');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #via map/reduce tests #8', function () {
var error = getErrorTypeByProp("name", "query_parse_error",
"Invalid value for positive integer: \"-1\"");
error.status.should.equal(400);
error.name.should.equal('query_parse_error');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #via map/reduce tests #9', function () {
var error = getErrorTypeByProp("name", "query_parse_error",
"Multi-key fetchs for reduce views must use `group=true`");
error.status.should.equal(400);
error.name.should.equal('query_parse_error');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #via map/reduce tests #10', function () {
var error = getErrorTypeByProp("name", "query_parse_error",
"No rows can match your key range, reverse your start_key and end_key " +
"or set descending=true");
error.status.should.equal(400);
error.name.should.equal('query_parse_error');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #via map/reduce tests #11', function () {
var error = getErrorTypeByProp("name", "query_parse_error",
"`include_docs` is invalid for reduce");
error.status.should.equal(400);
error.name.should.equal('query_parse_error');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #via map/reduce tests #12', function () {
var error = getErrorTypeByProp("name", "unknown_error", "function_clause");
error.status.should.equal(500);
error.name.should.equal('unknown_error');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #via map/reduce tests #13', function () {
var error = getErrorTypeByProp("status", undefined,
"builtin _sum function requires map values to be numbers or lists" +
" of numbers");
should.not.exist(error);
});
it('test getErrorTypeByProp #via map/reduce tests #15', function () {
var error = getErrorTypeByProp("name", "invalid_value",
"builtin _sum function requires map values to be numbers or " +
"lists of numbers");
should.not.exist(error);
});
it('test getErrorTypeByProp #via map/reduce tests #16', function () {
var error = getErrorTypeByProp("name", "not_found", "deleted");
error.status.should.equal(404);
error.name.should.equal('not_found');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #via map/reduce tests #17', function () {
var error = getErrorTypeByProp("name", "not_found", "missing");
error.status.should.equal(404);
error.name.should.equal('not_found');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #via map/reduce tests #18', function () {
var error = getErrorTypeByProp("name", "not_found", "missing_named_view");
error.status.should.equal(404);
error.name.should.equal('not_found');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #via map/reduce tests #19', function () {
var error = getErrorTypeByProp("name", "not_found", "no_db_file");
error.status.should.equal(404);
error.name.should.equal('not_found');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #via map/reduce tests #20', function () {
var error = getErrorTypeByProp("name", "query_parse_error",
"Invalid value for integer: \"1a\"");
error.status.should.equal(400);
error.name.should.equal('query_parse_error');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #via map/reduce tests #21', function () {
var error = getErrorTypeByProp("name", "query_parse_error",
"Invalid value for integer: \"exact\"");
error.status.should.equal(400);
error.name.should.equal('query_parse_error');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #via map/reduce tests #22', function () {
var error = getErrorTypeByProp("name", "query_parse_error",
"Invalid value for positive integer: \"-1\"");
error.status.should.equal(400);
error.name.should.equal('query_parse_error');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #via map/reduce tests #23', function () {
var error = getErrorTypeByProp("name", "query_parse_error",
"Multi-key fetchs for reduce views must use `group=true`");
error.status.should.equal(400);
error.name.should.equal('query_parse_error');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #via map/reduce tests #24', function () {
var error = getErrorTypeByProp("name", "query_parse_error",
"No rows can match your key range, reverse your start_key and end_key " +
"or set descending=true");
error.status.should.equal(400);
error.name.should.equal('query_parse_error');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #via map/reduce tests #25', function () {
var error = getErrorTypeByProp("name", "query_parse_error",
"`include_docs` is invalid for reduce");
error.status.should.equal(400);
error.name.should.equal('query_parse_error');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #via map/reduce tests #26', function () {
var error = getErrorTypeByProp("name", "unknown_error", "function_clause");
error.status.should.equal(500);
error.name.should.equal('unknown_error');
error.error.should.equal(true);
});
it('test getErrorTypeByProp #via map/reduce tests #27', function () {
var error = getErrorTypeByProp("status", undefined,
"builtin _sum function requires map values to be numbers or " +
"lists of numbers");
should.not.exist(error);
});
// these were generated by the main test suite
it('test generateErrorFromResponse() #1', function () {
var response = {"error": "not_found", "reason": "missing"};
var err = generateErrorFromResponse(response);
err.status.should.equal(404);
err.name.should.equal("not_found");
err.message.should.equal("missing");
err.error.should.equal(true);
});
it('test generateErrorFromResponse() #2', function () {
var response = {"error": "not_found", "reason": "no_db_file"};
var err = generateErrorFromResponse(response);
err.status.should.equal(404);
err.name.should.equal("not_found");
err.message.should.equal("missing");
err.error.should.equal(true);
});
it('test generateErrorFromResponse() #3', function () {
var response = {
"error": "query_parse_error",
"reason": "`keys` is incompatible with `key`, `start_key` and `end_key`"
};
var err = generateErrorFromResponse(response);
err.status.should.equal(400);
err.name.should.equal("query_parse_error");
err.message.should.equal("Some query parameter is invalid");
err.error.should.equal(true);
});
it('test generateErrorFromResponse() #4', function () {
var response = {
"error": "query_parse_error",
"reason": "`keys` must be an array of strings."
};
var err = generateErrorFromResponse(response);
err.status.should.equal(400);
err.name.should.equal("query_parse_error");
err.message.should.equal("Some query parameter is invalid");
err.error.should.equal(true);
});
it('test generateErrorFromResponse() #5', function () {
var response = {"missing": "2-fake"};
var err = generateErrorFromResponse(response);
err.status.should.equal(404);
err.name.should.equal("not_found");
err.message.should.equal("missing");
err.error.should.equal(true);
err.missing.should.equal("2-fake");
});
it('test generateErrorFromResponse() #6', function () {
var response = {
"error": "missing_stub",
"reason": "id:bin_doc, name:bar.txt"
};
var err = generateErrorFromResponse(response);
err.status.should.equal(412);
err.name.should.equal("missing_stub");
err.error.should.equal(true);
});
it('test generateErrorFromResponse() #7', function () {
var response = {
"error": "missing_stub",
"reason": "id:stubby, name:foo.txt"
};
var err = generateErrorFromResponse(response);
err.status.should.equal(412);
err.name.should.equal("missing_stub");
err.error.should.equal(true);
});
it('test generateErrorFromResponse() #8', function () {
var response = {
"error": "bad_request",
"reason": "Only reserved document ids may start with underscore."
};
var err = generateErrorFromResponse(response);
err.status.should.equal(400);
err.name.should.equal("bad_request");
err.message.should.equal("Only reserved document ids may start with " +
"underscore.");
err.error.should.equal(true);
});
it('test generateErrorFromResponse() #9', function () {
var response = {"error": "conflict", "reason": "Document update conflict."};
var err = generateErrorFromResponse(response);
err.status.should.equal(409);
err.name.should.equal("conflict");
err.message.should.equal("Document update conflict");
err.error.should.equal(true);
});
it('test generateErrorFromResponse() #10', function () {
var response = {"error": "bad_request", "reason": "Invalid rev format"};
var err = generateErrorFromResponse(response);
err.status.should.equal(400);
err.name.should.equal("bad_request");
err.message.should.equal("Invalid rev format");
err.error.should.equal(true);
});
it('test generateErrorFromResponse() #11', function () {
var response = {"error": "badarg", "reason": "33"};
var err = generateErrorFromResponse(response);
err.status.should.equal(500);
err.name.should.equal("badarg");
err.message.should.equal("Some query argument is invalid");
err.error.should.equal(true);
});
it('test generateErrorFromResponse() #12', function () {
var response = {
"error": "bad_request",
"reason": "Referer header required."
};
var err = generateErrorFromResponse(response);
err.status.should.equal(400);
err.name.should.equal("bad_request");
err.message.should.equal("Something wrong with the request");
err.error.should.equal(true);
});
it('test generateErrorFromResponse() #13', function () {
var response = {"status": 400};
var err = generateErrorFromResponse(response);
err.status.should.equal(400);
err.name.should.equal("bad_request");
err.message.should.equal("Missing JSON list of 'docs'");
err.error.should.equal(true);
});
it('test generateErrorFromResponse() #14', function () {
var response = {
"id": "77c03c2755ae08600a0ff58aebc513fe",
"error": "conflict",
"reason": "Document update conflict."
};
var err = generateErrorFromResponse(response);
err.status.should.equal(409);
err.name.should.equal("conflict");
err.message.should.equal("Document update conflict");
err.error.should.equal(true);
err.id.should.equal("77c03c2755ae08600a0ff58aebc513fe");
});
it('test generateErrorFromResponse() #15', function () {
var response = {"error": "not_found", "reason": "deleted"};
var err = generateErrorFromResponse(response);
err.status.should.equal(404);
err.name.should.equal("not_found");
err.message.should.equal("missing");
err.error.should.equal(true);
});
it('test generateErrorFromResponse() #16', function () {
var response = {
"error": "doc_validation",
"reason": "Bad special document member: _zing"
};
var err = generateErrorFromResponse(response);
err.status.should.equal(500);
err.name.should.equal("doc_validation");
err.message.should.equal("Bad special document member: _zing");
err.error.should.equal(true);
});
it('test generateErrorFromResponse() #23', function () {
var response = {
"error": "bad_request",
"reason": "Document id must be a string"
};
var err = generateErrorFromResponse(response);
err.status.should.equal(400);
err.name.should.equal("bad_request");
err.message.should.equal("Something wrong with the request");
err.error.should.equal(true);
});
it('test generateErrorFromResponse() #26', function () {
var response = {
"id": "doc1",
"rev": "1-x",
"error": "unauthorized",
"reason": "Document must have a foo."
};
var err = generateErrorFromResponse(response);
err.status.should.equal(401);
err.name.should.equal("unauthorized");
err.message.should.equal("Name or password is incorrect.");
err.error.should.equal(true);
err.id.should.equal("doc1");
});
it('test generateErrorFromResponse() #27', function () {
var response = {
"error": "file_exists",
"reason": "The database could not be created, the file already exists."
};
var err = generateErrorFromResponse(response);
err.status.should.equal(412);
err.name.should.equal("file_exists");
err.message.should.equal("The database could not be created, the file " +
"already exists.");
err.error.should.equal(true);
});
it('test generateErrorFromResponse() #29', function () {
var response = {"error": "not_found", "reason": "missing json key: odd"};
var err = generateErrorFromResponse(response);
err.status.should.equal(404);
err.name.should.equal("not_found");
err.message.should.equal("missing");
err.error.should.equal(true);
});
it('test generateErrorFromResponse() #30', function () {
var response = {
"error": "not_found",
"reason": "missing json key: filters"
};
var err = generateErrorFromResponse(response);
err.status.should.equal(404);
err.name.should.equal("not_found");
err.message.should.equal("missing");
err.error.should.equal(true);
});
it('test generateErrorFromResponse() #31', function () {
var response = {"error": "not_found", "reason": "missing json key: views"};
var err = generateErrorFromResponse(response);
err.status.should.equal(404);
err.name.should.equal("not_found");
err.message.should.equal("missing");
err.error.should.equal(true);
});
it('test generateErrorFromResponse() #32', function () {
var response = {
"error": "bad_request",
"reason": "`view` filter parameter is not provided."
};
var err = generateErrorFromResponse(response);
err.status.should.equal(400);
err.name.should.equal("bad_request");
err.message.should.equal("Something wrong with the request");
err.error.should.equal(true);
});
it('test generateErrorFromResponse() #33', function () {
var response = {
"status": 404,
"name": "not_found",
"message": "missing",
"error": true,
"reason": "missing"
};
var err = generateErrorFromResponse(response);
err.status.should.equal(404);
err.name.should.equal("not_found");
err.message.should.equal("missing");
err.error.should.equal(true);
});
it('test generateErrorFromResponse() #77', function () {
var response = {"error": "unknown_error", "reason": "function_clause"};
var err = generateErrorFromResponse(response);
err.status.should.equal(500);
err.name.should.equal("unknown_error");
err.message.should.equal("Database encountered an unknown error");
err.error.should.equal(true);
});
it('test generateErrorFromResponse() #78', function () {
var response = "<!doctype html><html>YO THIS IS AN ERROR</html>";
var err = generateErrorFromResponse(response);
err.status.should.equal(500);
err.name.should.equal("unknown_error");
err.message.should.equal("Database encountered an unknown error");
err.error.should.equal(true);
});
it('test generateErrorFromResponse() #81', function () {
var response = {
"id": "0596A614-2001-05B6-93C3-6B3B6504CD05",
"rev": "1-8156ee4ba7898510bfaf868668a81e4f",
"error": "forbidden",
"reason": "Document must have a foo."
};
var err = generateErrorFromResponse(response);
err.status.should.equal(403);
err.name.should.equal("forbidden");
err.message.should.equal("Forbidden by design doc validate_doc_update " +
"function");
err.error.should.equal(true);
err.id.should.equal("0596A614-2001-05B6-93C3-6B3B6504CD05");
});
it('test generateErrorFromResponse() #87', function () {
var response = {
"id": "45E4D1A4-B01D-6898-B8FF-035B2C76AB6B",
"rev": "1-a531a7aa3fb56bdae69f7ce4113486c4",
"error": "forbidden",
"reason": {"foo": "is object"}
};
var err = generateErrorFromResponse(response);
err.status.should.equal(403);
err.name.should.equal("forbidden");
err.message.should.equal("Forbidden by design doc validate_doc_update " +
"function");
err.error.should.equal(true);
err.id.should.equal("45E4D1A4-B01D-6898-B8FF-035B2C76AB6B");
});
it('test generateErrorFromResponse() #88', function () {
var response = {
"id": "5F99EF37-DABA-DACB-A58E-4C6D76511985",
"rev": "1-17702a69add79ff7d9006d43b9262ec2",
"error": "forbidden",
"reason": "Document foo is string"
};
var err = generateErrorFromResponse(response);
err.status.should.equal(403);
err.name.should.equal("forbidden");
err.message.should.equal("Forbidden by design doc validate_doc_update " +
"function");
err.error.should.equal(true);
err.id.should.equal("5F99EF37-DABA-DACB-A58E-4C6D76511985");
});
it('test generateErrorFromResponse() #89', function () {
var response = {
"id": "1A3F4028-2E5D-B12F-80BB-ED5234BF6E02",
"rev": "1-d89df54b4ec86054c05025137143b5e8",
"error": "unauthorized",
"reason": {"foo": "is object"}
};
var err = generateErrorFromResponse(response);
err.status.should.equal(401);
err.name.should.equal("unauthorized");
err.message.should.equal("Name or password is incorrect.");
err.error.should.equal(true);
err.id.should.equal("1A3F4028-2E5D-B12F-80BB-ED5234BF6E02");
});
it('test generateErrorFromResponse() #90', function () {
var response = {
"id": "36824FB1-C1E6-76EE-BF7E-4D3614A36736",
"rev": "1-3b1c04d44d17dbfef815433693dc26d4",
"error": "unauthorized",
"reason": "Document foo is string"
};
var err = generateErrorFromResponse(response);
err.status.should.equal(401);
err.name.should.equal("unauthorized");
err.message.should.equal("Name or password is incorrect.");
err.error.should.equal(true);
err.id.should.equal("36824FB1-C1E6-76EE-BF7E-4D3614A36736");
});
it('test generateErrorFromResponse() #91', function () {
var response = {
"id": "6DA30042-600E-2581-8BD8-8A92F79CE53E",
"rev": "1-6a36583f7500873176466ffc1e2c8b41",
"error": "unauthorized",
"reason": "go away, no picture"
};
var err = generateErrorFromResponse(response);
err.status.should.equal(401);
err.name.should.equal("unauthorized");
err.message.should.equal("Name or password is incorrect.");
err.error.should.equal(true);
err.id.should.equal("6DA30042-600E-2581-8BD8-8A92F79CE53E");
});
it('test generateErrorFromResponse() #93', function () {
var response = {
"id": "foo1",
"rev": "1-ba250664825530e39299e870460f77d6",
"error": "unauthorized",
"reason": "go away, no picture"
};
var err = generateErrorFromResponse(response);
err.status.should.equal(401);
err.name.should.equal("unauthorized");
err.message.should.equal("Name or password is incorrect.");
err.error.should.equal(true);
err.id.should.equal("foo1");
});
it('test generateErrorFromResponse() #96', function () {
var response = {
"id": "77c03c2755ae08600a0ff58aebcaef19",
"rev": "1-967a00dff5e02add41819138abb3284d",
"error": "forbidden",
"reason": "Document must have a foo."
};
var err = generateErrorFromResponse(response);
err.status.should.equal(403);
err.name.should.equal("forbidden");
err.message.should.equal("Forbidden by design doc validate_doc_update " +
"function");
err.error.should.equal(true);
err.id.should.equal("77c03c2755ae08600a0ff58aebcaef19");
});
it('test generateErrorFromResponse() #102', function () {
var response = {
"id": "77c03c2755ae08600a0ff58aebcb650f",
"rev": "1-e13a955ef7781be762def6793e1e789d",
"error": "forbidden",
"reason": "Document foo is string"
};
var err = generateErrorFromResponse(response);
err.status.should.equal(403);
err.name.should.equal("forbidden");
err.message.should.equal("Forbidden by design doc validate_doc_update " +
"function");
err.error.should.equal(true);
err.id.should.equal("77c03c2755ae08600a0ff58aebcb650f");
});
it('test generateErrorFromResponse() #103', function () {
var response = {
"id": "77c03c2755ae08600a0ff58aebcb7be6",
"rev": "1-eb291f6f3b68b37993b33ed7e5c68ebc",
"error": "forbidden",
"reason": {"foo": "is object"}
};
var err = generateErrorFromResponse(response);
err.status.should.equal(403);
err.name.should.equal("forbidden");
err.message.should.equal("Forbidden by design doc validate_doc_update " +
"function");
err.error.should.equal(true);
err.id.should.equal("77c03c2755ae08600a0ff58aebcb7be6");
});
// these were generated from the map/reduce test suite
it('test generateErrorFromResponse() via map/reduce #1', function () {
var response = {"error": "not_found", "reason": "missing"};
var err = generateErrorFromResponse(response);
err.status.should.equal(404);
err.name.should.equal("not_found");
err.message.should.equal("missing");
err.error.should.equal(true);
});
it('test generateErrorFromResponse() via map/reduce #2', function () {
var response = {"error": "not_found", "reason": "no_db_file"};
var err = generateErrorFromResponse(response);
err.status.should.equal(404);
err.name.should.equal("not_found");
err.message.should.equal("missing");
err.error.should.equal(true);
});
it('test generateErrorFromResponse() via map/reduce #3', function () {
var response = {
"error": "invalid_value",
"reason": "builtin _sum function requires map values to be numbers or " +
"lists of numbers"
};
var err = generateErrorFromResponse(response);
err.status.should.equal(500);
err.name.should.equal("invalid_value");
err.message.should.equal("Database encountered an unknown error");
err.error.should.equal(true);
});
it('test generateErrorFromResponse() via map/reduce #4', function () {
var response = {
"error": "query_parse_error",
"reason": "Invalid value for positive integer: \"-1\""
};
var err = generateErrorFromResponse(response);
err.status.should.equal(400);
err.name.should.equal("query_parse_error");
err.message.should.equal("Some query parameter is invalid");
err.error.should.equal(true);
});
it('test generateErrorFromResponse() via map/reduce #5', function () {
var response = {
"error": "query_parse_error",
"reason": "Invalid value for integer: \"exact\""
};
var err = generateErrorFromResponse(response);
err.status.should.equal(400);
err.name.should.equal("query_parse_error");
err.message.should.equal("Some query parameter is invalid");
err.error.should.equal(true);
});
it('test generateErrorFromResponse() via map/reduce #6', function () {
var response = {
"error": "query_parse_error",
"reason": "Invalid value for integer: \"1a\""
};
var err = generateErrorFromResponse(response);
err.status.should.equal(400);
err.name.should.equal("query_parse_error");
err.message.should.equal("Some query parameter is invalid");
err.error.should.equal(true);
});
it('test generateErrorFromResponse() via map/reduce #7', function () {
var response = {
"error": "query_parse_error",
"reason": "No rows can match your key range, reverse your start_key " +
"and end_key or set descending=true"
};
var err = generateErrorFromResponse(response);
err.status.should.equal(400);
err.name.should.equal("query_parse_error");
err.message.should.equal("Some query parameter is invalid");
err.error.should.equal(true);
});
it('test generateErrorFromResponse() via map/reduce #8', function () {
var response = {
"error": "query_parse_error",
"reason": "`include_docs` is invalid for reduce"
};
var err = generateErrorFromResponse(response);
err.status.should.equal(400);
err.name.should.equal("query_parse_error");
err.message.should.equal("Some query parameter is invalid");
err.error.should.equal(true);
});
it('test generateErrorFromResponse() via map/reduce #9', function () {
var response = {
"error": "query_parse_error",
"reason": "Multi-key fetchs for reduce views must use `group=true`"
};
var err = generateErrorFromResponse(response);
err.status.should.equal(400);
err.name.should.equal("query_parse_error");
err.message.should.equal("Some query parameter is invalid");
err.error.should.equal(true);
});
it('test generateErrorFromResponse() via map/reduce #10', function () {
var response = {"error": "not_found", "reason": "missing_named_view"};
var err = generateErrorFromResponse(response);
err.status.should.equal(404);
err.name.should.equal("not_found");
err.message.should.equal("missing");
err.error.should.equal(true);
});
it('test generateErrorFromResponse() via map/reduce #11', function () {
var response = {"error": "not_found", "reason": "deleted"};
var err = generateErrorFromResponse(response);
err.status.should.equal(404);
err.name.should.equal("not_found");
err.message.should.equal("missing");
err.error.should.equal(true);
});
it('test generateErrorFromResponse() via map/reduce #12', function () {
var response = {"error": "unknown_error", "reason": "function_clause"};
var err = generateErrorFromResponse(response);
err.status.should.equal(500);
err.name.should.equal("unknown_error");
err.message.should.equal("Database encountered an unknown error");
err.error.should.equal(true);
});
});