PageRenderTime 58ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/node_modules/nano/tests/shared/error.js

https://bitbucket.org/E_lexy/jmonitor
JavaScript | 96 lines | 85 code | 10 blank | 1 comment | 0 complexity | 03ad6af1ccffef6dd73c8f33254767fe MD5 | raw file
Possible License(s): MIT, Apache-2.0, BSD-3-Clause
  1. var specify = require("specify")
  2. , helpers = require("../helpers")
  3. , timeout = helpers.timeout
  4. , nano = helpers.nano
  5. , Nano = helpers.Nano
  6. , nock = helpers.nock
  7. ;
  8. var mock = nock(helpers.couch, "shared/error")
  9. , db = nano.use("shared_error")
  10. ;
  11. specify("shared_error:setup", timeout, function (assert) {
  12. nano.db.create("shared_error", function (err) {
  13. assert.equal(err, undefined, "Failed to create database");
  14. db.insert({"foo": "baz"}, "foobaz", function (error, foo) {
  15. assert.equal(error, undefined, "Should have stored foobaz");
  16. assert.equal(foo.ok, true, "Response should be ok");
  17. assert.equal(foo.id, "foobaz", "My id is foobaz");
  18. assert.ok(foo.rev, "Response should have rev");
  19. });
  20. });
  21. });
  22. specify("shared_error:conflict", timeout, function (assert) {
  23. db.insert({"foo": "bar"}, "foobaz", function (error, response) {
  24. assert.equal(error["status-code"], 409, "Should be conflict");
  25. assert.equal(error.message, error.reason, "Message should be reason");
  26. assert.equal(error.scope, "couch", "Scope is couch");
  27. assert.equal(error.error, "conflict", "Error is conflict");
  28. });
  29. });
  30. specify("shared_error:init", timeout, function (assert) {
  31. try {
  32. Nano('Not a File');
  33. } catch(err) {
  34. assert.ok(err, "There must be an error");
  35. assert.ok(err.message, "A note is given");
  36. assert.equal(err.errid, "bad_file", "Code is right");
  37. assert.equal(err.scope, "init", "Scope is init");
  38. }
  39. try {
  40. Nano({});
  41. } catch(err2) {
  42. assert.ok(err2, "There must be an error");
  43. assert.ok(err2.message, "A note is given");
  44. assert.equal(err2.errid, "bad_url", "Code is right");
  45. assert.equal(err2.scope, "init", "Scope is init");
  46. }
  47. });
  48. specify("shared_error:root", timeout, function (assert) {
  49. // this shouldn't error
  50. var root = nano.request()
  51. , buffer = ""
  52. ;
  53. root.on('data', function (chunk) { buffer += chunk; });
  54. root.on('end', function () {
  55. assert.ok(true, "Ended");
  56. });
  57. });
  58. specify("shared_error:stream", timeout, function (assert) {
  59. db.list("bad params").on('error', function (error) {
  60. assert.ok(error.message, "A note is given");
  61. assert.equal(error.errid, "bad_params", "Code is right");
  62. assert.equal(error.scope, "nano", "Scope exists");
  63. });
  64. });
  65. specify("shared_error:callback", timeout, function (assert) {
  66. db.list("bad params", function (error, response) {
  67. assert.ok(error, "There must be an error");
  68. assert.ok(error.message, "A note is given");
  69. assert.equal(error.errid, "bad_params", "Code is right");
  70. assert.equal(error.scope, "nano", "Scope exists");
  71. });
  72. });
  73. specify("shared_error:bad_delete", timeout, function (assert) {
  74. nano.db.destroy("say_wat_wat", function (error, response) {
  75. assert.ok(error, "There must be an error");
  76. assert.ok(error.message, "A note is given");
  77. assert.equal(error.description,'missing');
  78. });
  79. });
  80. specify("shared_error:teardown", timeout, function (assert) {
  81. nano.db.destroy("shared_error", function (err) {
  82. assert.equal(err, undefined, "Failed to destroy database");
  83. assert.ok(mock.isDone(), "Some mocks didn't run");
  84. });
  85. });
  86. specify.run(process.argv.slice(2));