ProjectPersistenceManagerTests.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* eslint-disable
  2. camelcase,
  3. no-return-assign,
  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. * DS101: Remove unnecessary use of Array.from
  11. * DS102: Remove unnecessary code created because of implicit returns
  12. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  13. */
  14. const SandboxedModule = require('sandboxed-module');
  15. const sinon = require('sinon');
  16. require('chai').should();
  17. const modulePath = require('path').join(__dirname, '../../../app/js/ProjectPersistenceManager');
  18. const tk = require("timekeeper");
  19. describe("ProjectPersistenceManager", function() {
  20. beforeEach(function() {
  21. this.ProjectPersistenceManager = SandboxedModule.require(modulePath, { requires: {
  22. "./UrlCache": (this.UrlCache = {}),
  23. "./CompileManager": (this.CompileManager = {}),
  24. "logger-sharelatex": (this.logger = { log: sinon.stub() }),
  25. "./db": (this.db = {})
  26. }
  27. });
  28. this.callback = sinon.stub();
  29. this.project_id = "project-id-123";
  30. return this.user_id = "1234";
  31. });
  32. describe("clearExpiredProjects", function() {
  33. beforeEach(function() {
  34. this.project_ids = [
  35. "project-id-1",
  36. "project-id-2"
  37. ];
  38. this.ProjectPersistenceManager._findExpiredProjectIds = sinon.stub().callsArgWith(0, null, this.project_ids);
  39. this.ProjectPersistenceManager.clearProjectFromCache = sinon.stub().callsArg(1);
  40. this.CompileManager.clearExpiredProjects = sinon.stub().callsArg(1);
  41. return this.ProjectPersistenceManager.clearExpiredProjects(this.callback);
  42. });
  43. it("should clear each expired project", function() {
  44. return Array.from(this.project_ids).map((project_id) =>
  45. this.ProjectPersistenceManager.clearProjectFromCache
  46. .calledWith(project_id)
  47. .should.equal(true));
  48. });
  49. return it("should call the callback", function() {
  50. return this.callback.called.should.equal(true);
  51. });
  52. });
  53. return describe("clearProject", function() {
  54. beforeEach(function() {
  55. this.ProjectPersistenceManager._clearProjectFromDatabase = sinon.stub().callsArg(1);
  56. this.UrlCache.clearProject = sinon.stub().callsArg(1);
  57. this.CompileManager.clearProject = sinon.stub().callsArg(2);
  58. return this.ProjectPersistenceManager.clearProject(this.project_id, this.user_id, this.callback);
  59. });
  60. it("should clear the project from the database", function() {
  61. return this.ProjectPersistenceManager._clearProjectFromDatabase
  62. .calledWith(this.project_id)
  63. .should.equal(true);
  64. });
  65. it("should clear all the cached Urls for the project", function() {
  66. return this.UrlCache.clearProject
  67. .calledWith(this.project_id)
  68. .should.equal(true);
  69. });
  70. it("should clear the project compile folder", function() {
  71. return this.CompileManager.clearProject
  72. .calledWith(this.project_id, this.user_id)
  73. .should.equal(true);
  74. });
  75. return it("should call the callback", function() {
  76. return this.callback.called.should.equal(true);
  77. });
  78. });
  79. });