Merge branch 'master' into ho-annom-user-events
This commit is contained in:
@@ -69,7 +69,7 @@ describe "ChatController", ->
|
||||
@req.query =
|
||||
limit: @limit = "30"
|
||||
before: @before = "12345"
|
||||
@CommentsController._injectUserInfoIntoThreads = sinon.stub().yields()
|
||||
@ChatController._injectUserInfoIntoThreads = sinon.stub().yields()
|
||||
@ChatApiHandler.getGlobalMessages = sinon.stub().yields(null, @messages = ["mock", "messages"])
|
||||
@ChatController.getMessages @req, @res
|
||||
|
||||
@@ -79,4 +79,78 @@ describe "ChatController", ->
|
||||
.should.equal true
|
||||
|
||||
it "should return the messages", ->
|
||||
@res.json.calledWith(@messages).should.equal true
|
||||
@res.json.calledWith(@messages).should.equal true
|
||||
|
||||
describe "_injectUserInfoIntoThreads", ->
|
||||
beforeEach ->
|
||||
@users = {
|
||||
"user_id_1": {
|
||||
"mock": "user_1"
|
||||
}
|
||||
"user_id_2": {
|
||||
"mock": "user_2"
|
||||
}
|
||||
}
|
||||
@UserInfoManager.getPersonalInfo = (user_id, callback) =>
|
||||
return callback(null, @users[user_id])
|
||||
sinon.spy @UserInfoManager, "getPersonalInfo"
|
||||
@UserInfoController.formatPersonalInfo = (user) ->
|
||||
return { "formatted": user["mock"] }
|
||||
|
||||
it "should inject a user object into messaged and resolved data", (done) ->
|
||||
@ChatController._injectUserInfoIntoThreads {
|
||||
thread1: {
|
||||
resolved: true
|
||||
resolved_by_user_id: "user_id_1"
|
||||
messages: [{
|
||||
user_id: "user_id_1"
|
||||
content: "foo"
|
||||
}, {
|
||||
user_id: "user_id_2"
|
||||
content: "bar"
|
||||
}]
|
||||
},
|
||||
thread2: {
|
||||
messages: [{
|
||||
user_id: "user_id_1"
|
||||
content: "baz"
|
||||
}]
|
||||
}
|
||||
}, (error, threads) ->
|
||||
expect(threads).to.deep.equal {
|
||||
thread1: {
|
||||
resolved: true
|
||||
resolved_by_user_id: "user_id_1"
|
||||
resolved_by_user: { "formatted": "user_1" }
|
||||
messages: [{
|
||||
user_id: "user_id_1"
|
||||
user: { "formatted": "user_1" }
|
||||
content: "foo"
|
||||
}, {
|
||||
user_id: "user_id_2"
|
||||
user: { "formatted": "user_2" }
|
||||
content: "bar"
|
||||
}]
|
||||
},
|
||||
thread2: {
|
||||
messages: [{
|
||||
user_id: "user_id_1"
|
||||
user: { "formatted": "user_1" }
|
||||
content: "baz"
|
||||
}]
|
||||
}
|
||||
}
|
||||
done()
|
||||
|
||||
it "should only need to look up each user once", (done) ->
|
||||
@ChatController._injectUserInfoIntoThreads [{
|
||||
messages: [{
|
||||
user_id: "user_id_1"
|
||||
content: "foo"
|
||||
}, {
|
||||
user_id: "user_id_1"
|
||||
content: "bar"
|
||||
}]
|
||||
}], (error, threads) =>
|
||||
@UserInfoManager.getPersonalInfo.calledOnce.should.equal true
|
||||
done()
|
||||
@@ -1,284 +0,0 @@
|
||||
should = require('chai').should()
|
||||
SandboxedModule = require('sandboxed-module')
|
||||
assert = require('assert')
|
||||
path = require('path')
|
||||
sinon = require('sinon')
|
||||
modulePath = path.join __dirname, "../../../../app/js/Features/Comments/CommentsController"
|
||||
expect = require("chai").expect
|
||||
|
||||
describe "CommentsController", ->
|
||||
beforeEach ->
|
||||
@user_id = 'mock-user-id'
|
||||
@settings = {}
|
||||
@ChatApiHandler = {}
|
||||
@EditorRealTimeController =
|
||||
emitToRoom:sinon.stub()
|
||||
@AuthenticationController =
|
||||
getLoggedInUserId: sinon.stub().returns(@user_id)
|
||||
@CommentsController = SandboxedModule.require modulePath, requires:
|
||||
"settings-sharelatex": @settings
|
||||
"logger-sharelatex": log: ->
|
||||
"../Chat/ChatApiHandler": @ChatApiHandler
|
||||
"../Editor/EditorRealTimeController": @EditorRealTimeController
|
||||
'../Authentication/AuthenticationController': @AuthenticationController
|
||||
'../User/UserInfoManager': @UserInfoManager = {}
|
||||
'../User/UserInfoController': @UserInfoController = {}
|
||||
"../DocumentUpdater/DocumentUpdaterHandler": @DocumentUpdaterHandler = {}
|
||||
@req = {}
|
||||
@res =
|
||||
json: sinon.stub()
|
||||
send: sinon.stub()
|
||||
|
||||
describe "sendComment", ->
|
||||
beforeEach ->
|
||||
@req.params =
|
||||
project_id: @project_id = "mock-project-id"
|
||||
thread_id: @thread_id = "mock-thread-id"
|
||||
@req.body =
|
||||
content: @content = "message-content"
|
||||
@UserInfoManager.getPersonalInfo = sinon.stub().yields(null, @user = {"unformatted": "user"})
|
||||
@UserInfoController.formatPersonalInfo = sinon.stub().returns(@formatted_user = {"formatted": "user"})
|
||||
@ChatApiHandler.sendComment = sinon.stub().yields(null, @message = {"mock": "message", user_id: @user_id})
|
||||
@CommentsController.sendComment @req, @res
|
||||
|
||||
it "should look up the user", ->
|
||||
@UserInfoManager.getPersonalInfo
|
||||
.calledWith(@user_id)
|
||||
.should.equal true
|
||||
|
||||
it "should format and inject the user into the comment", ->
|
||||
@UserInfoController.formatPersonalInfo
|
||||
.calledWith(@user)
|
||||
.should.equal true
|
||||
@message.user.should.deep.equal @formatted_user
|
||||
|
||||
it "should tell the chat handler about the message", ->
|
||||
@ChatApiHandler.sendComment
|
||||
.calledWith(@project_id, @thread_id, @user_id, @content)
|
||||
.should.equal true
|
||||
|
||||
it "should tell the editor real time controller about the update with the data from the chat handler", ->
|
||||
@EditorRealTimeController.emitToRoom
|
||||
.calledWith(@project_id, "new-comment", @thread_id, @message)
|
||||
.should.equal true
|
||||
|
||||
it "should return a 204 status code", ->
|
||||
@res.send.calledWith(204).should.equal true
|
||||
|
||||
describe "getThreads", ->
|
||||
beforeEach ->
|
||||
@req.params =
|
||||
project_id: @project_id = "mock-project-id"
|
||||
@ChatApiHandler.getThreads = sinon.stub().yields(null, @threads = {"mock", "threads"})
|
||||
@CommentsController._injectUserInfoIntoThreads = sinon.stub().yields(null, @threads)
|
||||
@CommentsController.getThreads @req, @res
|
||||
|
||||
it "should ask the chat handler about the request", ->
|
||||
@ChatApiHandler.getThreads
|
||||
.calledWith(@project_id)
|
||||
.should.equal true
|
||||
|
||||
it "should inject the user details into the threads", ->
|
||||
@CommentsController._injectUserInfoIntoThreads
|
||||
.calledWith(@threads)
|
||||
.should.equal true
|
||||
|
||||
it "should return the messages", ->
|
||||
@res.json.calledWith(@threads).should.equal true
|
||||
|
||||
describe "resolveThread", ->
|
||||
beforeEach ->
|
||||
@req.params =
|
||||
project_id: @project_id = "mock-project-id"
|
||||
thread_id: @thread_id = "mock-thread-id"
|
||||
@ChatApiHandler.resolveThread = sinon.stub().yields()
|
||||
@UserInfoManager.getPersonalInfo = sinon.stub().yields(null, @user = {"unformatted": "user"})
|
||||
@UserInfoController.formatPersonalInfo = sinon.stub().returns(@formatted_user = {"formatted": "user"})
|
||||
@CommentsController.resolveThread @req, @res
|
||||
|
||||
it "should ask the chat handler to resolve the thread", ->
|
||||
@ChatApiHandler.resolveThread
|
||||
.calledWith(@project_id, @thread_id)
|
||||
.should.equal true
|
||||
|
||||
it "should look up the user", ->
|
||||
@UserInfoManager.getPersonalInfo
|
||||
.calledWith(@user_id)
|
||||
.should.equal true
|
||||
|
||||
it "should tell the client the comment was resolved", ->
|
||||
@EditorRealTimeController.emitToRoom
|
||||
.calledWith(@project_id, "resolve-thread", @thread_id, @formatted_user)
|
||||
.should.equal true
|
||||
|
||||
it "should return a success code", ->
|
||||
@res.send.calledWith(204).should.equal
|
||||
|
||||
describe "reopenThread", ->
|
||||
beforeEach ->
|
||||
@req.params =
|
||||
project_id: @project_id = "mock-project-id"
|
||||
thread_id: @thread_id = "mock-thread-id"
|
||||
@ChatApiHandler.reopenThread = sinon.stub().yields()
|
||||
@CommentsController.reopenThread @req, @res
|
||||
|
||||
it "should ask the chat handler to reopen the thread", ->
|
||||
@ChatApiHandler.reopenThread
|
||||
.calledWith(@project_id, @thread_id)
|
||||
.should.equal true
|
||||
|
||||
it "should tell the client the comment was resolved", ->
|
||||
@EditorRealTimeController.emitToRoom
|
||||
.calledWith(@project_id, "reopen-thread", @thread_id)
|
||||
.should.equal true
|
||||
|
||||
it "should return a success code", ->
|
||||
@res.send.calledWith(204).should.equal
|
||||
|
||||
describe "deleteThread", ->
|
||||
beforeEach ->
|
||||
@req.params =
|
||||
project_id: @project_id = "mock-project-id"
|
||||
doc_id: @doc_id = "mock-doc-id"
|
||||
thread_id: @thread_id = "mock-thread-id"
|
||||
@DocumentUpdaterHandler.deleteThread = sinon.stub().yields()
|
||||
@ChatApiHandler.deleteThread = sinon.stub().yields()
|
||||
@CommentsController.deleteThread @req, @res
|
||||
|
||||
it "should ask the doc udpater to delete the thread", ->
|
||||
@DocumentUpdaterHandler.deleteThread
|
||||
.calledWith(@project_id, @doc_id, @thread_id)
|
||||
.should.equal true
|
||||
|
||||
it "should ask the chat handler to delete the thread", ->
|
||||
@ChatApiHandler.deleteThread
|
||||
.calledWith(@project_id, @thread_id)
|
||||
.should.equal true
|
||||
|
||||
it "should tell the client the thread was deleted", ->
|
||||
@EditorRealTimeController.emitToRoom
|
||||
.calledWith(@project_id, "delete-thread", @thread_id)
|
||||
.should.equal true
|
||||
|
||||
it "should return a success code", ->
|
||||
@res.send.calledWith(204).should.equal
|
||||
|
||||
describe "editMessage", ->
|
||||
beforeEach ->
|
||||
@req.params =
|
||||
project_id: @project_id = "mock-project-id"
|
||||
thread_id: @thread_id = "mock-thread-id"
|
||||
message_id: @message_id = "mock-thread-id"
|
||||
@req.body =
|
||||
content: @content = "mock-content"
|
||||
@ChatApiHandler.editMessage = sinon.stub().yields()
|
||||
@CommentsController.editMessage @req, @res
|
||||
|
||||
it "should ask the chat handler to edit the comment", ->
|
||||
@ChatApiHandler.editMessage
|
||||
.calledWith(@project_id, @thread_id, @message_id, @content)
|
||||
.should.equal true
|
||||
|
||||
it "should tell the client the comment was edited", ->
|
||||
@EditorRealTimeController.emitToRoom
|
||||
.calledWith(@project_id, "edit-message", @thread_id, @message_id, @content)
|
||||
.should.equal true
|
||||
|
||||
it "should return a success code", ->
|
||||
@res.send.calledWith(204).should.equal
|
||||
|
||||
describe "deleteMessage", ->
|
||||
beforeEach ->
|
||||
@req.params =
|
||||
project_id: @project_id = "mock-project-id"
|
||||
thread_id: @thread_id = "mock-thread-id"
|
||||
message_id: @message_id = "mock-thread-id"
|
||||
@ChatApiHandler.deleteMessage = sinon.stub().yields()
|
||||
@CommentsController.deleteMessage @req, @res
|
||||
|
||||
it "should ask the chat handler to deleted the message", ->
|
||||
@ChatApiHandler.deleteMessage
|
||||
.calledWith(@project_id, @thread_id, @message_id)
|
||||
.should.equal true
|
||||
|
||||
it "should tell the client the message was deleted", ->
|
||||
@EditorRealTimeController.emitToRoom
|
||||
.calledWith(@project_id, "delete-message", @thread_id, @message_id)
|
||||
.should.equal true
|
||||
|
||||
it "should return a success code", ->
|
||||
@res.send.calledWith(204).should.equal
|
||||
|
||||
describe "_injectUserInfoIntoThreads", ->
|
||||
beforeEach ->
|
||||
@users = {
|
||||
"user_id_1": {
|
||||
"mock": "user_1"
|
||||
}
|
||||
"user_id_2": {
|
||||
"mock": "user_2"
|
||||
}
|
||||
}
|
||||
@UserInfoManager.getPersonalInfo = (user_id, callback) =>
|
||||
return callback(null, @users[user_id])
|
||||
sinon.spy @UserInfoManager, "getPersonalInfo"
|
||||
@UserInfoController.formatPersonalInfo = (user) ->
|
||||
return { "formatted": user["mock"] }
|
||||
|
||||
it "should inject a user object into messaged and resolved data", (done) ->
|
||||
@CommentsController._injectUserInfoIntoThreads {
|
||||
thread1: {
|
||||
resolved: true
|
||||
resolved_by_user_id: "user_id_1"
|
||||
messages: [{
|
||||
user_id: "user_id_1"
|
||||
content: "foo"
|
||||
}, {
|
||||
user_id: "user_id_2"
|
||||
content: "bar"
|
||||
}]
|
||||
},
|
||||
thread2: {
|
||||
messages: [{
|
||||
user_id: "user_id_1"
|
||||
content: "baz"
|
||||
}]
|
||||
}
|
||||
}, (error, threads) ->
|
||||
expect(threads).to.deep.equal {
|
||||
thread1: {
|
||||
resolved: true
|
||||
resolved_by_user_id: "user_id_1"
|
||||
resolved_by_user: { "formatted": "user_1" }
|
||||
messages: [{
|
||||
user_id: "user_id_1"
|
||||
user: { "formatted": "user_1" }
|
||||
content: "foo"
|
||||
}, {
|
||||
user_id: "user_id_2"
|
||||
user: { "formatted": "user_2" }
|
||||
content: "bar"
|
||||
}]
|
||||
},
|
||||
thread2: {
|
||||
messages: [{
|
||||
user_id: "user_id_1"
|
||||
user: { "formatted": "user_1" }
|
||||
content: "baz"
|
||||
}]
|
||||
}
|
||||
}
|
||||
done()
|
||||
|
||||
it "should only need to look up each user once", (done) ->
|
||||
@CommentsController._injectUserInfoIntoThreads [{
|
||||
messages: [{
|
||||
user_id: "user_id_1"
|
||||
content: "foo"
|
||||
}, {
|
||||
user_id: "user_id_1"
|
||||
content: "bar"
|
||||
}]
|
||||
}], (error, threads) =>
|
||||
@UserInfoManager.getPersonalInfo.calledOnce.should.equal true
|
||||
done()
|
||||
@@ -17,8 +17,8 @@ describe "FileStoreHandler", ->
|
||||
@writeStream =
|
||||
my:"writeStream"
|
||||
on: (type, cb)->
|
||||
if type == "end"
|
||||
cb()
|
||||
if type == "response"
|
||||
cb({statusCode: 200})
|
||||
@readStream = {my:"readStream", on: sinon.stub()}
|
||||
@request = sinon.stub()
|
||||
@settings = apis:{filestore:{url:"http//filestore.sharelatex.test"}}
|
||||
@@ -79,6 +79,16 @@ describe "FileStoreHandler", ->
|
||||
@handler._buildUrl.calledWith(@project_id, @file_id).should.equal true
|
||||
done()
|
||||
|
||||
it 'should callback with null', (done) ->
|
||||
@fs.createReadStream.returns
|
||||
pipe:->
|
||||
on: (type, cb)->
|
||||
if type == "end"
|
||||
cb()
|
||||
@handler.uploadFileFromDisk @project_id, @file_id, @fsPath, (err) =>
|
||||
expect(err).to.not.exist
|
||||
done()
|
||||
|
||||
describe "symlink", ->
|
||||
it "should not read file if it is symlink", (done)->
|
||||
@isSafeOnFileSystem = false
|
||||
@@ -86,6 +96,23 @@ describe "FileStoreHandler", ->
|
||||
@fs.createReadStream.called.should.equal false
|
||||
done()
|
||||
|
||||
describe "when upload fails", ->
|
||||
beforeEach ->
|
||||
@writeStream.on = (type, cb) ->
|
||||
if type == "response"
|
||||
cb({statusCode: 500})
|
||||
|
||||
it 'should callback with an error', (done) ->
|
||||
@fs.createReadStream.returns
|
||||
pipe:->
|
||||
on: (type, cb)->
|
||||
if type == "end"
|
||||
cb()
|
||||
@handler.uploadFileFromDisk @project_id, @file_id, @fsPath, (err) =>
|
||||
expect(err).to.exist
|
||||
expect(err).to.be.instanceof Error
|
||||
done()
|
||||
|
||||
describe "deleteFile", ->
|
||||
|
||||
it "should send a delete request to filestore api", (done)->
|
||||
|
||||
@@ -13,7 +13,7 @@ describe "ProjectController", ->
|
||||
@project_id = "123213jlkj9kdlsaj"
|
||||
|
||||
@user =
|
||||
_id:"!£123213kjljkl"
|
||||
_id:"588f3ddae8ebc1bac07c9fa4"
|
||||
first_name: "bjkdsjfk"
|
||||
@settings =
|
||||
apis:
|
||||
@@ -302,7 +302,7 @@ describe "ProjectController", ->
|
||||
name:"my proj"
|
||||
_id:"213123kjlkj"
|
||||
@user =
|
||||
_id:"123kj21k3lj"
|
||||
_id: "588f3ddae8ebc1bac07c9fa4"
|
||||
ace:
|
||||
fontSize:"massive"
|
||||
theme:"sexy"
|
||||
@@ -381,3 +381,11 @@ describe "ProjectController", ->
|
||||
opts.showTrackChangesOnboarding.should.equal false
|
||||
done()
|
||||
@ProjectController.loadEditor @req, @res
|
||||
|
||||
it "should set showTrackChangesOnboarding = false if the user signed up after release", (done) ->
|
||||
@AuthenticationController.getLoggedInUserId.returns("58c11a608ba0d6e49e8ce5d5")
|
||||
@AnalyticsManager.getLastOccurance.yields(null, null)
|
||||
@res.render = (pageName, opts)=>
|
||||
opts.showTrackChangesOnboarding.should.equal false
|
||||
done()
|
||||
@ProjectController.loadEditor @req, @res
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
should = require('chai').should()
|
||||
SandboxedModule = require('sandboxed-module')
|
||||
assert = require('assert')
|
||||
sinon = require('sinon')
|
||||
path = require "path"
|
||||
modulePath = path.join __dirname, "../../../../app/js/Features/TrackChanges/RangesManager"
|
||||
expect = require("chai").expect
|
||||
|
||||
describe "RangesManager", ->
|
||||
beforeEach ->
|
||||
@RangesManager = SandboxedModule.require modulePath, requires:
|
||||
"../DocumentUpdater/DocumentUpdaterHandler": @DocumentUpdaterHandler = {}
|
||||
"../Docstore/DocstoreManager": @DocstoreManager = {}
|
||||
"../User/UserInfoManager": @UserInfoManager = {}
|
||||
|
||||
describe "getAllChangesUsers", ->
|
||||
beforeEach ->
|
||||
@project_id = "mock-project-id"
|
||||
@user_id1 = "mock-user-id-1"
|
||||
@user_id1 = "mock-user-id-2"
|
||||
@docs = [{
|
||||
ranges:
|
||||
changes: [{
|
||||
op: { i: "foo", p: 42 }
|
||||
metadata:
|
||||
user_id: @user_id1
|
||||
}, {
|
||||
op: { i: "bar", p: 102 }
|
||||
metadata:
|
||||
user_id: @user_id2
|
||||
}]
|
||||
}, {
|
||||
ranges:
|
||||
changes: [{
|
||||
op: { i: "baz", p: 3 }
|
||||
metadata:
|
||||
user_id: @user_id1
|
||||
}]
|
||||
}]
|
||||
@users = {}
|
||||
@users[@user_id1] = {"mock": "user-1"}
|
||||
@users[@user_id2] = {"mock": "user-2"}
|
||||
@UserInfoManager.getPersonalInfo = (user_id, callback) => callback null, @users[user_id]
|
||||
sinon.spy @UserInfoManager, "getPersonalInfo"
|
||||
@RangesManager.getAllRanges = sinon.stub().yields(null, @docs)
|
||||
|
||||
it "should return an array of unique users", (done) ->
|
||||
@RangesManager.getAllChangesUsers @project_id, (error, users) =>
|
||||
users.should.deep.equal [{"mock": "user-1"}, {"mock": "user-2"}]
|
||||
done()
|
||||
|
||||
it "should only call getPersonalInfo once for each user", (done) ->
|
||||
@RangesManager.getAllChangesUsers @project_id, (error, users) =>
|
||||
@UserInfoManager.getPersonalInfo.calledTwice.should.equal true
|
||||
done()
|
||||
Reference in New Issue
Block a user