2020-05-06 06:11:22 -04:00
|
|
|
/* eslint-disable
|
|
|
|
no-return-assign,
|
|
|
|
no-unused-vars,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2020-05-06 06:10:51 -04:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS101: Remove unnecessary use of Array.from
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2020-05-06 06:11:36 -04:00
|
|
|
const sinon = require('sinon')
|
2021-04-01 15:51:00 -04:00
|
|
|
const { expect } = require('chai')
|
2020-05-06 06:11:36 -04:00
|
|
|
const modulePath = '../../../../app/js/RangesManager.js'
|
|
|
|
const SandboxedModule = require('sandboxed-module')
|
2017-03-15 10:12:06 -04:00
|
|
|
|
2020-05-06 06:11:36 -04:00
|
|
|
describe('RangesManager', function () {
|
|
|
|
beforeEach(function () {
|
2022-04-07 05:02:19 -04:00
|
|
|
this.RangesManager = SandboxedModule.require(modulePath, {
|
2023-05-23 04:10:44 -04:00
|
|
|
requires: {
|
|
|
|
'@overleaf/metrics': (this.Metrics = { histogram: sinon.stub() }),
|
|
|
|
},
|
2022-04-07 05:02:19 -04:00
|
|
|
})
|
2017-05-12 09:42:40 -04:00
|
|
|
|
2020-05-06 06:11:36 -04:00
|
|
|
this.doc_id = 'doc-id-123'
|
|
|
|
this.project_id = 'project-id-123'
|
|
|
|
this.user_id = 'user-id-123'
|
|
|
|
return (this.callback = sinon.stub())
|
|
|
|
})
|
2017-03-15 10:12:06 -04:00
|
|
|
|
2020-05-06 06:11:36 -04:00
|
|
|
describe('applyUpdate', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.updates = [
|
|
|
|
{
|
|
|
|
meta: {
|
2021-07-13 07:04:42 -04:00
|
|
|
user_id: this.user_id,
|
2020-05-06 06:11:36 -04:00
|
|
|
},
|
|
|
|
op: [
|
|
|
|
{
|
|
|
|
i: 'two ',
|
2021-07-13 07:04:42 -04:00
|
|
|
p: 4,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2020-05-06 06:11:36 -04:00
|
|
|
]
|
|
|
|
this.entries = {
|
|
|
|
comments: [
|
|
|
|
{
|
|
|
|
op: {
|
|
|
|
c: 'three ',
|
2021-07-13 07:04:42 -04:00
|
|
|
p: 4,
|
2020-05-06 06:11:36 -04:00
|
|
|
},
|
|
|
|
metadata: {
|
2021-07-13 07:04:42 -04:00
|
|
|
user_id: this.user_id,
|
|
|
|
},
|
|
|
|
},
|
2020-05-06 06:11:36 -04:00
|
|
|
],
|
|
|
|
changes: [
|
|
|
|
{
|
|
|
|
op: {
|
|
|
|
i: 'five',
|
2021-07-13 07:04:42 -04:00
|
|
|
p: 15,
|
2020-05-06 06:11:36 -04:00
|
|
|
},
|
|
|
|
metadata: {
|
2021-07-13 07:04:42 -04:00
|
|
|
user_id: this.user_id,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2020-05-06 06:11:36 -04:00
|
|
|
}
|
|
|
|
return (this.newDocLines = ['one two three four five'])
|
|
|
|
}) // old is "one three four five"
|
2017-05-09 11:16:25 -04:00
|
|
|
|
2020-05-06 06:11:36 -04:00
|
|
|
describe('successfully', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
return this.RangesManager.applyUpdate(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.entries,
|
|
|
|
this.updates,
|
|
|
|
this.newDocLines,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
2019-04-11 08:25:03 -04:00
|
|
|
|
2020-05-06 06:11:36 -04:00
|
|
|
return it('should return the modified the comments and changes', function () {
|
|
|
|
this.callback.called.should.equal(true)
|
2023-03-21 08:06:13 -04:00
|
|
|
const [error, entries, rangesWereCollapsed] = Array.from(
|
2020-05-06 06:11:36 -04:00
|
|
|
this.callback.args[0]
|
|
|
|
)
|
|
|
|
expect(error).to.be.null
|
2023-03-21 08:06:13 -04:00
|
|
|
expect(rangesWereCollapsed).to.equal(false)
|
2020-05-06 06:11:36 -04:00
|
|
|
entries.comments[0].op.should.deep.equal({
|
|
|
|
c: 'three ',
|
2021-07-13 07:04:42 -04:00
|
|
|
p: 8,
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
return entries.changes[0].op.should.deep.equal({
|
|
|
|
i: 'five',
|
2021-07-13 07:04:42 -04:00
|
|
|
p: 19,
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2019-04-11 08:25:03 -04:00
|
|
|
|
2020-05-06 06:11:36 -04:00
|
|
|
describe('with empty comments', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.entries.comments = []
|
|
|
|
return this.RangesManager.applyUpdate(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.entries,
|
|
|
|
this.updates,
|
|
|
|
this.newDocLines,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
2019-04-11 08:25:03 -04:00
|
|
|
|
2020-05-06 06:11:36 -04:00
|
|
|
return it('should return an object with no comments', function () {
|
|
|
|
// Save space in redis and don't store just {}
|
|
|
|
this.callback.called.should.equal(true)
|
|
|
|
const [error, entries] = Array.from(this.callback.args[0])
|
|
|
|
expect(error).to.be.null
|
|
|
|
return expect(entries.comments).to.be.undefined
|
|
|
|
})
|
|
|
|
})
|
2017-05-12 09:42:40 -04:00
|
|
|
|
2020-05-06 06:11:36 -04:00
|
|
|
describe('with empty changes', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.entries.changes = []
|
|
|
|
return this.RangesManager.applyUpdate(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.entries,
|
|
|
|
this.updates,
|
|
|
|
this.newDocLines,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
2017-05-09 11:16:25 -04:00
|
|
|
|
2020-05-06 06:11:36 -04:00
|
|
|
return it('should return an object with no changes', function () {
|
|
|
|
// Save space in redis and don't store just {}
|
|
|
|
this.callback.called.should.equal(true)
|
|
|
|
const [error, entries] = Array.from(this.callback.args[0])
|
|
|
|
expect(error).to.be.null
|
|
|
|
return expect(entries.changes).to.be.undefined
|
|
|
|
})
|
|
|
|
})
|
2017-05-09 11:16:25 -04:00
|
|
|
|
2020-05-06 06:11:36 -04:00
|
|
|
describe('with too many comments', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.RangesManager.MAX_COMMENTS = 2
|
|
|
|
this.updates = [
|
|
|
|
{
|
|
|
|
meta: {
|
2021-07-13 07:04:42 -04:00
|
|
|
user_id: this.user_id,
|
2020-05-06 06:11:36 -04:00
|
|
|
},
|
|
|
|
op: [
|
|
|
|
{
|
|
|
|
c: 'one',
|
|
|
|
p: 0,
|
2021-07-13 07:04:42 -04:00
|
|
|
t: 'thread-id-1',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2020-05-06 06:11:36 -04:00
|
|
|
]
|
|
|
|
this.entries = {
|
|
|
|
comments: [
|
|
|
|
{
|
|
|
|
op: {
|
|
|
|
c: 'three ',
|
|
|
|
p: 4,
|
2021-07-13 07:04:42 -04:00
|
|
|
t: 'thread-id-2',
|
2020-05-06 06:11:36 -04:00
|
|
|
},
|
|
|
|
metadata: {
|
2021-07-13 07:04:42 -04:00
|
|
|
user_id: this.user_id,
|
|
|
|
},
|
2020-05-06 06:11:36 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
op: {
|
|
|
|
c: 'four ',
|
|
|
|
p: 10,
|
2021-07-13 07:04:42 -04:00
|
|
|
t: 'thread-id-3',
|
2020-05-06 06:11:36 -04:00
|
|
|
},
|
|
|
|
metadata: {
|
2021-07-13 07:04:42 -04:00
|
|
|
user_id: this.user_id,
|
|
|
|
},
|
|
|
|
},
|
2020-05-06 06:11:36 -04:00
|
|
|
],
|
2021-07-13 07:04:42 -04:00
|
|
|
changes: [],
|
2020-05-06 06:11:36 -04:00
|
|
|
}
|
|
|
|
return this.RangesManager.applyUpdate(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.entries,
|
|
|
|
this.updates,
|
|
|
|
this.newDocLines,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
2017-05-09 11:16:25 -04:00
|
|
|
|
2020-05-06 06:11:36 -04:00
|
|
|
return it('should return an error', function () {
|
|
|
|
this.callback.called.should.equal(true)
|
|
|
|
const [error, entries] = Array.from(this.callback.args[0])
|
|
|
|
expect(error).to.not.be.null
|
|
|
|
return expect(error.message).to.equal(
|
|
|
|
'too many comments or tracked changes'
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
2017-05-12 09:42:40 -04:00
|
|
|
|
2020-05-06 06:11:36 -04:00
|
|
|
describe('with too many changes', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.RangesManager.MAX_CHANGES = 2
|
|
|
|
this.updates = [
|
|
|
|
{
|
|
|
|
meta: {
|
|
|
|
user_id: this.user_id,
|
2021-07-13 07:04:42 -04:00
|
|
|
tc: 'track-changes-id-yes',
|
2020-05-06 06:11:36 -04:00
|
|
|
},
|
|
|
|
op: [
|
|
|
|
{
|
|
|
|
i: 'one ',
|
2021-07-13 07:04:42 -04:00
|
|
|
p: 0,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2020-05-06 06:11:36 -04:00
|
|
|
]
|
|
|
|
this.entries = {
|
|
|
|
changes: [
|
|
|
|
{
|
|
|
|
op: {
|
|
|
|
i: 'three',
|
2021-07-13 07:04:42 -04:00
|
|
|
p: 4,
|
2020-05-06 06:11:36 -04:00
|
|
|
},
|
|
|
|
metadata: {
|
2021-07-13 07:04:42 -04:00
|
|
|
user_id: this.user_id,
|
|
|
|
},
|
2020-05-06 06:11:36 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
op: {
|
|
|
|
i: 'four',
|
2021-07-13 07:04:42 -04:00
|
|
|
p: 10,
|
2020-05-06 06:11:36 -04:00
|
|
|
},
|
|
|
|
metadata: {
|
2021-07-13 07:04:42 -04:00
|
|
|
user_id: this.user_id,
|
|
|
|
},
|
|
|
|
},
|
2020-05-06 06:11:36 -04:00
|
|
|
],
|
2021-07-13 07:04:42 -04:00
|
|
|
comments: [],
|
2020-05-06 06:11:36 -04:00
|
|
|
}
|
|
|
|
this.newDocLines = ['one two three four']
|
|
|
|
return this.RangesManager.applyUpdate(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.entries,
|
|
|
|
this.updates,
|
|
|
|
this.newDocLines,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
2017-05-12 09:42:40 -04:00
|
|
|
|
2020-05-06 06:11:36 -04:00
|
|
|
return it('should return an error', function () {
|
|
|
|
// Save space in redis and don't store just {}
|
|
|
|
this.callback.called.should.equal(true)
|
|
|
|
const [error, entries] = Array.from(this.callback.args[0])
|
|
|
|
expect(error).to.not.be.null
|
|
|
|
return expect(error.message).to.equal(
|
|
|
|
'too many comments or tracked changes'
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
2017-05-12 09:42:40 -04:00
|
|
|
|
2020-05-06 06:11:36 -04:00
|
|
|
describe('inconsistent changes', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.updates = [
|
|
|
|
{
|
|
|
|
meta: {
|
2021-07-13 07:04:42 -04:00
|
|
|
user_id: this.user_id,
|
2020-05-06 06:11:36 -04:00
|
|
|
},
|
|
|
|
op: [
|
|
|
|
{
|
|
|
|
c: "doesn't match",
|
2021-07-13 07:04:42 -04:00
|
|
|
p: 0,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2020-05-06 06:11:36 -04:00
|
|
|
]
|
|
|
|
return this.RangesManager.applyUpdate(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.entries,
|
|
|
|
this.updates,
|
|
|
|
this.newDocLines,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
2017-05-09 11:16:25 -04:00
|
|
|
|
2020-05-06 06:11:36 -04:00
|
|
|
return it('should return an error', function () {
|
|
|
|
// Save space in redis and don't store just {}
|
|
|
|
this.callback.called.should.equal(true)
|
|
|
|
const [error, entries] = Array.from(this.callback.args[0])
|
|
|
|
expect(error).to.not.be.null
|
|
|
|
return expect(error.message).to.equal(
|
|
|
|
'Change ({"op":{"i":"five","p":15},"metadata":{"user_id":"user-id-123"}}) doesn\'t match text ("our ")'
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
2017-05-12 09:42:40 -04:00
|
|
|
|
2022-04-07 05:02:19 -04:00
|
|
|
describe('with an update that collapses a range', function () {
|
2020-05-06 06:11:36 -04:00
|
|
|
beforeEach(function () {
|
|
|
|
this.updates = [
|
|
|
|
{
|
|
|
|
meta: {
|
2021-07-13 07:04:42 -04:00
|
|
|
user_id: this.user_id,
|
2020-05-06 06:11:36 -04:00
|
|
|
},
|
|
|
|
op: [
|
|
|
|
{
|
|
|
|
d: 'one',
|
|
|
|
p: 0,
|
2021-07-13 07:04:42 -04:00
|
|
|
t: 'thread-id-1',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2020-05-06 06:11:36 -04:00
|
|
|
]
|
|
|
|
this.entries = {
|
|
|
|
comments: [
|
|
|
|
{
|
|
|
|
op: {
|
|
|
|
c: 'n',
|
|
|
|
p: 1,
|
2021-07-13 07:04:42 -04:00
|
|
|
t: 'thread-id-2',
|
2020-05-06 06:11:36 -04:00
|
|
|
},
|
|
|
|
metadata: {
|
2021-07-13 07:04:42 -04:00
|
|
|
user_id: this.user_id,
|
|
|
|
},
|
|
|
|
},
|
2020-05-06 06:11:36 -04:00
|
|
|
],
|
2021-07-13 07:04:42 -04:00
|
|
|
changes: [],
|
2020-05-06 06:11:36 -04:00
|
|
|
}
|
|
|
|
return this.RangesManager.applyUpdate(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.entries,
|
|
|
|
this.updates,
|
|
|
|
this.newDocLines,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
2017-05-12 09:42:40 -04:00
|
|
|
|
2020-05-06 06:11:36 -04:00
|
|
|
return it('should return ranges_were_collapsed == true', function () {
|
|
|
|
this.callback.called.should.equal(true)
|
2023-03-21 08:06:13 -04:00
|
|
|
const [error, entries, rangesWereCollapsed] = Array.from(
|
2020-05-06 06:11:36 -04:00
|
|
|
this.callback.args[0]
|
|
|
|
)
|
2023-03-21 08:06:13 -04:00
|
|
|
return expect(rangesWereCollapsed).to.equal(true)
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
})
|
2022-04-07 05:02:19 -04:00
|
|
|
|
|
|
|
describe('with an update that deletes ranges', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.updates = [
|
|
|
|
{
|
|
|
|
meta: {
|
|
|
|
user_id: this.user_id,
|
|
|
|
},
|
|
|
|
op: [
|
|
|
|
{
|
|
|
|
d: 'one two three four five',
|
|
|
|
p: 0,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
]
|
|
|
|
this.entries = {
|
|
|
|
comments: [
|
|
|
|
{
|
|
|
|
op: {
|
|
|
|
c: 'n',
|
|
|
|
p: 1,
|
|
|
|
t: 'thread-id-2',
|
|
|
|
},
|
|
|
|
metadata: {
|
|
|
|
user_id: this.user_id,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
changes: [
|
|
|
|
{
|
|
|
|
op: {
|
|
|
|
i: 'hello',
|
|
|
|
p: 1,
|
|
|
|
t: 'thread-id-2',
|
|
|
|
},
|
|
|
|
metadata: {
|
|
|
|
user_id: this.user_id,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}
|
|
|
|
return this.RangesManager.applyUpdate(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.entries,
|
|
|
|
this.updates,
|
|
|
|
this.newDocLines,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should increment the range-delta histogram', function () {
|
|
|
|
this.Metrics.histogram.called.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
return it('should return ranges_were_collapsed == true', function () {
|
|
|
|
this.callback.called.should.equal(true)
|
2023-03-21 08:06:13 -04:00
|
|
|
const [error, entries, rangesWereCollapsed] = Array.from(
|
2022-04-07 05:02:19 -04:00
|
|
|
this.callback.args[0]
|
|
|
|
)
|
2023-03-21 08:06:13 -04:00
|
|
|
return expect(rangesWereCollapsed).to.equal(true)
|
2022-04-07 05:02:19 -04:00
|
|
|
})
|
|
|
|
})
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
2017-05-12 09:42:40 -04:00
|
|
|
|
2020-05-06 06:11:36 -04:00
|
|
|
return describe('acceptChanges', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.RangesManager = SandboxedModule.require(modulePath, {
|
|
|
|
requires: {
|
2022-10-05 08:17:32 -04:00
|
|
|
'@overleaf/ranges-tracker': (this.RangesTracker =
|
|
|
|
SandboxedModule.require('@overleaf/ranges-tracker')),
|
2023-05-23 04:10:44 -04:00
|
|
|
'@overleaf/metrics': {},
|
2021-07-13 07:04:42 -04:00
|
|
|
},
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
this.ranges = {
|
|
|
|
comments: [],
|
|
|
|
changes: [
|
|
|
|
{
|
|
|
|
id: 'a1',
|
|
|
|
op: {
|
|
|
|
i: 'lorem',
|
2021-07-13 07:04:42 -04:00
|
|
|
p: 0,
|
|
|
|
},
|
2020-05-06 06:11:36 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'a2',
|
|
|
|
op: {
|
|
|
|
i: 'ipsum',
|
2021-07-13 07:04:42 -04:00
|
|
|
p: 10,
|
|
|
|
},
|
2020-05-06 06:11:36 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'a3',
|
|
|
|
op: {
|
|
|
|
i: 'dolor',
|
2021-07-13 07:04:42 -04:00
|
|
|
p: 20,
|
|
|
|
},
|
2020-05-06 06:11:36 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'a4',
|
|
|
|
op: {
|
|
|
|
i: 'sit',
|
2021-07-13 07:04:42 -04:00
|
|
|
p: 30,
|
|
|
|
},
|
2020-05-06 06:11:36 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'a5',
|
|
|
|
op: {
|
|
|
|
i: 'amet',
|
2021-07-13 07:04:42 -04:00
|
|
|
p: 40,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2020-05-06 06:11:36 -04:00
|
|
|
}
|
|
|
|
return (this.removeChangeIdsSpy = sinon.spy(
|
|
|
|
this.RangesTracker.prototype,
|
|
|
|
'removeChangeIds'
|
|
|
|
))
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('successfully with a single change', function () {
|
|
|
|
beforeEach(function (done) {
|
|
|
|
this.change_ids = [this.ranges.changes[1].id]
|
|
|
|
return this.RangesManager.acceptChanges(
|
|
|
|
this.change_ids,
|
|
|
|
this.ranges,
|
|
|
|
(err, ranges) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (err) return done(err)
|
2020-05-06 06:11:36 -04:00
|
|
|
this.rangesResponse = ranges
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should log the call with the correct number of changes', function () {
|
2021-09-30 04:28:32 -04:00
|
|
|
return this.logger.debug
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith('accepting 1 changes in ranges')
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should delegate the change removal to the ranges tracker', function () {
|
|
|
|
return this.removeChangeIdsSpy
|
|
|
|
.calledWith(this.change_ids)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should remove the change', function () {
|
|
|
|
return expect(
|
|
|
|
this.rangesResponse.changes.find(
|
2021-07-13 07:04:42 -04:00
|
|
|
change => change.id === this.ranges.changes[1].id
|
2020-05-06 06:11:36 -04:00
|
|
|
)
|
|
|
|
).to.be.undefined
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should return the original number of changes minus 1', function () {
|
|
|
|
return this.rangesResponse.changes.length.should.equal(
|
|
|
|
this.ranges.changes.length - 1
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
return it('should not touch other changes', function () {
|
2021-07-13 07:04:42 -04:00
|
|
|
return [0, 2, 3, 4].map(i =>
|
2020-05-06 06:11:36 -04:00
|
|
|
expect(
|
|
|
|
this.rangesResponse.changes.find(
|
2021-07-13 07:04:42 -04:00
|
|
|
change => change.id === this.ranges.changes[i].id
|
2020-05-06 06:11:36 -04:00
|
|
|
)
|
|
|
|
).to.deep.equal(this.ranges.changes[i])
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
return describe('successfully with multiple changes', function () {
|
|
|
|
beforeEach(function (done) {
|
|
|
|
this.change_ids = [
|
|
|
|
this.ranges.changes[1].id,
|
|
|
|
this.ranges.changes[3].id,
|
2021-07-13 07:04:42 -04:00
|
|
|
this.ranges.changes[4].id,
|
2020-05-06 06:11:36 -04:00
|
|
|
]
|
|
|
|
return this.RangesManager.acceptChanges(
|
|
|
|
this.change_ids,
|
|
|
|
this.ranges,
|
|
|
|
(err, ranges) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (err) return done(err)
|
2020-05-06 06:11:36 -04:00
|
|
|
this.rangesResponse = ranges
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should log the call with the correct number of changes', function () {
|
2021-09-30 04:28:32 -04:00
|
|
|
return this.logger.debug
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(`accepting ${this.change_ids.length} changes in ranges`)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should delegate the change removal to the ranges tracker', function () {
|
|
|
|
return this.removeChangeIdsSpy
|
|
|
|
.calledWith(this.change_ids)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should remove the changes', function () {
|
|
|
|
return [1, 3, 4].map(
|
2021-07-13 07:04:42 -04:00
|
|
|
i =>
|
2020-05-06 06:11:36 -04:00
|
|
|
expect(
|
|
|
|
this.rangesResponse.changes.find(
|
2021-07-13 07:04:42 -04:00
|
|
|
change => change.id === this.ranges.changes[1].id
|
2020-05-06 06:11:36 -04:00
|
|
|
)
|
|
|
|
).to.be.undefined
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should return the original number of changes minus the number of accepted changes', function () {
|
|
|
|
return this.rangesResponse.changes.length.should.equal(
|
|
|
|
this.ranges.changes.length - 3
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
return it('should not touch other changes', function () {
|
2021-07-13 07:04:42 -04:00
|
|
|
return [0, 2].map(i =>
|
2020-05-06 06:11:36 -04:00
|
|
|
expect(
|
|
|
|
this.rangesResponse.changes.find(
|
2021-07-13 07:04:42 -04:00
|
|
|
change => change.id === this.ranges.changes[i].id
|
2020-05-06 06:11:36 -04:00
|
|
|
)
|
|
|
|
).to.deep.equal(this.ranges.changes[i])
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|