2017-01-06 07:41:58 -05:00
|
|
|
should = require('chai').should()
|
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
|
assert = require('assert')
|
|
|
|
sinon = require('sinon')
|
|
|
|
path = require "path"
|
2017-01-10 07:43:53 -05:00
|
|
|
modulePath = path.join __dirname, "../../../../app/js/Features/TrackChanges/RangesManager"
|
2017-01-06 07:41:58 -05:00
|
|
|
expect = require("chai").expect
|
|
|
|
|
|
|
|
describe "RangesManager", ->
|
|
|
|
beforeEach ->
|
|
|
|
@RangesManager = SandboxedModule.require modulePath, requires:
|
|
|
|
"../DocumentUpdater/DocumentUpdaterHandler": @DocumentUpdaterHandler = {}
|
|
|
|
"../Docstore/DocstoreManager": @DocstoreManager = {}
|
|
|
|
"../User/UserInfoManager": @UserInfoManager = {}
|
|
|
|
|
2017-01-10 07:43:53 -05:00
|
|
|
describe "getAllChangesUsers", ->
|
2017-01-06 07:41:58 -05:00
|
|
|
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) ->
|
2017-01-10 07:43:53 -05:00
|
|
|
@RangesManager.getAllChangesUsers @project_id, (error, users) =>
|
2017-01-06 07:41:58 -05:00
|
|
|
users.should.deep.equal [{"mock": "user-1"}, {"mock": "user-2"}]
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should only call getPersonalInfo once for each user", (done) ->
|
2017-01-10 07:43:53 -05:00
|
|
|
@RangesManager.getAllChangesUsers @project_id, (error, users) =>
|
2017-01-06 07:41:58 -05:00
|
|
|
@UserInfoManager.getPersonalInfo.calledTwice.should.equal true
|
|
|
|
done()
|