2020-06-23 13:30:34 -04:00
|
|
|
/* eslint-disable
|
|
|
|
no-unused-vars,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2020-06-23 13:30:29 -04:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS101: Remove unnecessary use of Array.from
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2021-03-18 16:19:31 -04:00
|
|
|
const { expect } = require('chai')
|
2020-06-23 13:30:45 -04:00
|
|
|
|
|
|
|
const RealTimeClient = require('./helpers/RealTimeClient')
|
|
|
|
const MockWebServer = require('./helpers/MockWebServer')
|
|
|
|
const FixturesManager = require('./helpers/FixturesManager')
|
|
|
|
|
|
|
|
const async = require('async')
|
|
|
|
|
|
|
|
describe('clientTracking', function () {
|
|
|
|
describe('when a client updates its cursor location', function () {
|
|
|
|
before(function (done) {
|
|
|
|
return async.series(
|
|
|
|
[
|
2021-07-13 07:04:45 -04:00
|
|
|
cb => {
|
2020-06-23 13:30:45 -04:00
|
|
|
return FixturesManager.setUpProject(
|
|
|
|
{
|
|
|
|
privilegeLevel: 'owner',
|
2021-07-13 07:04:45 -04:00
|
|
|
project: { name: 'Test Project' },
|
2020-06-23 13:30:45 -04:00
|
|
|
},
|
2023-03-20 10:10:40 -04:00
|
|
|
(error, { user_id: userId, project_id: projectId }) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (error) return done(error)
|
2023-03-20 10:10:40 -04:00
|
|
|
this.user_id = userId
|
|
|
|
this.project_id = projectId
|
2020-06-23 13:30:45 -04:00
|
|
|
return cb()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
},
|
|
|
|
|
2021-07-13 07:04:45 -04:00
|
|
|
cb => {
|
2020-06-23 13:30:45 -04:00
|
|
|
return FixturesManager.setUpDoc(
|
|
|
|
this.project_id,
|
|
|
|
{ lines: this.lines, version: this.version, ops: this.ops },
|
2023-03-20 10:10:40 -04:00
|
|
|
(e, { doc_id: docId }) => {
|
|
|
|
this.doc_id = docId
|
2020-06-23 13:30:45 -04:00
|
|
|
return cb(e)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
},
|
|
|
|
|
2021-07-13 07:04:45 -04:00
|
|
|
cb => {
|
2023-11-29 09:50:21 -05:00
|
|
|
this.clientA = RealTimeClient.connect(this.project_id, cb)
|
2020-06-23 13:30:45 -04:00
|
|
|
},
|
|
|
|
|
2021-07-13 07:04:45 -04:00
|
|
|
cb => {
|
2023-11-29 09:50:21 -05:00
|
|
|
this.clientB = RealTimeClient.connect(this.project_id, cb)
|
2020-06-23 13:30:45 -04:00
|
|
|
},
|
|
|
|
|
2021-07-13 07:04:45 -04:00
|
|
|
cb => {
|
2020-06-23 13:30:45 -04:00
|
|
|
return this.clientA.emit('joinDoc', this.doc_id, cb)
|
|
|
|
},
|
|
|
|
|
2021-07-13 07:04:45 -04:00
|
|
|
cb => {
|
2020-06-23 13:30:45 -04:00
|
|
|
this.updates = []
|
2021-07-13 07:04:45 -04:00
|
|
|
this.clientB.on('clientTracking.clientUpdated', data => {
|
2020-06-23 13:30:45 -04:00
|
|
|
return this.updates.push(data)
|
|
|
|
})
|
|
|
|
|
|
|
|
return this.clientA.emit(
|
|
|
|
'clientTracking.updatePosition',
|
|
|
|
{
|
|
|
|
row: (this.row = 42),
|
|
|
|
column: (this.column = 36),
|
2021-07-13 07:04:45 -04:00
|
|
|
doc_id: this.doc_id,
|
2020-06-23 13:30:45 -04:00
|
|
|
},
|
2021-07-13 07:04:45 -04:00
|
|
|
error => {
|
2020-06-23 13:30:45 -04:00
|
|
|
if (error != null) {
|
|
|
|
throw error
|
|
|
|
}
|
|
|
|
return setTimeout(cb, 300)
|
|
|
|
}
|
|
|
|
)
|
2021-07-13 07:04:45 -04:00
|
|
|
}, // Give the message a chance to reach client B.
|
2020-06-23 13:30:45 -04:00
|
|
|
],
|
|
|
|
done
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should tell other clients about the update', function () {
|
|
|
|
return this.updates.should.deep.equal([
|
|
|
|
{
|
|
|
|
row: this.row,
|
|
|
|
column: this.column,
|
|
|
|
doc_id: this.doc_id,
|
|
|
|
id: this.clientA.publicId,
|
|
|
|
user_id: this.user_id,
|
2021-07-13 07:04:45 -04:00
|
|
|
name: 'Joe Bloggs',
|
|
|
|
},
|
2020-06-23 13:30:45 -04:00
|
|
|
])
|
|
|
|
})
|
|
|
|
|
|
|
|
return it('should record the update in getConnectedUsers', function (done) {
|
|
|
|
return this.clientB.emit(
|
|
|
|
'clientTracking.getConnectedUsers',
|
|
|
|
(error, users) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (error) return done(error)
|
2020-06-23 13:30:45 -04:00
|
|
|
for (const user of Array.from(users)) {
|
|
|
|
if (user.client_id === this.clientA.publicId) {
|
|
|
|
expect(user.cursorData).to.deep.equal({
|
|
|
|
row: this.row,
|
|
|
|
column: this.column,
|
2021-07-13 07:04:45 -04:00
|
|
|
doc_id: this.doc_id,
|
2020-06-23 13:30:45 -04:00
|
|
|
})
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new Error('user was never found')
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
return describe('when an anonymous client updates its cursor location', function () {
|
|
|
|
before(function (done) {
|
|
|
|
return async.series(
|
|
|
|
[
|
2021-07-13 07:04:45 -04:00
|
|
|
cb => {
|
2020-06-23 13:30:45 -04:00
|
|
|
return FixturesManager.setUpProject(
|
|
|
|
{
|
|
|
|
privilegeLevel: 'owner',
|
|
|
|
project: { name: 'Test Project' },
|
2021-07-13 07:04:45 -04:00
|
|
|
publicAccess: 'readAndWrite',
|
2020-06-23 13:30:45 -04:00
|
|
|
},
|
2023-06-13 04:35:39 -04:00
|
|
|
(
|
|
|
|
error,
|
|
|
|
{ user_id: userId, project_id: projectId, anonymousAccessToken }
|
|
|
|
) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (error) return done(error)
|
2023-03-20 10:10:40 -04:00
|
|
|
this.user_id = userId
|
|
|
|
this.project_id = projectId
|
2023-06-13 04:35:39 -04:00
|
|
|
this.anonymousAccessToken = anonymousAccessToken
|
2020-06-23 13:30:45 -04:00
|
|
|
return cb()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
},
|
|
|
|
|
2021-07-13 07:04:45 -04:00
|
|
|
cb => {
|
2020-06-23 13:30:45 -04:00
|
|
|
return FixturesManager.setUpDoc(
|
|
|
|
this.project_id,
|
|
|
|
{ lines: this.lines, version: this.version, ops: this.ops },
|
2023-03-20 10:10:40 -04:00
|
|
|
(e, { doc_id: docId }) => {
|
|
|
|
this.doc_id = docId
|
2020-06-23 13:30:45 -04:00
|
|
|
return cb(e)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
},
|
|
|
|
|
2021-07-13 07:04:45 -04:00
|
|
|
cb => {
|
2023-11-29 09:50:21 -05:00
|
|
|
this.clientA = RealTimeClient.connect(this.project_id, cb)
|
2020-06-23 13:30:45 -04:00
|
|
|
},
|
|
|
|
|
2021-07-13 07:04:45 -04:00
|
|
|
cb => {
|
2023-11-29 09:50:21 -05:00
|
|
|
RealTimeClient.setAnonSession(
|
|
|
|
this.project_id,
|
|
|
|
this.anonymousAccessToken,
|
2020-06-23 13:30:45 -04:00
|
|
|
cb
|
|
|
|
)
|
|
|
|
},
|
|
|
|
|
2021-07-13 07:04:45 -04:00
|
|
|
cb => {
|
2023-11-29 09:50:21 -05:00
|
|
|
this.anonymous = RealTimeClient.connect(this.project_id, cb)
|
2020-06-23 13:30:45 -04:00
|
|
|
},
|
|
|
|
|
2021-07-13 07:04:45 -04:00
|
|
|
cb => {
|
2020-06-23 13:30:45 -04:00
|
|
|
return this.anonymous.emit('joinDoc', this.doc_id, cb)
|
|
|
|
},
|
|
|
|
|
2021-07-13 07:04:45 -04:00
|
|
|
cb => {
|
2020-06-23 13:30:45 -04:00
|
|
|
this.updates = []
|
2021-07-13 07:04:45 -04:00
|
|
|
this.clientA.on('clientTracking.clientUpdated', data => {
|
2020-06-23 13:30:45 -04:00
|
|
|
return this.updates.push(data)
|
|
|
|
})
|
|
|
|
|
|
|
|
return this.anonymous.emit(
|
|
|
|
'clientTracking.updatePosition',
|
|
|
|
{
|
|
|
|
row: (this.row = 42),
|
|
|
|
column: (this.column = 36),
|
2021-07-13 07:04:45 -04:00
|
|
|
doc_id: this.doc_id,
|
2020-06-23 13:30:45 -04:00
|
|
|
},
|
2021-07-13 07:04:45 -04:00
|
|
|
error => {
|
2020-06-23 13:30:45 -04:00
|
|
|
if (error != null) {
|
|
|
|
throw error
|
|
|
|
}
|
|
|
|
return setTimeout(cb, 300)
|
|
|
|
}
|
|
|
|
)
|
2021-07-13 07:04:45 -04:00
|
|
|
}, // Give the message a chance to reach client B.
|
2020-06-23 13:30:45 -04:00
|
|
|
],
|
|
|
|
done
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
return it('should tell other clients about the update', function () {
|
|
|
|
return this.updates.should.deep.equal([
|
|
|
|
{
|
|
|
|
row: this.row,
|
|
|
|
column: this.column,
|
|
|
|
doc_id: this.doc_id,
|
|
|
|
id: this.anonymous.publicId,
|
|
|
|
user_id: 'anonymous-user',
|
2021-07-13 07:04:45 -04:00
|
|
|
name: '',
|
|
|
|
},
|
2020-06-23 13:30:45 -04:00
|
|
|
])
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|