ProjectPersistenceManagerTests.js 2.8 KB

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