fix(subs): replaces permission subs with created/deleted + sharedBy/revokedBy props

This commit is contained in:
Dimitrie Stefanescu
2020-09-01 11:46:38 +01:00
parent 11571a1d76
commit 690d95bfde
3 changed files with 286 additions and 310 deletions
+11 -24
View File
@@ -51,6 +51,7 @@ module.exports = {
}
},
Stream: {
async collaborators( parent, args, context, info ) {
@@ -59,6 +60,7 @@ module.exports = {
}
},
User: {
async streams( parent, args, context, info ) {
@@ -73,6 +75,7 @@ module.exports = {
}
},
Mutation: {
async streamCreate( parent, args, context, info ) {
@@ -123,11 +126,7 @@ module.exports = {
let granted = await grantPermissionsStream( params )
if ( granted ) {
await pubsub.publish( STREAM_PERMISSION_GRANTED, {
streamPermissionGranted: { ...params, grantor: context.userId },
userId: params.userId,
streamId: params.streamId
} )
await pubsub.publish( USER_STREAM_CREATED, { userStreamCreated: { id: args.permissionParams.streamId, sharedBy: context.userId }, ownerId: args.permissionParams.userId } )
}
return granted
@@ -138,17 +137,19 @@ module.exports = {
let revoked = await revokePermissionsStream( { ...args.permissionParams } )
if ( revoked ) {
await pubsub.publish( STREAM_PERMISSION_REVOKED, {
streamPermissionRevoked: { ...args.permissionParams },
userId: args.permissionParams.userId,
streamId: args.permissionParams.streamId
} )
await pubsub.publish( USER_STREAM_DELETED, { userStreamDeleted: { streamId: args.permissionParams.streamId, revokedBy: context.userId }, ownerId: args.permissionParams.userId } )
// await pubsub.publish( USER_STREAM_DELETED, {
// userStreamPermissionRevoked: { ...args.permissionParams },
// userId: args.permissionParams.userId,
// streamId: args.permissionParams.streamId
// } )
}
return revoked
}
},
Subscription: {
userStreamCreated: {
@@ -181,19 +182,5 @@ module.exports = {
return payload.streamId === variables.streamId
} )
},
streamPermissionGranted: {
subscribe: withFilter( ( ) => pubsub.asyncIterator( [ STREAM_PERMISSION_GRANTED ] ),
( payload, variables ) => {
return payload.userId === variables.userId
} )
},
streamPermissionRevoked: {
subscribe: withFilter( ( ) => pubsub.asyncIterator( [ STREAM_PERMISSION_REVOKED ] ),
( payload, variables ) => {
return payload.userId === variables.userId
} )
}
}
}
@@ -111,19 +111,6 @@ extend type Subscription {
@hasRole(role: "server:user")
@hasScope(scope: "streams:read")
"""
Subscribes to stream permission granted event. Use this to display an up-to-date list of streams for your profile.
"""
streamPermissionGranted( userId: String! ): JSONObject
@hasRole(role: "server:user")
@hasScope(scope: "profile:read")
"""
Subscribes to stream delete event. Use this to display an up-to-date list of streams for your profile.
"""
streamPermissionRevoked( userId: String! ): JSONObject
@hasRole(role: "server:user")
@hasScope(scope: "profile:read")
}
input StreamCreateInput {
+275 -273
View File
@@ -132,6 +132,66 @@ describe( 'GraphQL API Subscriptions', ( ) => {
consumer.unsubscribe( )
} ).timeout( 5000 )
it( 'A user (me) should be notified when stream permission is granted', async ( ) => {
const resSC = await sendRequest( userA.token, { query: `mutation { streamCreate(stream: { name: "Subs Test (u A) Private", description: "Hello World", isPublic:false } ) }` } )
const streamId = resSC.body.data.streamCreate
let eventNum = 0
const query = gql `subscription permissionGranted { userStreamCreated }`
const client = createSubscriptionObservable( wsAddr, userB.token, query )
const consumer = client.subscribe( eventData => {
console.log( eventData )
expect( eventData.data.userStreamCreated ).to.exist
expect( eventData.data.userStreamCreated.sharedBy ).to.exist
eventNum++
} )
await sleep( 500 )
let sg =
await sendRequest( userA.token, {
query: `mutation { streamGrantPermission( permissionParams: {streamId: "${streamId}", userId: "${userB.id}", role: "stream:contributor"} ) }`
} )
.expect( 200 )
.expect( noErrors )
await sleep( 1000 ) // we need to wait up a second here
expect( eventNum ).to.equal( 1 )
consumer.unsubscribe( )
} ).timeout( 5000 )
it( 'A user (me) should be notified when stream permission is revoked', async ( ) => {
const resSC = await sendRequest( userA.token, { query: `mutation { streamCreate(stream: { name: "Subs Test (u A) Private", description: "Hello World", isPublic:false } ) }` } )
const streamId = resSC.body.data.streamCreate
let eventNum = 0
const query = gql `subscription permissionRevoked { userStreamDeleted }`
const client = createSubscriptionObservable( wsAddr, userB.token, query )
const consumer = client.subscribe( eventData => {
console.log( eventData.data )
expect( eventData.data.userStreamDeleted ).to.exist
expect( eventData.data.userStreamDeleted.revokedBy ).to.exist
eventNum++
} )
await sleep( 500 )
let sg = await sendRequest( userA.token, {
query: `mutation { streamGrantPermission( permissionParams: {streamId: "${streamId}", userId: "${userB.id}", role: "stream:contributor"} ) }`
} )
.expect( 200 )
.expect( noErrors )
let sr = await sendRequest( userA.token, {
query: `mutation { streamRevokePermission( permissionParams: {streamId: "${streamId}", userId: "${userB.id}"} ) }`
} )
.expect( 200 )
.expect( noErrors )
await sleep( 1000 ) // we need to wait up a second here
expect( eventNum ).to.equal( 1 )
consumer.unsubscribe( )
} ).timeout( 5000 )
it( 'Should be notified when a stream is updated', async ( ) => {
const resSC = await sendRequest( userA.token, { query: `mutation { streamCreate(stream: { name: "Subs Test (u A) Private", description: "Hello World", isPublic:false } ) }` } )
const streamId = resSC.body.data.streamCreate
@@ -187,64 +247,6 @@ describe( 'GraphQL API Subscriptions', ( ) => {
consumer.unsubscribe( )
} ).timeout( 5000 )
it( 'Should be notified when stream permission is granted', async ( ) => {
const resSC = await sendRequest( userA.token, { query: `mutation { streamCreate(stream: { name: "Subs Test (u A) Private", description: "Hello World", isPublic:false } ) }` } )
const streamId = resSC.body.data.streamCreate
let eventNum = 0
const query = gql `subscription permissionGranted { streamPermissionGranted( userId: "${userB.id}" ) }`
const client = createSubscriptionObservable( wsAddr, userB.token, query )
const consumer = client.subscribe( eventData => {
expect( eventData.data.streamPermissionGranted ).to.exist
eventNum++
} )
await sleep( 500 )
let sg =
await sendRequest( userA.token, {
query: `mutation { streamGrantPermission( permissionParams: {streamId: "${streamId}", userId: "${userB.id}", role: "stream:contributor"} ) }`
} )
.expect( 200 )
.expect( noErrors )
await sleep( 1000 ) // we need to wait up a second here
expect( eventNum ).to.equal( 1 )
consumer.unsubscribe( )
} ).timeout( 5000 )
it( 'Should be notified when stream permission is revoked', async ( ) => {
const resSC = await sendRequest( userA.token, { query: `mutation { streamCreate(stream: { name: "Subs Test (u A) Private", description: "Hello World", isPublic:false } ) }` } )
const streamId = resSC.body.data.streamCreate
let eventNum = 0
const query = gql `subscription permissionRevoked { streamPermissionRevoked( userId: "${userB.id}" ) }`
const client = createSubscriptionObservable( wsAddr, userB.token, query )
const consumer = client.subscribe( eventData => {
expect( eventData.data.streamPermissionRevoked ).to.exist
eventNum++
} )
await sleep( 500 )
let sg = await sendRequest( userA.token, {
query: `mutation { streamGrantPermission( permissionParams: {streamId: "${streamId}", userId: "${userB.id}", role: "stream:contributor"} ) }`
} )
.expect( 200 )
.expect( noErrors )
let sr = await sendRequest( userA.token, {
query: `mutation { streamRevokePermission( permissionParams: {streamId: "${streamId}", userId: "${userB.id}"} ) }`
} )
.expect( 200 )
.expect( noErrors )
await sleep( 1000 ) // we need to wait up a second here
expect( eventNum ).to.equal( 1 )
consumer.unsubscribe( )
} ).timeout( 5000 )
it( 'Should *not* be notified of stream creation if invalid token', async ( ) => {
let eventNum = 0
const query = gql `subscription mySub { userStreamCreated }`
@@ -314,260 +316,260 @@ describe( 'GraphQL API Subscriptions', ( ) => {
} ).timeout( 5000 )
} )
describe( 'Branches', ( ) => {
it( 'Should be notified when a branch is created', async ( ) => {
const resSC = await sendRequest( userA.token, { query: `mutation { streamCreate(stream: { name: "Subs Test (u A) Private", description: "Hello World", isPublic:false } ) }` } )
const streamId = resSC.body.data.streamCreate
// describe( 'Branches', ( ) => {
// it( 'Should be notified when a branch is created', async ( ) => {
// const resSC = await sendRequest( userA.token, { query: `mutation { streamCreate(stream: { name: "Subs Test (u A) Private", description: "Hello World", isPublic:false } ) }` } )
// const streamId = resSC.body.data.streamCreate
let eventNum = 0
const query = gql `subscription { branchCreated( streamId: "${streamId}" ) }`
const client = createSubscriptionObservable( wsAddr, userA.token, query )
const consumer = client.subscribe( eventData => {
expect( eventData.data.branchCreated ).to.exist
eventNum++
} )
// let eventNum = 0
// const query = gql `subscription { branchCreated( streamId: "${streamId}" ) }`
// const client = createSubscriptionObservable( wsAddr, userA.token, query )
// const consumer = client.subscribe( eventData => {
// expect( eventData.data.branchCreated ).to.exist
// eventNum++
// } )
await sleep( 500 )
// await sleep( 500 )
let bc1 = await sendRequest( userA.token, {
query: `mutation { branchCreate ( branch: { streamId: "${streamId}", name: "new branch 🌿", description: "this is a test branch 🌳" } ) }`
} )
.expect( 200 )
.expect( noErrors )
let bc2 = await sendRequest( userA.token, {
query: `mutation { branchCreate ( branch: { streamId: "${streamId}", name: "another branch 🥬", description: "this is a test branch 🌳" } ) }`
} )
.expect( 200 )
.expect( noErrors )
// let bc1 = await sendRequest( userA.token, {
// query: `mutation { branchCreate ( branch: { streamId: "${streamId}", name: "new branch 🌿", description: "this is a test branch 🌳" } ) }`
// } )
// .expect( 200 )
// .expect( noErrors )
// let bc2 = await sendRequest( userA.token, {
// query: `mutation { branchCreate ( branch: { streamId: "${streamId}", name: "another branch 🥬", description: "this is a test branch 🌳" } ) }`
// } )
// .expect( 200 )
// .expect( noErrors )
await sleep( 1000 ) // we need to wait up a second here
expect( eventNum ).to.equal( 2 )
consumer.unsubscribe( )
} ).timeout( 5000 )
// await sleep( 1000 ) // we need to wait up a second here
// expect( eventNum ).to.equal( 2 )
// consumer.unsubscribe( )
// } ).timeout( 5000 )
it( 'Should be notified when a branch is updated', async ( ) => {
const resSC = await sendRequest( userA.token, { query: `mutation { streamCreate(stream: { name: "Subs Test (u A) Private", description: "Hello World", isPublic:false } ) }` } )
const streamId = resSC.body.data.streamCreate
const bc1 = await sendRequest( userA.token, {
query: `mutation { branchCreate ( branch: { streamId: "${streamId}", name: "new branch 🌿", description: "this is a test branch 🌳" } ) }`
} )
const branchId = bc1.body.data.branchCreate
// it( 'Should be notified when a branch is updated', async ( ) => {
// const resSC = await sendRequest( userA.token, { query: `mutation { streamCreate(stream: { name: "Subs Test (u A) Private", description: "Hello World", isPublic:false } ) }` } )
// const streamId = resSC.body.data.streamCreate
// const bc1 = await sendRequest( userA.token, {
// query: `mutation { branchCreate ( branch: { streamId: "${streamId}", name: "new branch 🌿", description: "this is a test branch 🌳" } ) }`
// } )
// const branchId = bc1.body.data.branchCreate
let eventNum = 0
const query = gql `subscription { branchUpdated( streamId: "${streamId}" ) }`
const client = createSubscriptionObservable( wsAddr, userA.token, query )
const consumer = client.subscribe( eventData => {
expect( eventData.data.branchUpdated ).to.exist
eventNum++
} )
// let eventNum = 0
// const query = gql `subscription { branchUpdated( streamId: "${streamId}" ) }`
// const client = createSubscriptionObservable( wsAddr, userA.token, query )
// const consumer = client.subscribe( eventData => {
// expect( eventData.data.branchUpdated ).to.exist
// eventNum++
// } )
await sleep( 500 )
// await sleep( 500 )
let bu1 = await sendRequest( userA.token, {
query: `mutation { branchUpdate ( branch: { streamId: "${streamId}", id: "${branchId}", description: "updating this branch" } ) }`
} )
.expect( 200 )
.expect( noErrors )
let bu2 = await sendRequest( userA.token, {
query: `mutation { branchUpdate ( branch: { streamId: "${streamId}", id: "${branchId}", description: "updating this branch v2" } ) }`
} )
.expect( 200 )
.expect( noErrors )
// let bu1 = await sendRequest( userA.token, {
// query: `mutation { branchUpdate ( branch: { streamId: "${streamId}", id: "${branchId}", description: "updating this branch" } ) }`
// } )
// .expect( 200 )
// .expect( noErrors )
// let bu2 = await sendRequest( userA.token, {
// query: `mutation { branchUpdate ( branch: { streamId: "${streamId}", id: "${branchId}", description: "updating this branch v2" } ) }`
// } )
// .expect( 200 )
// .expect( noErrors )
await sleep( 1000 ) // we need to wait up a second here
expect( eventNum ).to.equal( 2 )
consumer.unsubscribe( )
} ).timeout( 5000 )
// await sleep( 1000 ) // we need to wait up a second here
// expect( eventNum ).to.equal( 2 )
// consumer.unsubscribe( )
// } ).timeout( 5000 )
it( 'Should be notified when a branch is deleted', async ( ) => {
const resSC = await sendRequest( userA.token, { query: `mutation { streamCreate(stream: { name: "Subs Test (u A) Private", description: "Hello World", isPublic:false } ) }` } )
const streamId = resSC.body.data.streamCreate
const bc1 = await sendRequest( userA.token, {
query: `mutation { branchCreate ( branch: { streamId: "${streamId}", name: "new branch 🌿", description: "this is a test branch 🌳" } ) }`
} )
const bc2 = await sendRequest( userA.token, {
query: `mutation { branchCreate ( branch: { streamId: "${streamId}", name: "another branch 🥬", description: "this is a test branch 🌳" } ) }`
} )
const bid1 = bc1.body.data.branchCreate
const bid2 = bc2.body.data.branchCreate
// it( 'Should be notified when a branch is deleted', async ( ) => {
// const resSC = await sendRequest( userA.token, { query: `mutation { streamCreate(stream: { name: "Subs Test (u A) Private", description: "Hello World", isPublic:false } ) }` } )
// const streamId = resSC.body.data.streamCreate
// const bc1 = await sendRequest( userA.token, {
// query: `mutation { branchCreate ( branch: { streamId: "${streamId}", name: "new branch 🌿", description: "this is a test branch 🌳" } ) }`
// } )
// const bc2 = await sendRequest( userA.token, {
// query: `mutation { branchCreate ( branch: { streamId: "${streamId}", name: "another branch 🥬", description: "this is a test branch 🌳" } ) }`
// } )
// const bid1 = bc1.body.data.branchCreate
// const bid2 = bc2.body.data.branchCreate
let eventNum = 0
const query = gql `subscription { branchDeleted( streamId: "${streamId}" ) }`
const client = createSubscriptionObservable( wsAddr, userA.token, query )
const consumer = client.subscribe( eventData => {
expect( eventData.data.branchDeleted ).to.exist
eventNum++
} )
// let eventNum = 0
// const query = gql `subscription { branchDeleted( streamId: "${streamId}" ) }`
// const client = createSubscriptionObservable( wsAddr, userA.token, query )
// const consumer = client.subscribe( eventData => {
// expect( eventData.data.branchDeleted ).to.exist
// eventNum++
// } )
await sleep( 500 )
// await sleep( 500 )
let bd1 = await sendRequest( userA.token, {
query: `mutation { branchDelete ( branch: { streamId: "${streamId}", id: "${bid1}" } ) }`
} )
.expect( 200 )
.expect( noErrors )
let bd2 = await sendRequest( userA.token, {
query: `mutation { branchDelete ( branch: { streamId: "${streamId}", id: "${bid2}" } ) }`
} )
.expect( 200 )
.expect( noErrors )
// let bd1 = await sendRequest( userA.token, {
// query: `mutation { branchDelete ( branch: { streamId: "${streamId}", id: "${bid1}" } ) }`
// } )
// .expect( 200 )
// .expect( noErrors )
// let bd2 = await sendRequest( userA.token, {
// query: `mutation { branchDelete ( branch: { streamId: "${streamId}", id: "${bid2}" } ) }`
// } )
// .expect( 200 )
// .expect( noErrors )
await sleep( 1000 ) // we need to wait up a second here
expect( eventNum ).to.equal( 2 )
consumer.unsubscribe( )
} ).timeout( 5000 )
// await sleep( 1000 ) // we need to wait up a second here
// expect( eventNum ).to.equal( 2 )
// consumer.unsubscribe( )
// } ).timeout( 5000 )
it( `Should *not* be notified when a branch is created for a stream you're not authorised for`, async ( ) => {
const resSC = await sendRequest( userA.token, { query: `mutation { streamCreate(stream: { name: "Subs Test (u A) Private", description: "Hello World", isPublic:false } ) }` } )
const streamId = resSC.body.data.streamCreate
// it( `Should *not* be notified when a branch is created for a stream you're not authorised for`, async ( ) => {
// const resSC = await sendRequest( userA.token, { query: `mutation { streamCreate(stream: { name: "Subs Test (u A) Private", description: "Hello World", isPublic:false } ) }` } )
// const streamId = resSC.body.data.streamCreate
let eventNum = 0
const query = gql `subscription { branchCreated( streamId: "${streamId}" ) }`
const client = createSubscriptionObservable( wsAddr, userB.token, query )
const consumer = client.subscribe( eventData => {
expect( eventData.data.branchCreated ).to.not.exist
eventNum++
} )
// let eventNum = 0
// const query = gql `subscription { branchCreated( streamId: "${streamId}" ) }`
// const client = createSubscriptionObservable( wsAddr, userB.token, query )
// const consumer = client.subscribe( eventData => {
// expect( eventData.data.branchCreated ).to.not.exist
// eventNum++
// } )
await sleep( 500 )
// await sleep( 500 )
let bc = await sendRequest( userA.token, {
query: `mutation { branchCreate ( branch: { streamId: "${streamId}", name: "new branch 🌿", description: "this is a test branch 🌳" } ) }`
} )
.expect( 200 )
.expect( noErrors )
// let bc = await sendRequest( userA.token, {
// query: `mutation { branchCreate ( branch: { streamId: "${streamId}", name: "new branch 🌿", description: "this is a test branch 🌳" } ) }`
// } )
// .expect( 200 )
// .expect( noErrors )
await sleep( 1000 ) // we need to wait up a second here
expect( eventNum ).to.equal( 0 )
consumer.unsubscribe( )
} ).timeout( 5000 )
} )
// await sleep( 1000 ) // we need to wait up a second here
// expect( eventNum ).to.equal( 0 )
// consumer.unsubscribe( )
// } ).timeout( 5000 )
// } )
describe( 'Commits', ( ) => {
it( 'Should be notified when a commit is created', async ( ) => {
const resSC = await sendRequest( userA.token, { query: `mutation { streamCreate(stream: { name: "Subs Test (u A) Private", description: "Hello World", isPublic:false } ) }` } )
const streamId = resSC.body.data.streamCreate
const resOC1 = await sendRequest( userA.token, { query: `mutation { objectCreate( objectInput: {streamId: "${streamId}", objects: {hello: "goodbye 🌊"}} ) }` } )
const resOC2 = await sendRequest( userA.token, { query: `mutation { objectCreate( objectInput: {streamId: "${streamId}", objects: {wow: "cool 🐟"}} ) }` } )
const objId1 = resOC1.body.data.objectCreate
const objId2 = resOC2.body.data.objectCreate
// describe( 'Commits', ( ) => {
// it( 'Should be notified when a commit is created', async ( ) => {
// const resSC = await sendRequest( userA.token, { query: `mutation { streamCreate(stream: { name: "Subs Test (u A) Private", description: "Hello World", isPublic:false } ) }` } )
// const streamId = resSC.body.data.streamCreate
// const resOC1 = await sendRequest( userA.token, { query: `mutation { objectCreate( objectInput: {streamId: "${streamId}", objects: {hello: "goodbye 🌊"}} ) }` } )
// const resOC2 = await sendRequest( userA.token, { query: `mutation { objectCreate( objectInput: {streamId: "${streamId}", objects: {wow: "cool 🐟"}} ) }` } )
// const objId1 = resOC1.body.data.objectCreate
// const objId2 = resOC2.body.data.objectCreate
let eventNum = 0
const query = gql `subscription { commitCreated( streamId: "${streamId}" ) }`
const client = createSubscriptionObservable( wsAddr, userA.token, query )
const consumer = client.subscribe( eventData => {
expect( eventData.data.commitCreated ).to.exist
eventNum++
} )
// let eventNum = 0
// const query = gql `subscription { commitCreated( streamId: "${streamId}" ) }`
// const client = createSubscriptionObservable( wsAddr, userA.token, query )
// const consumer = client.subscribe( eventData => {
// expect( eventData.data.commitCreated ).to.exist
// eventNum++
// } )
await sleep( 500 )
// await sleep( 500 )
let cc1 = await sendRequest( userA.token, {
query: `mutation { commitCreate ( commit: { streamId: "${streamId}", branchName: "master", objectId: "${objId1}" } ) }`
} )
.expect( 200 )
.expect( noErrors )
let cc2 = await sendRequest( userA.token, {
query: `mutation { commitCreate ( commit: { streamId: "${streamId}", branchName: "master", objectId: "${objId2}" } ) }`
} )
.expect( 200 )
.expect( noErrors )
// let cc1 = await sendRequest( userA.token, {
// query: `mutation { commitCreate ( commit: { streamId: "${streamId}", branchName: "master", objectId: "${objId1}" } ) }`
// } )
// .expect( 200 )
// .expect( noErrors )
// let cc2 = await sendRequest( userA.token, {
// query: `mutation { commitCreate ( commit: { streamId: "${streamId}", branchName: "master", objectId: "${objId2}" } ) }`
// } )
// .expect( 200 )
// .expect( noErrors )
await sleep( 1000 ) // we need to wait up a second here
expect( eventNum ).to.equal( 2 )
consumer.unsubscribe( )
} ).timeout( 5000 )
// await sleep( 1000 ) // we need to wait up a second here
// expect( eventNum ).to.equal( 2 )
// consumer.unsubscribe( )
// } ).timeout( 5000 )
it( 'Should be notified when a commit is updated', async ( ) => {
const resSC = await sendRequest( userA.token, { query: `mutation { streamCreate(stream: { name: "Subs Test (u A) Private", description: "Hello World", isPublic:false } ) }` } )
const streamId = resSC.body.data.streamCreate
const resOC = await sendRequest( userA.token, { query: `mutation { objectCreate( objectInput: {streamId: "${streamId}", objects: {hello: "goodbye 🌊"}} ) }` } )
const objId = resOC.body.data.objectCreate
const resCC = await sendRequest( userA.token, { query: `mutation { commitCreate ( commit: { streamId: "${streamId}", branchName: "master", objectId: "${objId}" } ) }` } )
const commitId = resCC.body.data.commitCreate
// it( 'Should be notified when a commit is updated', async ( ) => {
// const resSC = await sendRequest( userA.token, { query: `mutation { streamCreate(stream: { name: "Subs Test (u A) Private", description: "Hello World", isPublic:false } ) }` } )
// const streamId = resSC.body.data.streamCreate
// const resOC = await sendRequest( userA.token, { query: `mutation { objectCreate( objectInput: {streamId: "${streamId}", objects: {hello: "goodbye 🌊"}} ) }` } )
// const objId = resOC.body.data.objectCreate
// const resCC = await sendRequest( userA.token, { query: `mutation { commitCreate ( commit: { streamId: "${streamId}", branchName: "master", objectId: "${objId}" } ) }` } )
// const commitId = resCC.body.data.commitCreate
let eventNum = 0
const query = gql `subscription { commitUpdated( streamId: "${streamId}" ) }`
const client = createSubscriptionObservable( wsAddr, userA.token, query )
const consumer = client.subscribe( eventData => {
expect( eventData.data.commitUpdated ).to.exist
eventNum++
} )
// let eventNum = 0
// const query = gql `subscription { commitUpdated( streamId: "${streamId}" ) }`
// const client = createSubscriptionObservable( wsAddr, userA.token, query )
// const consumer = client.subscribe( eventData => {
// expect( eventData.data.commitUpdated ).to.exist
// eventNum++
// } )
await sleep( 500 )
// await sleep( 500 )
let cu1 = await sendRequest( userA.token, {
query: `mutation { commitUpdate ( commit: { streamId: "${streamId}", id: "${commitId}", message: "updating this commit" } ) }`
} )
.expect( 200 )
.expect( noErrors )
let cu2 = await sendRequest( userA.token, {
query: `mutation { commitUpdate ( commit: { streamId: "${streamId}", id: "${commitId}", message: "updating this commit v2" } ) }`
} )
.expect( 200 )
.expect( noErrors )
// let cu1 = await sendRequest( userA.token, {
// query: `mutation { commitUpdate ( commit: { streamId: "${streamId}", id: "${commitId}", message: "updating this commit" } ) }`
// } )
// .expect( 200 )
// .expect( noErrors )
// let cu2 = await sendRequest( userA.token, {
// query: `mutation { commitUpdate ( commit: { streamId: "${streamId}", id: "${commitId}", message: "updating this commit v2" } ) }`
// } )
// .expect( 200 )
// .expect( noErrors )
await sleep( 1000 ) // we need to wait up a second here
expect( eventNum ).to.equal( 2 )
consumer.unsubscribe( )
} ).timeout( 5000 )
// await sleep( 1000 ) // we need to wait up a second here
// expect( eventNum ).to.equal( 2 )
// consumer.unsubscribe( )
// } ).timeout( 5000 )
it( 'Should be notified when a commit is deleted', async ( ) => {
const resSC = await sendRequest( userA.token, { query: `mutation { streamCreate(stream: { name: "Subs Test (u A) Private", description: "Hello World", isPublic:false } ) }` } )
const streamId = resSC.body.data.streamCreate
const resOC = await sendRequest( userA.token, { query: `mutation { objectCreate( objectInput: {streamId: "${streamId}", objects: {hello: "goodbye 🌊"}} ) }` } )
const objId = resOC.body.data.objectCreate
const resCC = await sendRequest( userA.token, { query: `mutation { commitCreate ( commit: { streamId: "${streamId}", branchName: "master", objectId: "${objId}" } ) }` } )
const commitId = resCC.body.data.commitCreate
// it( 'Should be notified when a commit is deleted', async ( ) => {
// const resSC = await sendRequest( userA.token, { query: `mutation { streamCreate(stream: { name: "Subs Test (u A) Private", description: "Hello World", isPublic:false } ) }` } )
// const streamId = resSC.body.data.streamCreate
// const resOC = await sendRequest( userA.token, { query: `mutation { objectCreate( objectInput: {streamId: "${streamId}", objects: {hello: "goodbye 🌊"}} ) }` } )
// const objId = resOC.body.data.objectCreate
// const resCC = await sendRequest( userA.token, { query: `mutation { commitCreate ( commit: { streamId: "${streamId}", branchName: "master", objectId: "${objId}" } ) }` } )
// const commitId = resCC.body.data.commitCreate
let eventNum = 0
const query = gql `subscription { commitDeleted( streamId: "${streamId}" ) }`
const client = createSubscriptionObservable( wsAddr, userA.token, query )
const consumer = client.subscribe( eventData => {
expect( eventData.data.commitDeleted ).to.exist
eventNum++
} )
// let eventNum = 0
// const query = gql `subscription { commitDeleted( streamId: "${streamId}" ) }`
// const client = createSubscriptionObservable( wsAddr, userA.token, query )
// const consumer = client.subscribe( eventData => {
// expect( eventData.data.commitDeleted ).to.exist
// eventNum++
// } )
await sleep( 500 )
// await sleep( 500 )
let cd = await sendRequest( userA.token, {
query: `mutation { commitDelete ( commit: { streamId: "${streamId}", id: "${commitId}" } ) }`
} )
.expect( 200 )
.expect( noErrors )
// let cd = await sendRequest( userA.token, {
// query: `mutation { commitDelete ( commit: { streamId: "${streamId}", id: "${commitId}" } ) }`
// } )
// .expect( 200 )
// .expect( noErrors )
await sleep( 1000 ) // we need to wait up a second here
expect( eventNum ).to.equal( 1 )
consumer.unsubscribe( )
} ).timeout( 5000 )
// await sleep( 1000 ) // we need to wait up a second here
// expect( eventNum ).to.equal( 1 )
// consumer.unsubscribe( )
// } ).timeout( 5000 )
it( `Should *not* be notified when a commit is created on a stream you're not authorised for`, async ( ) => {
const resSC = await sendRequest( userA.token, { query: `mutation { streamCreate(stream: { name: "Subs Test (u A) Private", description: "Hello World", isPublic:false } ) }` } )
const streamId = resSC.body.data.streamCreate
const resOC = await sendRequest( userA.token, { query: `mutation { objectCreate( objectInput: {streamId: "${streamId}", objects: {hello: "goodbye 🌊"}} ) }` } )
const objId = resOC.body.data.objectCreate
// it( `Should *not* be notified when a commit is created on a stream you're not authorised for`, async ( ) => {
// const resSC = await sendRequest( userA.token, { query: `mutation { streamCreate(stream: { name: "Subs Test (u A) Private", description: "Hello World", isPublic:false } ) }` } )
// const streamId = resSC.body.data.streamCreate
// const resOC = await sendRequest( userA.token, { query: `mutation { objectCreate( objectInput: {streamId: "${streamId}", objects: {hello: "goodbye 🌊"}} ) }` } )
// const objId = resOC.body.data.objectCreate
let eventNum = 0
const query = gql `subscription { commitCreated( streamId: "${streamId}" ) }`
const client = createSubscriptionObservable( wsAddr, userB.token, query )
const consumer = client.subscribe( eventData => {
expect( eventData.data.commitCreated ).to.not.exist
eventNum++
} )
// let eventNum = 0
// const query = gql `subscription { commitCreated( streamId: "${streamId}" ) }`
// const client = createSubscriptionObservable( wsAddr, userB.token, query )
// const consumer = client.subscribe( eventData => {
// expect( eventData.data.commitCreated ).to.not.exist
// eventNum++
// } )
await sleep( 500 )
// await sleep( 500 )
let cc = await sendRequest( userA.token, {
query: `mutation { commitCreate ( commit: { streamId: "${streamId}", branchName: "master", objectId: "${objId}" } ) }`
} )
.expect( 200 )
.expect( noErrors )
// let cc = await sendRequest( userA.token, {
// query: `mutation { commitCreate ( commit: { streamId: "${streamId}", branchName: "master", objectId: "${objId}" } ) }`
// } )
// .expect( 200 )
// .expect( noErrors )
await sleep( 1000 ) // we need to wait up a second here
expect( eventNum ).to.equal( 0 )
consumer.unsubscribe( )
} ).timeout( 5000 )
} )
// await sleep( 1000 ) // we need to wait up a second here
// expect( eventNum ).to.equal( 0 )
// consumer.unsubscribe( )
// } ).timeout( 5000 )
// } )
} )
/**