GettingDocsTests.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* eslint-disable
  2. camelcase,
  3. handle-callback-err,
  4. no-unused-vars,
  5. */
  6. // TODO: This file was created by bulk-decaffeinate.
  7. // Fix any style issues and re-enable lint.
  8. /*
  9. * decaffeinate suggestions:
  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 {ObjectId} = require("mongojs");
  18. const DocstoreApp = require("./helpers/DocstoreApp");
  19. const DocstoreClient = require("./helpers/DocstoreClient");
  20. describe("Getting a doc", function() {
  21. beforeEach(function(done) {
  22. this.project_id = ObjectId();
  23. this.doc_id = ObjectId();
  24. this.lines = ["original", "lines"];
  25. this.version = 42;
  26. this.ranges = {
  27. changes: [{
  28. id: ObjectId().toString(),
  29. op: { i: "foo", p: 3 },
  30. meta: {
  31. user_id: ObjectId().toString(),
  32. ts: new Date().toString()
  33. }
  34. }]
  35. };
  36. return DocstoreApp.ensureRunning(() => {
  37. return DocstoreClient.createDoc(this.project_id, this.doc_id, this.lines, this.version, this.ranges, error => {
  38. if (error != null) { throw error; }
  39. return done();
  40. });
  41. });
  42. });
  43. describe("when the doc exists", function() { return it("should get the doc lines and version", function(done) {
  44. return DocstoreClient.getDoc(this.project_id, this.doc_id, {}, (error, res, doc) => {
  45. doc.lines.should.deep.equal(this.lines);
  46. doc.version.should.equal(this.version);
  47. doc.ranges.should.deep.equal(this.ranges);
  48. return done();
  49. });
  50. }); });
  51. describe("when the doc does not exist", function() { return it("should return a 404", function(done) {
  52. const missing_doc_id = ObjectId();
  53. return DocstoreClient.getDoc(this.project_id, missing_doc_id, {}, (error, res, doc) => {
  54. res.statusCode.should.equal(404);
  55. return done();
  56. });
  57. }); });
  58. return describe("when the doc is a deleted doc", function() {
  59. beforeEach(function(done) {
  60. this.deleted_doc_id = ObjectId();
  61. return DocstoreClient.createDoc(this.project_id, this.deleted_doc_id, this.lines, this.version, this.ranges, error => {
  62. if (error != null) { throw error; }
  63. return DocstoreClient.deleteDoc(this.project_id, this.deleted_doc_id, done);
  64. });
  65. });
  66. it("should return the doc", function(done) {
  67. return DocstoreClient.getDoc(this.project_id, this.deleted_doc_id, {include_deleted:true},(error, res, doc) => {
  68. doc.lines.should.deep.equal(this.lines);
  69. doc.version.should.equal(this.version);
  70. doc.ranges.should.deep.equal(this.ranges);
  71. doc.deleted.should.equal(true);
  72. return done();
  73. });
  74. });
  75. return it("should return a 404 when the query string is not set", function(done){
  76. return DocstoreClient.getDoc(this.project_id, this.deleted_doc_id, {},(error, res, doc) => {
  77. res.statusCode.should.equal(404);
  78. return done();
  79. });
  80. });
  81. });
  82. });