2014-02-12 05:23:40 -05:00
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
|
sinon = require('sinon')
|
|
|
|
require('chai').should()
|
|
|
|
modulePath = require('path').join __dirname, '../../../../app/js/Features/ThirdPartyDataStore/TpdsController.js'
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-02 09:15:30 -04:00
|
|
|
describe 'TpdsController', ->
|
2014-02-12 05:23:40 -05:00
|
|
|
beforeEach ->
|
2014-10-02 09:15:30 -04:00
|
|
|
@TpdsUpdateHandler = {}
|
|
|
|
@TpdsController = SandboxedModule.require modulePath, requires:
|
|
|
|
'./TpdsUpdateHandler':@TpdsUpdateHandler
|
|
|
|
'./UpdateMerger': @UpdateMerger = {}
|
2014-02-12 05:23:40 -05:00
|
|
|
'logger-sharelatex':
|
|
|
|
log:->
|
|
|
|
err:->
|
|
|
|
@user_id = "dsad29jlkjas"
|
|
|
|
|
|
|
|
describe 'getting an update', ->
|
|
|
|
|
|
|
|
it 'should process the update with the update reciver', (done)->
|
|
|
|
path = "/projectName/here.txt"
|
|
|
|
req =
|
|
|
|
pause:->
|
|
|
|
params:{0:path, "user_id":@user_id}
|
|
|
|
session:
|
|
|
|
destroy:->
|
2014-10-15 09:11:02 -04:00
|
|
|
@TpdsUpdateHandler.newUpdate = sinon.stub().callsArg(4)
|
2014-02-12 05:23:40 -05:00
|
|
|
res = send: =>
|
2014-10-02 09:15:30 -04:00
|
|
|
@TpdsUpdateHandler.newUpdate.calledWith(@user_id, "projectName","/here.txt", req).should.equal true
|
2014-02-12 05:23:40 -05:00
|
|
|
done()
|
2014-10-02 09:15:30 -04:00
|
|
|
@TpdsController.mergeUpdate req, res
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
describe 'getting a delete update', ->
|
|
|
|
it 'should process the delete with the update reciver', (done)->
|
|
|
|
path = "/projectName/here.txt"
|
|
|
|
req =
|
|
|
|
params:{0:path, "user_id":@user_id}
|
|
|
|
session:
|
|
|
|
destroy:->
|
2014-10-15 09:11:02 -04:00
|
|
|
@TpdsUpdateHandler.deleteUpdate = sinon.stub().callsArg(3)
|
2014-02-12 05:23:40 -05:00
|
|
|
res = send: =>
|
2014-10-02 09:15:30 -04:00
|
|
|
@TpdsUpdateHandler.deleteUpdate.calledWith(@user_id, "projectName", "/here.txt").should.equal true
|
2014-02-12 05:23:40 -05:00
|
|
|
done()
|
2014-10-02 09:15:30 -04:00
|
|
|
@TpdsController.deleteUpdate req, res
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
describe 'parseParams', ->
|
|
|
|
|
|
|
|
it 'should take the project name off the start and replace with slash', ->
|
|
|
|
path = "noSlashHere"
|
|
|
|
req = params:{0:path, user_id:@user_id}
|
2014-10-02 09:15:30 -04:00
|
|
|
result = @TpdsController.parseParams(req)
|
2014-02-12 05:23:40 -05:00
|
|
|
result.user_id.should.equal @user_id
|
|
|
|
result.filePath.should.equal "/"
|
|
|
|
result.projectName.should.equal path
|
|
|
|
|
|
|
|
|
|
|
|
it 'should take the project name off the start and return it with no slashes in', ->
|
|
|
|
path = "/project/file.tex"
|
|
|
|
req = params:{0:path, user_id:@user_id}
|
2014-10-02 09:15:30 -04:00
|
|
|
result = @TpdsController.parseParams(req)
|
2014-02-12 05:23:40 -05:00
|
|
|
result.user_id.should.equal @user_id
|
|
|
|
result.filePath.should.equal "/file.tex"
|
|
|
|
result.projectName.should.equal "project"
|
|
|
|
|
|
|
|
it 'should take the project name of and return a slash for the file path', ->
|
|
|
|
path = "/project_name"
|
|
|
|
req = params:{0:path, user_id:@user_id}
|
2014-10-02 09:15:30 -04:00
|
|
|
result = @TpdsController.parseParams(req)
|
2014-02-12 05:23:40 -05:00
|
|
|
result.projectName.should.equal "project_name"
|
|
|
|
result.filePath.should.equal "/"
|
2014-10-02 09:15:30 -04:00
|
|
|
|
|
|
|
describe 'updateProjectContents', ->
|
|
|
|
beforeEach ->
|
|
|
|
@UpdateMerger.mergeUpdate = sinon.stub().callsArg(3)
|
|
|
|
@req =
|
|
|
|
params:
|
|
|
|
0: @path = "chapters/main.tex"
|
|
|
|
project_id: @project_id = "project-id-123"
|
|
|
|
session:
|
|
|
|
destroy: sinon.stub()
|
2014-10-15 09:11:02 -04:00
|
|
|
headers:
|
|
|
|
"x-update-source": @source = "github"
|
2014-10-02 09:15:30 -04:00
|
|
|
@res =
|
|
|
|
send: sinon.stub()
|
|
|
|
|
|
|
|
@TpdsController.updateProjectContents @req, @res
|
|
|
|
|
|
|
|
it "should merge the update", ->
|
|
|
|
@UpdateMerger.mergeUpdate
|
2014-10-03 06:33:18 -04:00
|
|
|
.calledWith(@project_id, "/" + @path, @req)
|
2014-10-02 09:15:30 -04:00
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should return a success", ->
|
|
|
|
@res.send.calledWith(200).should.equal true
|
|
|
|
|
|
|
|
it "should clear the session", ->
|
|
|
|
@req.session.destroy.called.should.equal true
|
|
|
|
|
|
|
|
describe 'deleteProjectContents', ->
|
|
|
|
beforeEach ->
|
|
|
|
@UpdateMerger.deleteUpdate = sinon.stub().callsArg(2)
|
|
|
|
@req =
|
|
|
|
params:
|
|
|
|
0: @path = "chapters/main.tex"
|
|
|
|
project_id: @project_id = "project-id-123"
|
|
|
|
session:
|
|
|
|
destroy: sinon.stub()
|
2014-10-15 09:11:02 -04:00
|
|
|
headers:
|
|
|
|
"x-update-source": @source = "github"
|
2014-10-02 09:15:30 -04:00
|
|
|
@res =
|
|
|
|
send: sinon.stub()
|
|
|
|
|
|
|
|
@TpdsController.deleteProjectContents @req, @res
|
|
|
|
|
|
|
|
it "should delete the file", ->
|
|
|
|
@UpdateMerger.deleteUpdate
|
2014-10-03 06:33:18 -04:00
|
|
|
.calledWith(@project_id, "/" + @path)
|
2014-10-02 09:15:30 -04:00
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should return a success", ->
|
|
|
|
@res.send.calledWith(200).should.equal true
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2014-10-02 09:15:30 -04:00
|
|
|
it "should clear the session", ->
|
|
|
|
@req.session.destroy.called.should.equal true
|
2014-02-12 05:23:40 -05:00
|
|
|
|