From 119be26989b6c188fa4982798dd627511ce33dff Mon Sep 17 00:00:00 2001 From: Alasdair Smith Date: Wed, 15 Nov 2017 15:59:13 +0000 Subject: [PATCH] Remove unnecessary project getter Had bad assumption about whether ol-integration module would be available in filesystem, now replaced with Module hook --- .../Features/Project/V1ProjectGetter.coffee | 21 -------- .../Project/V1ProjectGetterTests.coffee | 54 ------------------- 2 files changed, 75 deletions(-) delete mode 100644 services/web/app/coffee/Features/Project/V1ProjectGetter.coffee delete mode 100644 services/web/test/UnitTests/coffee/Project/V1ProjectGetterTests.coffee diff --git a/services/web/app/coffee/Features/Project/V1ProjectGetter.coffee b/services/web/app/coffee/Features/Project/V1ProjectGetter.coffee deleted file mode 100644 index b304429b2f..0000000000 --- a/services/web/app/coffee/Features/Project/V1ProjectGetter.coffee +++ /dev/null @@ -1,21 +0,0 @@ -fs = require 'fs' -path = require 'path' -logger = require 'logger-sharelatex' - -INTEGRATION_MODULE_PATH = path.resolve(__dirname, '../../../../modules/overleaf-integration-web-module') - -V1ProjectGetter = - # Default implementation is a no-op - findAllUsersProjects: (userId, callback = (error, projects) ->) -> - logger.log {}, "integration modules doesn't exist, not loading V1 projects" - return callback() - -fs.stat INTEGRATION_MODULE_PATH, (error, stats) -> - return if error? or !stats.isDirectory() - logger.log {isDirectory: stats.isDirectory()}, "integration module does exist, loading V1 projects" - # Monkey patch impl to actually fetch projects - V1ProjectGetter.findAllUsersProjects = (userId, callback = (error, projects) ->) -> - IntegrationProjectListGetter = require(path.join(INTEGRATION_MODULE_PATH, 'app/coffee/ProjectList/ProjectListGetter')) - IntegrationProjectListGetter.findAllUsersProjects(userId, callback) - -module.exports = V1ProjectGetter \ No newline at end of file diff --git a/services/web/test/UnitTests/coffee/Project/V1ProjectGetterTests.coffee b/services/web/test/UnitTests/coffee/Project/V1ProjectGetterTests.coffee deleted file mode 100644 index c97574550b..0000000000 --- a/services/web/test/UnitTests/coffee/Project/V1ProjectGetterTests.coffee +++ /dev/null @@ -1,54 +0,0 @@ -sinon = require('sinon') -should = require('chai').should() -SandboxedModule = require('sandboxed-module') - -modulePath = '../../../../app/js/Features/Project/V1ProjectGetter.js' - -describe 'V1ProjectGetter', -> - beforeEach -> - @path = - resolve: sinon.stub().returns('path/to/integration/module') - join: sinon.stub().returns('path/to/file/in/integration/module') - @IntegrationProjectListGetter = - findAllUsersProjects: sinon.stub() - @userId = 123 - @callback = sinon.stub() - - describe 'without overleaf-integration-web-module', -> - beforeEach -> - @fs = - stat: sinon.stub().yields({code: 'mock-ENOENT-error'}) - @V1ProjectGetter = SandboxedModule.require modulePath, requires: - # Mock not finding integration module - 'fs': @fs - 'path': @path - 'logger-sharelatex': log: -> - 'path/to/file/in/integration/module': @IntegrationProjectListGetter - # Call method - @V1ProjectGetter.findAllUsersProjects @userId, @callback - - it 'should call the callback with no arguments', -> - @callback.calledWith().should.equal true - @IntegrationProjectListGetter.findAllUsersProjects.called.should.equal false - - describe 'with overleaf-integration-web-module', -> - beforeEach -> - @fs = - stat: sinon.stub().yields(null, isDirectory: sinon.stub().returns(true)) - @V1ProjectGetter = SandboxedModule.require modulePath, requires: - # Mock finding integration module - 'fs': @fs - 'path': @path - 'logger-sharelatex': log: -> - 'path/to/file/in/integration/module': @IntegrationProjectListGetter - # Mock integration module response - @IntegrationProjectListGetter.findAllUsersProjects.yields(null, @response = { - projects: [{ id: '123mockV1Id', title: 'mock title' }] - tags: [{ name: 'mock tag', project_ids: ['123mockV1Id'] }] - }) - # Call method - @V1ProjectGetter.findAllUsersProjects @userId, @callback - - it 'should call the callback with all the projects and tags', -> - @callback.calledWith(null, @response).should.equal true - @IntegrationProjectListGetter.findAllUsersProjects.called.should.equal true