GettingProjectDocsTests.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* eslint-disable
  2. handle-callback-err,
  3. no-unused-vars,
  4. */
  5. // TODO: This file was created by bulk-decaffeinate.
  6. // Fix any style issues and re-enable lint.
  7. /*
  8. * decaffeinate suggestions:
  9. * DS101: Remove unnecessary use of Array.from
  10. * DS102: Remove unnecessary code created because of implicit returns
  11. * DS207: Consider shorter variations of null checks
  12. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  13. */
  14. const sinon = require("sinon");
  15. const chai = require("chai");
  16. chai.should();
  17. const {
  18. expect
  19. } = chai;
  20. const MockWebApi = require("./helpers/MockWebApi");
  21. const DocUpdaterClient = require("./helpers/DocUpdaterClient");
  22. const DocUpdaterApp = require("./helpers/DocUpdaterApp");
  23. describe("Getting documents for project", function() {
  24. before(function(done) {
  25. this.lines = ["one", "two", "three"];
  26. this.version = 42;
  27. return DocUpdaterApp.ensureRunning(done);
  28. });
  29. describe("when project state hash does not match", function() {
  30. before(function(done) {
  31. this.projectStateHash = DocUpdaterClient.randomId();
  32. [this.project_id, this.doc_id] = Array.from([DocUpdaterClient.randomId(), DocUpdaterClient.randomId()]);
  33. MockWebApi.insertDoc(this.project_id, this.doc_id, {lines: this.lines, version: this.version});
  34. return DocUpdaterClient.preloadDoc(this.project_id, this.doc_id, error => {
  35. if (error != null) { throw error; }
  36. return DocUpdaterClient.getProjectDocs(this.project_id, this.projectStateHash, (error, res, returnedDocs) => {
  37. this.res = res;
  38. this.returnedDocs = returnedDocs;
  39. return done();
  40. });
  41. });
  42. });
  43. return it("should return a 409 Conflict response", function() {
  44. return this.res.statusCode.should.equal(409);
  45. });
  46. });
  47. describe("when project state hash matches", function() {
  48. before(function(done) {
  49. this.projectStateHash = DocUpdaterClient.randomId();
  50. [this.project_id, this.doc_id] = Array.from([DocUpdaterClient.randomId(), DocUpdaterClient.randomId()]);
  51. MockWebApi.insertDoc(this.project_id, this.doc_id, {lines: this.lines, version: this.version});
  52. return DocUpdaterClient.preloadDoc(this.project_id, this.doc_id, error => {
  53. if (error != null) { throw error; }
  54. return DocUpdaterClient.getProjectDocs(this.project_id, this.projectStateHash, (error, res0, returnedDocs0) => {
  55. // set the hash
  56. this.res0 = res0;
  57. this.returnedDocs0 = returnedDocs0;
  58. return DocUpdaterClient.getProjectDocs(this.project_id, this.projectStateHash, (error, res, returnedDocs) => {
  59. // the hash should now match
  60. this.res = res;
  61. this.returnedDocs = returnedDocs;
  62. return done();
  63. });
  64. });
  65. });
  66. });
  67. it("should return a 200 response", function() {
  68. return this.res.statusCode.should.equal(200);
  69. });
  70. return it("should return the documents", function() {
  71. return this.returnedDocs.should.deep.equal([ {_id: this.doc_id, lines: this.lines, v: this.version} ]);
  72. });
  73. });
  74. return describe("when the doc has been removed", function() {
  75. before(function(done) {
  76. this.projectStateHash = DocUpdaterClient.randomId();
  77. [this.project_id, this.doc_id] = Array.from([DocUpdaterClient.randomId(), DocUpdaterClient.randomId()]);
  78. MockWebApi.insertDoc(this.project_id, this.doc_id, {lines: this.lines, version: this.version});
  79. return DocUpdaterClient.preloadDoc(this.project_id, this.doc_id, error => {
  80. if (error != null) { throw error; }
  81. return DocUpdaterClient.getProjectDocs(this.project_id, this.projectStateHash, (error, res0, returnedDocs0) => {
  82. // set the hash
  83. this.res0 = res0;
  84. this.returnedDocs0 = returnedDocs0;
  85. return DocUpdaterClient.deleteDoc(this.project_id, this.doc_id, (error, res, body) => {
  86. // delete the doc
  87. return DocUpdaterClient.getProjectDocs(this.project_id, this.projectStateHash, (error, res1, returnedDocs) => {
  88. // the hash would match, but the doc has been deleted
  89. this.res = res1;
  90. this.returnedDocs = returnedDocs;
  91. return done();
  92. });
  93. });
  94. });
  95. });
  96. });
  97. return it("should return a 409 Conflict response", function() {
  98. return this.res.statusCode.should.equal(409);
  99. });
  100. });
  101. });