MongoAWS.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* eslint-disable
  2. handle-callback-err,
  3. no-return-assign,
  4. */
  5. // TODO: This file was created by bulk-decaffeinate.
  6. // Fix any style issues and re-enable lint.
  7. /*
  8. * decaffeinate suggestions:
  9. * DS102: Remove unnecessary code created because of implicit returns
  10. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  11. */
  12. const chai = require('chai');
  13. chai.should();
  14. const sinon = require("sinon");
  15. const modulePath = "../../../../app/js/MongoAWS.js";
  16. const SandboxedModule = require('sandboxed-module');
  17. const {ObjectId} = require("mongojs");
  18. const MemoryStream = require('memorystream');
  19. const zlib = require("zlib");
  20. describe("MongoAWS", function() {
  21. beforeEach(function() {
  22. this.MongoAWS = SandboxedModule.require(modulePath, { requires: {
  23. "settings-sharelatex": (this.settings = {
  24. trackchanges: {
  25. s3: {
  26. secret: "s3-secret",
  27. key: "s3-key"
  28. },
  29. stores: {
  30. doc_history: "s3-bucket"
  31. }
  32. }
  33. }),
  34. "child_process": (this.child_process = {}),
  35. "mongo-uri": (this.mongouri = {}),
  36. "logger-sharelatex": (this.logger = {log: sinon.stub(), error: sinon.stub(), err() {}}),
  37. "aws-sdk": (this.awssdk = {}),
  38. "fs": (this.fs = {}),
  39. "s3-streams": (this.S3S = {}),
  40. "./mongojs" : { db: (this.db = {}), ObjectId },
  41. "JSONStream": (this.JSONStream = {}),
  42. "readline-stream": (this.readline = sinon.stub()),
  43. 'metrics-sharelatex': {inc(){}}
  44. }
  45. });
  46. this.project_id = ObjectId().toString();
  47. this.doc_id = ObjectId().toString();
  48. this.pack_id = ObjectId();
  49. this.update = { v:123 };
  50. return this.callback = sinon.stub();
  51. });
  52. describe("archivePack", function() {
  53. beforeEach(function(done) {
  54. this.awssdk.config = { update: sinon.stub() };
  55. this.awssdk.S3 = sinon.stub();
  56. this.S3S.WriteStream = () => MemoryStream.createWriteStream();
  57. this.db.docHistory = {};
  58. this.db.docHistory.findOne = sinon.stub().callsArgWith(1, null, {"pack":"hello"});
  59. return this.MongoAWS.archivePack(this.project_id, this.doc_id, this.pack_id, (err, result) => {
  60. this.callback();
  61. return done();
  62. });
  63. });
  64. return it("should call the callback", function() {
  65. return this.callback.called.should.equal(true);
  66. });
  67. });
  68. return describe("unArchivePack", function() {
  69. beforeEach(function(done) {
  70. return zlib.gzip('{"pack":"123"}', (err, zbuf) => {
  71. this.awssdk.config = { update: sinon.stub() };
  72. this.awssdk.S3 = sinon.stub();
  73. this.S3S.ReadStream = () => MemoryStream.createReadStream(zbuf, {readable:true});
  74. this.db.docHistory = {};
  75. this.db.docHistory.insert = sinon.stub().callsArgWith(1, null, "pack");
  76. return this.MongoAWS.unArchivePack(this.project_id, this.doc_id, this.pack_id, (err, result) => {
  77. this.callback();
  78. return done();
  79. });
  80. });
  81. });
  82. return it("should call db.docHistory.insert", function() {
  83. return this.db.docHistory.insert.called.should.equal(true);
  84. });
  85. });
  86. });