2014-02-12 05:23:40 -05:00
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
|
assert = require('assert')
|
|
|
|
require('chai').should()
|
|
|
|
modulePath = require('path').join __dirname, '../../../../app/js/Features/ThirdPartyDataStore/TpdsUpdateSender.js'
|
|
|
|
sinon = require('sinon')
|
|
|
|
ath = require('path')
|
|
|
|
project_id = "project_id_here"
|
|
|
|
user_id = "user_id_here"
|
|
|
|
read_only_ref_1 = "read_only_ref_1_id_here"
|
|
|
|
collaberator_ref_1 = "collaberator_ref_1_here"
|
|
|
|
project_name = "project_name_here"
|
|
|
|
|
|
|
|
thirdPartyDataStoreApiUrl = "http://third-party-json-store.herokuapp.com"
|
|
|
|
httpUsername = "user"
|
|
|
|
httpPass = "pass"
|
|
|
|
siteUrl = "http://www.localhost:3000"
|
|
|
|
httpAuthSiteUrl = "http://#{httpUsername}:#{httpPass}@www.localhost:3000"
|
|
|
|
filestoreUrl = "filestore.sharelatex.com"
|
|
|
|
|
|
|
|
describe 'TpdsUpdateSender', ->
|
|
|
|
beforeEach ->
|
2015-06-22 17:28:17 -04:00
|
|
|
@requestQueuer = (queue, meth, opts, callback)->
|
2016-03-08 06:54:45 -05:00
|
|
|
project = {owner_ref:user_id}
|
|
|
|
member_ids = [collaberator_ref_1, read_only_ref_1, user_id]
|
|
|
|
@CollaboratorsHandler =
|
|
|
|
getMemberIds: sinon.stub().yields(null, member_ids)
|
2014-02-12 05:23:40 -05:00
|
|
|
@Project = findById:sinon.stub().callsArgWith(2, null, project)
|
2014-05-20 08:18:59 -04:00
|
|
|
@docstoreUrl = "docstore.sharelatex.env"
|
2015-07-02 07:09:08 -04:00
|
|
|
@request = sinon.stub().returns(pipe:->)
|
|
|
|
@settings =
|
|
|
|
siteUrl:siteUrl
|
|
|
|
httpAuthSiteUrl:httpAuthSiteUrl,
|
|
|
|
apis:
|
|
|
|
thirdPartyDataStore: {url: thirdPartyDataStoreApiUrl}
|
|
|
|
filestore:
|
|
|
|
url: filestoreUrl
|
|
|
|
docstore:
|
|
|
|
pubUrl: @docstoreUrl
|
2014-02-12 05:23:40 -05:00
|
|
|
@updateSender = SandboxedModule.require modulePath, requires:
|
2015-07-02 07:09:08 -04:00
|
|
|
"settings-sharelatex": @settings
|
2014-02-12 05:23:40 -05:00
|
|
|
"logger-sharelatex":{log:->}
|
|
|
|
'../../models/Project': Project:@Project
|
2015-07-02 07:09:08 -04:00
|
|
|
'request':@request
|
2016-03-08 06:54:45 -05:00
|
|
|
'../Collaborators/CollaboratorsHandler': @CollaboratorsHandler
|
2015-07-02 07:09:08 -04:00
|
|
|
|
|
|
|
describe "_enqueue", ->
|
|
|
|
|
|
|
|
it "should not call request if there is no tpdsworker url", (done)->
|
|
|
|
@updateSender._enqueue null, null, null, (err)=>
|
|
|
|
@request.called.should.equal false
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should post the message to the tpdsworker", (done)->
|
|
|
|
@settings.apis.tpdsworker = url:"www.tpdsworker.env"
|
|
|
|
group = "myproject"
|
|
|
|
method = "somemethod"
|
|
|
|
job = "do something"
|
|
|
|
@request.callsArgWith(1)
|
|
|
|
@updateSender._enqueue group, method, job, (err)=>
|
|
|
|
args = @request.args[0][0]
|
|
|
|
args.json.group.should.equal group
|
|
|
|
args.json.job.should.equal job
|
|
|
|
args.json.method.should.equal method
|
|
|
|
args.uri.should.equal "www.tpdsworker.env/enqueue/web_to_tpds_http_requests"
|
|
|
|
done()
|
|
|
|
|
|
|
|
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
describe 'sending updates', ->
|
|
|
|
|
2015-06-22 17:28:17 -04:00
|
|
|
it 'queues a post the file with user and file id', (done)->
|
2014-02-12 05:23:40 -05:00
|
|
|
file_id = '4545345'
|
|
|
|
path = '/some/path/here.jpg'
|
2015-06-22 17:28:17 -04:00
|
|
|
@updateSender._enqueue = (uid, method, job, callback)->
|
2014-02-12 05:23:40 -05:00
|
|
|
uid.should.equal project_id
|
|
|
|
job.method.should.equal "post"
|
|
|
|
job.streamOrigin.should.equal "#{filestoreUrl}/project/#{project_id}/file/#{file_id}"
|
|
|
|
expectedUrl = "#{thirdPartyDataStoreApiUrl}/user/#{user_id}/entity/#{encodeURIComponent(project_name)}#{encodeURIComponent(path)}"
|
|
|
|
job.uri.should.equal expectedUrl
|
|
|
|
job.headers.sl_all_user_ids.should.eql(JSON.stringify([collaberator_ref_1, read_only_ref_1, user_id]))
|
|
|
|
done()
|
|
|
|
@updateSender.addFile {project_id:project_id, file_id:file_id, path:path, project_name:project_name}, ->
|
|
|
|
|
2014-05-20 08:19:02 -04:00
|
|
|
it 'post doc with stream origin of docstore', (done)->
|
2014-02-12 05:23:40 -05:00
|
|
|
doc_id = "4545345"
|
|
|
|
path = "/some/path/here.tex"
|
|
|
|
lines = ["line1", "line2", "line3"]
|
|
|
|
|
2015-06-22 17:28:17 -04:00
|
|
|
@updateSender._enqueue = (uid, method, job, callback)=>
|
2014-02-12 05:23:40 -05:00
|
|
|
uid.should.equal project_id
|
|
|
|
job.method.should.equal "post"
|
|
|
|
expectedUrl = "#{thirdPartyDataStoreApiUrl}/user/#{user_id}/entity/#{encodeURIComponent(project_name)}#{encodeURIComponent(path)}"
|
|
|
|
job.uri.should.equal expectedUrl
|
2014-05-20 08:19:02 -04:00
|
|
|
job.streamOrigin.should.equal "#{@docstoreUrl}/project/#{project_id}/doc/#{doc_id}/raw"
|
2014-02-12 05:23:40 -05:00
|
|
|
job.headers.sl_all_user_ids.should.eql(JSON.stringify([collaberator_ref_1, read_only_ref_1, user_id]))
|
|
|
|
done()
|
|
|
|
@updateSender.addDoc {project_id:project_id, doc_id:doc_id, path:path, docLines:lines,project_name:project_name}
|
|
|
|
|
|
|
|
it 'deleting entity', (done)->
|
|
|
|
path = "/path/here/t.tex"
|
2015-06-22 17:28:17 -04:00
|
|
|
@updateSender._enqueue = (uid, method, job, callback)->
|
2014-02-12 05:23:40 -05:00
|
|
|
uid.should.equal project_id
|
|
|
|
job.method.should.equal "DELETE"
|
|
|
|
expectedUrl = "#{thirdPartyDataStoreApiUrl}/user/#{user_id}/entity/#{encodeURIComponent(project_name)}#{encodeURIComponent(path)}"
|
|
|
|
job.headers.sl_all_user_ids.should.eql(JSON.stringify([collaberator_ref_1, read_only_ref_1, user_id]))
|
|
|
|
job.uri.should.equal expectedUrl
|
|
|
|
done()
|
|
|
|
@updateSender.deleteEntity {project_id:project_id, path:path, project_name:project_name}
|
|
|
|
|
|
|
|
it 'moving entity', (done)->
|
|
|
|
startPath = "staring/here/file.tex"
|
|
|
|
endPath = "ending/here/file.tex"
|
2015-06-22 17:28:17 -04:00
|
|
|
@updateSender._enqueue = (uid, method, job, callback)->
|
2014-02-12 05:23:40 -05:00
|
|
|
uid.should.equal project_id
|
|
|
|
job.method.should.equal "put"
|
|
|
|
job.uri.should.equal "#{thirdPartyDataStoreApiUrl}/user/#{user_id}/entity"
|
|
|
|
job.json.startPath.should.equal "/#{project_name}/#{startPath}"
|
|
|
|
job.json.endPath.should.equal "/#{project_name}/#{endPath}"
|
|
|
|
job.headers.sl_all_user_ids.should.eql(JSON.stringify([collaberator_ref_1, read_only_ref_1, user_id]))
|
|
|
|
done()
|
|
|
|
@updateSender.moveEntity {project_id:project_id, startPath:startPath, endPath:endPath, project_name:project_name}
|
|
|
|
|
|
|
|
it 'should be able to rename a project using the move entity func', (done)->
|
|
|
|
oldProjectName = "/oldProjectName/"
|
|
|
|
newProjectName = "/newProjectName/"
|
2015-06-22 17:28:17 -04:00
|
|
|
@updateSender._enqueue = (uid, method, job, callback)->
|
2014-02-12 05:23:40 -05:00
|
|
|
uid.should.equal project_id
|
|
|
|
job.method.should.equal "put"
|
|
|
|
job.uri.should.equal "#{thirdPartyDataStoreApiUrl}/user/#{user_id}/entity"
|
|
|
|
job.json.startPath.should.equal oldProjectName
|
|
|
|
job.json.endPath.should.equal newProjectName
|
|
|
|
job.headers.sl_all_user_ids.should.eql(JSON.stringify([collaberator_ref_1, read_only_ref_1, user_id]))
|
|
|
|
done()
|
|
|
|
@updateSender.moveEntity {project_id:project_id, project_name:oldProjectName, newProjectName:newProjectName}
|
2014-08-13 12:26:18 -04:00
|
|
|
|
|
|
|
it "pollDropboxForUser", (done) ->
|
2015-06-22 17:28:17 -04:00
|
|
|
@updateSender._enqueue = sinon.stub().callsArg(3)
|
2014-08-13 12:26:18 -04:00
|
|
|
@updateSender.pollDropboxForUser user_id, (error) =>
|
2015-06-22 17:28:17 -04:00
|
|
|
@updateSender._enqueue
|
2014-08-13 12:26:18 -04:00
|
|
|
.calledWith(
|
|
|
|
"poll-dropbox:#{user_id}",
|
|
|
|
"standardHttpRequest",
|
|
|
|
{
|
|
|
|
method: "POST"
|
|
|
|
uri: "#{thirdPartyDataStoreApiUrl}/user/poll"
|
|
|
|
json:
|
|
|
|
user_ids: [user_id]
|
|
|
|
}
|
|
|
|
)
|
|
|
|
.should.equal true
|
|
|
|
done()
|