overleaf/services/web/test/UnitTests/coffee/TrackChanges/RangesManagerTests.coffee

55 lines
1.7 KiB
CoffeeScript
Raw Normal View History

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"
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 = {}
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) ->
@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) ->
@RangesManager.getAllChangesUsers @project_id, (error, users) =>
2017-01-06 07:41:58 -05:00
@UserInfoManager.getPersonalInfo.calledTwice.should.equal true
done()