|
@@ -41,6 +41,9 @@ describe('receiveEditorEvent', function () {
|
|
|
this.user_b_id = null
|
|
this.user_b_id = null
|
|
|
this.user_b_client = null
|
|
this.user_b_client = null
|
|
|
|
|
|
|
|
|
|
+ this.user_c_id = null
|
|
|
|
|
+ this.user_c_client = null
|
|
|
|
|
+
|
|
|
async.series(
|
|
async.series(
|
|
|
[
|
|
[
|
|
|
/**
|
|
/**
|
|
@@ -51,6 +54,7 @@ describe('receiveEditorEvent', function () {
|
|
|
{
|
|
{
|
|
|
privilegeLevel: 'owner',
|
|
privilegeLevel: 'owner',
|
|
|
project: { name: 'Test Project' },
|
|
project: { name: 'Test Project' },
|
|
|
|
|
+ userMetadata: { isInvitedMember: true },
|
|
|
},
|
|
},
|
|
|
(error, { user_id: userId, project_id: projectId }) => {
|
|
(error, { user_id: userId, project_id: projectId }) => {
|
|
|
if (error) return done(error)
|
|
if (error) return done(error)
|
|
@@ -95,13 +99,14 @@ describe('receiveEditorEvent', function () {
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * add user_a to project
|
|
|
|
|
|
|
+ * add user_a to project, as an invited member
|
|
|
*/
|
|
*/
|
|
|
cb => {
|
|
cb => {
|
|
|
return FixturesManager.setUpProject(
|
|
return FixturesManager.setUpProject(
|
|
|
{
|
|
{
|
|
|
privilegeLevel: 'readAndWrite',
|
|
privilegeLevel: 'readAndWrite',
|
|
|
project_id: this.project_id,
|
|
project_id: this.project_id,
|
|
|
|
|
+ userMetadata: { isTokenMember: false, isInvitedMember: true },
|
|
|
},
|
|
},
|
|
|
(error, { user_id: userIdSecond }) => {
|
|
(error, { user_id: userIdSecond }) => {
|
|
|
if (error) return done(error)
|
|
if (error) return done(error)
|
|
@@ -133,13 +138,14 @@ describe('receiveEditorEvent', function () {
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * Set up user_b
|
|
|
|
|
|
|
+ * Set up user_b, as a token-access/link-sharing user
|
|
|
*/
|
|
*/
|
|
|
cb => {
|
|
cb => {
|
|
|
return FixturesManager.setUpProject(
|
|
return FixturesManager.setUpProject(
|
|
|
{
|
|
{
|
|
|
privilegeLevel: 'readAndWrite',
|
|
privilegeLevel: 'readAndWrite',
|
|
|
project_id: this.project_id,
|
|
project_id: this.project_id,
|
|
|
|
|
+ userMetadata: { isTokenMember: true, isInvitedMember: false },
|
|
|
},
|
|
},
|
|
|
(error, { user_id: userIdThird }) => {
|
|
(error, { user_id: userIdThird }) => {
|
|
|
if (error) return done(error)
|
|
if (error) return done(error)
|
|
@@ -170,23 +176,81 @@ describe('receiveEditorEvent', function () {
|
|
|
return this.user_b_client.emit('joinDoc', this.doc_id, cb)
|
|
return this.user_b_client.emit('joinDoc', this.doc_id, cb)
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Set up user_c, as a 'restricted' user (anonymous read-only link-sharing)
|
|
|
|
|
+ */
|
|
|
|
|
+ cb => {
|
|
|
|
|
+ return FixturesManager.setUpProject(
|
|
|
|
|
+ {
|
|
|
|
|
+ privilegeLevel: 'readAndWrite',
|
|
|
|
|
+ project_id: this.project_id,
|
|
|
|
|
+ userMetadata: {
|
|
|
|
|
+ isTokenMember: false,
|
|
|
|
|
+ isInvitedMember: false,
|
|
|
|
|
+ isRestrictedUser: true,
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ (error, { user_id: userIdFourth }) => {
|
|
|
|
|
+ if (error) return done(error)
|
|
|
|
|
+ this.user_c_id = userIdFourth
|
|
|
|
|
+ return cb()
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Connect user_c to project/doc
|
|
|
|
|
+ */
|
|
|
|
|
+ cb => {
|
|
|
|
|
+ this.user_c_client = RealTimeClient.connect()
|
|
|
|
|
+ return this.user_c_client.on('connectionAccepted', cb)
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ cb => {
|
|
|
|
|
+ return this.user_c_client.emit(
|
|
|
|
|
+ 'joinProject',
|
|
|
|
|
+ {
|
|
|
|
|
+ project_id: this.project_id,
|
|
|
|
|
+ },
|
|
|
|
|
+ cb
|
|
|
|
|
+ )
|
|
|
|
|
+ },
|
|
|
|
|
+ cb => {
|
|
|
|
|
+ return this.user_c_client.emit('joinDoc', this.doc_id, cb)
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ // --------------
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Listen for updates
|
|
* Listen for updates
|
|
|
*/
|
|
*/
|
|
|
cb => {
|
|
cb => {
|
|
|
- const eventName = 'userRemovedFromProject'
|
|
|
|
|
this.owner_updates = []
|
|
this.owner_updates = []
|
|
|
- this.owner_client.on(eventName, update =>
|
|
|
|
|
- this.owner_updates.push({ [eventName]: update })
|
|
|
|
|
- )
|
|
|
|
|
this.user_a_updates = []
|
|
this.user_a_updates = []
|
|
|
- this.user_a_client.on(eventName, update =>
|
|
|
|
|
- this.user_a_updates.push({ [eventName]: update })
|
|
|
|
|
- )
|
|
|
|
|
this.user_b_updates = []
|
|
this.user_b_updates = []
|
|
|
- this.user_b_client.on(eventName, update =>
|
|
|
|
|
- this.user_b_updates.push({ [eventName]: update })
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ this.user_c_updates = []
|
|
|
|
|
+
|
|
|
|
|
+ const eventNames = [
|
|
|
|
|
+ 'userRemovedFromProject',
|
|
|
|
|
+ 'project:publicAccessLevel:changed',
|
|
|
|
|
+ 'project:access:revoked',
|
|
|
|
|
+ ]
|
|
|
|
|
+
|
|
|
|
|
+ for (const eventName of eventNames) {
|
|
|
|
|
+ this.owner_client.on(eventName, update =>
|
|
|
|
|
+ this.owner_updates.push({ [eventName]: update })
|
|
|
|
|
+ )
|
|
|
|
|
+ this.user_a_client.on(eventName, update =>
|
|
|
|
|
+ this.user_a_updates.push({ [eventName]: update })
|
|
|
|
|
+ )
|
|
|
|
|
+ this.user_b_client.on(eventName, update =>
|
|
|
|
|
+ this.user_b_updates.push({ [eventName]: update })
|
|
|
|
|
+ )
|
|
|
|
|
+ this.user_c_client.on(eventName, update =>
|
|
|
|
|
+ this.user_c_updates.push({ [eventName]: update })
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return cb()
|
|
return cb()
|
|
|
},
|
|
},
|
|
|
],
|
|
],
|
|
@@ -204,6 +268,101 @@ describe('receiveEditorEvent', function () {
|
|
|
if (this.user_b_client) {
|
|
if (this.user_b_client) {
|
|
|
this.user_b_client.disconnect()
|
|
this.user_b_client.disconnect()
|
|
|
}
|
|
}
|
|
|
|
|
+ if (this.user_c_client) {
|
|
|
|
|
+ this.user_c_client.disconnect()
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ describe('event: project:publicAccessLevel:changed, set to private', function () {
|
|
|
|
|
+ beforeEach(function (done) {
|
|
|
|
|
+ /**
|
|
|
|
|
+ * We turn off link sharing
|
|
|
|
|
+ */
|
|
|
|
|
+ rclient.publish(
|
|
|
|
|
+ 'editor-events',
|
|
|
|
|
+ JSON.stringify({
|
|
|
|
|
+ room_id: this.project_id,
|
|
|
|
|
+ message: 'project:publicAccessLevel:changed',
|
|
|
|
|
+ payload: [{ newAccessLevel: 'private' }],
|
|
|
|
|
+ })
|
|
|
|
|
+ )
|
|
|
|
|
+ setTimeout(done, 200)
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('should disconnect the token-access user, and restricted users', function () {
|
|
|
|
|
+ expect(this.user_b_client.socket.connected).to.equal(false)
|
|
|
|
|
+ expect(this.user_c_client.socket.connected).to.equal(false)
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('should not disconnect the other users', function () {
|
|
|
|
|
+ expect(this.owner_client.socket.connected).to.equal(true)
|
|
|
|
|
+ expect(this.user_a_client.socket.connected).to.equal(true)
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('should send the event to the remaining connected clients', function () {
|
|
|
|
|
+ expect(this.owner_updates).to.deep.equal([
|
|
|
|
|
+ { 'project:publicAccessLevel:changed': { newAccessLevel: 'private' } },
|
|
|
|
|
+ ])
|
|
|
|
|
+
|
|
|
|
|
+ expect(this.user_a_updates).to.deep.equal([
|
|
|
|
|
+ { 'project:publicAccessLevel:changed': { newAccessLevel: 'private' } },
|
|
|
|
|
+ ])
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('should send a project:access:revoked message to the disconnected clients', function () {
|
|
|
|
|
+ expect(this.user_b_updates).to.deep.equal([
|
|
|
|
|
+ { 'project:access:revoked': undefined },
|
|
|
|
|
+ ])
|
|
|
|
|
+ expect(this.user_c_updates).to.deep.equal([
|
|
|
|
|
+ { 'project:access:revoked': undefined },
|
|
|
|
|
+ ])
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ describe('event: project:publicAccessLevel:changed, set to tokenBased', function () {
|
|
|
|
|
+ beforeEach(function (done) {
|
|
|
|
|
+ /**
|
|
|
|
|
+ * We turn on link sharing
|
|
|
|
|
+ */
|
|
|
|
|
+ rclient.publish(
|
|
|
|
|
+ 'editor-events',
|
|
|
|
|
+ JSON.stringify({
|
|
|
|
|
+ room_id: this.project_id,
|
|
|
|
|
+ message: 'project:publicAccessLevel:changed',
|
|
|
|
|
+ payload: [{ newAccessLevel: 'tokenBased' }],
|
|
|
|
|
+ })
|
|
|
|
|
+ )
|
|
|
|
|
+ setTimeout(done, 200)
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('should not disconnect anyone', function () {
|
|
|
|
|
+ expect(this.owner_client.socket.connected).to.equal(true)
|
|
|
|
|
+ expect(this.user_a_client.socket.connected).to.equal(true)
|
|
|
|
|
+ expect(this.user_b_client.socket.connected).to.equal(true)
|
|
|
|
|
+ expect(this.user_c_client.socket.connected).to.equal(true)
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('should send the event to all non-restricted clients', function () {
|
|
|
|
|
+ expect(this.owner_updates).to.deep.equal([
|
|
|
|
|
+ {
|
|
|
|
|
+ 'project:publicAccessLevel:changed': { newAccessLevel: 'tokenBased' },
|
|
|
|
|
+ },
|
|
|
|
|
+ ])
|
|
|
|
|
+
|
|
|
|
|
+ expect(this.user_a_updates).to.deep.equal([
|
|
|
|
|
+ {
|
|
|
|
|
+ 'project:publicAccessLevel:changed': { newAccessLevel: 'tokenBased' },
|
|
|
|
|
+ },
|
|
|
|
|
+ ])
|
|
|
|
|
+
|
|
|
|
|
+ expect(this.user_b_updates).to.deep.equal([
|
|
|
|
|
+ {
|
|
|
|
|
+ 'project:publicAccessLevel:changed': { newAccessLevel: 'tokenBased' },
|
|
|
|
|
+ },
|
|
|
|
|
+ ])
|
|
|
|
|
+ // restricted users don't receive this type of message
|
|
|
|
|
+ expect(this.user_c_updates.length).to.equal(0)
|
|
|
|
|
+ })
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
describe('event: userRemovedFromProject', function () {
|
|
describe('event: userRemovedFromProject', function () {
|
|
@@ -238,11 +397,15 @@ describe('receiveEditorEvent', function () {
|
|
|
{ userRemovedFromProject: removedUserId },
|
|
{ userRemovedFromProject: removedUserId },
|
|
|
])
|
|
])
|
|
|
|
|
|
|
|
- expect(this.user_a_updates.length).to.equal(0)
|
|
|
|
|
-
|
|
|
|
|
expect(this.user_b_updates).to.deep.equal([
|
|
expect(this.user_b_updates).to.deep.equal([
|
|
|
{ userRemovedFromProject: removedUserId },
|
|
{ userRemovedFromProject: removedUserId },
|
|
|
])
|
|
])
|
|
|
})
|
|
})
|
|
|
|
|
+
|
|
|
|
|
+ it('should send a project:access:revoked message to the disconnected clients', function () {
|
|
|
|
|
+ expect(this.user_a_updates).to.deep.equal([
|
|
|
|
|
+ { 'project:access:revoked': undefined },
|
|
|
|
|
+ ])
|
|
|
|
|
+ })
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|