diff --git a/test/contract/steps/membership/membership_add.ts b/test/contract/steps/membership/membership_add.ts new file mode 100644 index 000000000..5e7a573ff --- /dev/null +++ b/test/contract/steps/membership/membership_add.ts @@ -0,0 +1,38 @@ +import { Given, When, Then } from '@cucumber/cucumber'; +import { expect } from 'chai'; + +Given('the user ID {string} and space ID {string}', async function(userId, spaceId) { + this.userId = userId; + this.spaceId = spaceId; +}); + +When('I add the membership', async function() { + let pubnub = this.getPubnub({ + publishKey: this.keyset.publishKey, + subscribeKey: this.keyset.subscribeKey + }); + + let result = await pubnub.addMemberships({ + userId: this.userId, + spaces: [ this.spaceId ] + }); + expect(result.status).to.equal(200); + this.memberships = result.data; +}); + +Then('I get a list of memberships', async function() { + expect(this.memberships).to.not.be.undefined; + expect(this.memberships.length).to.be.greaterThan(0); + + this.membership = this.memberships[0]; +}); + +Then('containing a membership with', async function() { + expect(this.membership).to.not.be.undefined; +}); + +Then('add membership space ID equal to {string}', async function(spaceId) { + // this is an SDK bug 'channel' should be 'space' + expect(this.membership.channel).to.not.be.undefined; + expect(this.membership.channel.id).to.equal(spaceId); +}); diff --git a/test/contract/steps/membership/membership_fetch.ts b/test/contract/steps/membership/membership_fetch.ts new file mode 100644 index 000000000..617a78c9e --- /dev/null +++ b/test/contract/steps/membership/membership_fetch.ts @@ -0,0 +1,25 @@ +import { Given, When, Then } from '@cucumber/cucumber'; +import { expect } from 'chai'; + +Given('the user ID {string}', async function(userId) { + this.userId = userId; +}); + +When('I fetch the membership', async function() { + let pubnub = this.getPubnub({ + publishKey: this.keyset.publishKey, + subscribeKey: this.keyset.subscribeKey + }); + + let result = await pubnub.fetchMemberships({ + userId: this.userId, + include: {} + }); + expect(result.status).to.equal(200); + this.memberships = result.data; +}); + +Then('fetch membership space ID equal to {string}', async function(spaceId) { + expect(this.membership.space).to.not.be.undefined; + expect(this.membership.space.id).to.equal(spaceId); +}); \ No newline at end of file diff --git a/test/contract/steps/membership/membership_remove.ts b/test/contract/steps/membership/membership_remove.ts new file mode 100644 index 000000000..e1fb2415f --- /dev/null +++ b/test/contract/steps/membership/membership_remove.ts @@ -0,0 +1,20 @@ +import { Given, When, Then } from '@cucumber/cucumber'; +import { expect } from 'chai'; + +When('I remove the membership {string}', async function(spaceId) { + let pubnub = this.getPubnub({ + publishKey: this.keyset.publishKey, + subscribeKey: this.keyset.subscribeKey + }); + + let result = await pubnub.removeMemberships({ + userId: this.userId, + spaceIds: [ spaceId ] + }); + expect(result.status).to.equal(200); + this.memberships = result.data; +}); + +Then('I get an empty list of memberships', async function() { + expect(this.memberships.length).to.equal(0); +}); \ No newline at end of file diff --git a/test/contract/steps/membership/membership_update.ts b/test/contract/steps/membership/membership_update.ts new file mode 100644 index 000000000..47aec0e81 --- /dev/null +++ b/test/contract/steps/membership/membership_update.ts @@ -0,0 +1,32 @@ +import { Given, When, Then } from '@cucumber/cucumber'; +import { expect } from 'chai'; + +When('I update the membership to {string}', async function(spaceId) { + let pubnub = this.getPubnub({ + publishKey: this.keyset.publishKey, + subscribeKey: this.keyset.subscribeKey + }); + + let result = await pubnub.updateMemberships({ + userId: this.userId, + spaces: [ spaceId ] + }); + expect(result.status).to.equal(200); + this.updatedMemberships = result.data; +}); + +Then('I get a list of updated memberships', async function() { + expect(this.memberships).to.not.be.undefined; + expect(this.memberships.length).to.be.greaterThan(0); + + this.updatedMembership = this.updatedMemberships[0]; +}); + +Then('containing an updated membership with', async function() { + expect(this.updatedMembership).to.not.be.undefined; +}); + +Then('updated membership space ID equal to {string}', async function(spaceId) { + expect(this.updatedMembership.channel).to.not.be.undefined; + expect(this.updatedMembership.channel.id).to.equal(spaceId); +}); diff --git a/test/contract/steps/space/space_create.ts b/test/contract/steps/space/space_create.ts new file mode 100644 index 000000000..edfc55f46 --- /dev/null +++ b/test/contract/steps/space/space_create.ts @@ -0,0 +1,25 @@ +import { Given, When, Then } from '@cucumber/cucumber'; +import { expect } from 'chai'; + +Given('the space ID {string}, name {string}, description {string}', async function(spaceId, spaceName, spaceDescription) { + this.spaceId = spaceId; + this.spaceName = spaceName; + this.spaceDescription = spaceDescription; +}); + +When('I create the space', async function() { + let pubnub = this.getPubnub({ + publishKey: this.keyset.publishKey, + subscribeKey: this.keyset.subscribeKey + }); + + let result = await pubnub.createSpace({ + spaceId: this.spaceId, + data: { + name: this.spaceName, + description: this.spaceDescription, + } + }); + expect(result.status).to.equal(200); + this.space = result.data; +}); \ No newline at end of file diff --git a/test/contract/steps/space/space_fetch.ts b/test/contract/steps/space/space_fetch.ts new file mode 100644 index 000000000..12fea4ab9 --- /dev/null +++ b/test/contract/steps/space/space_fetch.ts @@ -0,0 +1,53 @@ +import { Given, When, Then } from '@cucumber/cucumber'; +import { expect } from 'chai'; + +Given('there is a space with ID {string}, name {string}, description {string}', async function(spaceId, spaceName, spaceDescription) { + this.spaceId = spaceId; + this.spaceName = spaceName; + this.spaceDescription = spaceDescription; +}); + +When('I fetch the space {string}', async function(spaceId) { + // ensure we fetch the existing specified space id + expect(spaceId).to.equal(this.spaceId); + + let pubnub = this.getPubnub({ + publishKey: this.keyset.publishKey, + subscribeKey: this.keyset.subscribeKey + }); + + let result = await pubnub.fetchSpace({ + spaceId: spaceId + }); + expect(result.status).to.equal(200); + this.space = result.data; +}); + +When('I fetch all spaces', async function() { + let pubnub = this.getPubnub({ + publishKey: this.keyset.publishKey, + subscribeKey: this.keyset.subscribeKey + }); + + let result = await pubnub.fetchSpaces(); + expect(result.status).to.equal(200); + this.spaces = result.data; +}); + +Then('I get a list of space objects', async function() { + expect(this.spaces).to.not.be.undefined; + + this.space = this.spaces[0]; +}); + +Then('I get a space object with', async function() { + expect(this.space).to.not.be.undefined; +}); + +Then('Space ID equal to {string}', async function(spaceId) { + expect(spaceId).to.equal(this.space.id); +}); + +Then('Space name equal to {string}', async function(spaceName) { + expect(spaceName).to.equal(this.space.name); +}); diff --git a/test/contract/steps/space/space_remove.ts b/test/contract/steps/space/space_remove.ts new file mode 100644 index 000000000..58da8a086 --- /dev/null +++ b/test/contract/steps/space/space_remove.ts @@ -0,0 +1,43 @@ +import { Given, When, Then } from '@cucumber/cucumber'; +import { expect } from 'chai'; + +When('I remove the space', async function() { + let pubnub = this.getPubnub({ + publishKey: this.keyset.publishKey, + subscribeKey: this.keyset.subscribeKey + }); + + let result = await pubnub.removeSpace({ + spaceId: this.spaceId + }); + expect(result.status).to.equal(200); + this.space = result.data; +}); + +Then('I get a null space', async function() { + expect(this.space).to.be.null; +}); + +When('I attempt to fetch the space {string}', async function(spaceId) { + // ensure we fetch the existing specified space id + expect(spaceId).to.equal(this.spaceId); + + let pubnub = this.getPubnub({ + publishKey: this.keyset.publishKey, + subscribeKey: this.keyset.subscribeKey + }); + + try { + let result = await pubnub.fetchSpace({ + spaceId: spaceId + }); + + this.removeStatus = result.status; + } catch (e: any) { + this.errorMessage = e.message; + } +}); + +Then('I get get a space not found error', async function() { + expect(this.errorMessage).to.equal('PubNub call failed, check status for details'); +}); diff --git a/test/contract/steps/space/space_update.ts b/test/contract/steps/space/space_update.ts new file mode 100644 index 000000000..bb1d6a77d --- /dev/null +++ b/test/contract/steps/space/space_update.ts @@ -0,0 +1,33 @@ +import { Given, When, Then } from '@cucumber/cucumber'; +import { expect } from 'chai'; + +Given('the desired space name {string}', async function(spaceName) { + this.spaceNameUpdated = spaceName; +}); + +When('I update the space', async function() { + let pubnub = this.getPubnub({ + publishKey: this.keyset.publishKey, + subscribeKey: this.keyset.subscribeKey + }); + + let result = await pubnub.updateSpace({ + spaceId: this.spaceId, + data: { + name: this.spaceNameUpdated + } + }); + expect(result.status).to.equal(200); + this.updatedSpace = result.data; +}); + +Then('I get an updated space object with', async function() { + expect(this.updatedSpace).to.not.be.undefined; + + this.space = this.updatedSpace +}); + +Then('Updated space name equal to {string}', async function(spaceName) { + expect(spaceName).to.equal(this.updatedSpace.name); +}); + \ No newline at end of file diff --git a/test/contract/steps/user/user_create.ts b/test/contract/steps/user/user_create.ts new file mode 100644 index 000000000..7e3f7ff7e --- /dev/null +++ b/test/contract/steps/user/user_create.ts @@ -0,0 +1,23 @@ +import { Given, When, Then } from '@cucumber/cucumber'; +import { expect } from 'chai'; + +Given('the user ID {string}, name {string}', async function(userId, userName) { + this.userId = userId; + this.userName = userName; +}); + +When('I create the user', async function() { + let pubnub = this.getPubnub({ + publishKey: this.keyset.publishKey, + subscribeKey: this.keyset.subscribeKey + }); + + let result = await pubnub.createUser({ + userId: this.userId, + data: { + name: this.userName + } + }); + expect(result.status).to.equal(200); + this.user = result.data; +}); \ No newline at end of file diff --git a/test/contract/steps/user/user_fetch.ts b/test/contract/steps/user/user_fetch.ts new file mode 100644 index 000000000..045850d29 --- /dev/null +++ b/test/contract/steps/user/user_fetch.ts @@ -0,0 +1,52 @@ +import { Given, When, Then } from '@cucumber/cucumber'; +import { expect } from 'chai'; + +Given('there is a user with ID {string}, name {string}', async function(userId, userName) { + this.userId = userId; + this.userName = userName; +}); + +When('I fetch the user {string}', async function(userId) { + // ensure we fetch the existing specified user id + expect(userId).to.equal(this.userId); + + let pubnub = this.getPubnub({ + publishKey: this.keyset.publishKey, + subscribeKey: this.keyset.subscribeKey + }); + + let result = await pubnub.fetchUser({ + userId: userId + }); + expect(result.status).to.equal(200); + this.user = result.data; +}); + +When('I fetch all users', async function() { + let pubnub = this.getPubnub({ + publishKey: this.keyset.publishKey, + subscribeKey: this.keyset.subscribeKey + }); + + let result = await pubnub.fetchUsers(); + expect(result.status).to.equal(200); + this.users = result.data; +}); + +Then('I get a list of user objects', async function() { + expect(this.users).to.not.be.undefined; + + this.user = this.users[0]; +}); + +Then('I get a user object with', async function() { + expect(this.user).to.not.be.undefined; +}); + +Then('User ID equal to {string}', async function(userId) { + expect(userId).to.equal(this.user.id); +}); + +Then('User name equal to {string}', async function(userName) { + expect(userName).to.equal(this.user.name); +}); diff --git a/test/contract/steps/user/user_remove.ts b/test/contract/steps/user/user_remove.ts new file mode 100644 index 000000000..2f97f9699 --- /dev/null +++ b/test/contract/steps/user/user_remove.ts @@ -0,0 +1,43 @@ +import { Given, When, Then } from '@cucumber/cucumber'; +import { expect } from 'chai'; + +When('I remove the user', async function() { + let pubnub = this.getPubnub({ + publishKey: this.keyset.publishKey, + subscribeKey: this.keyset.subscribeKey + }); + + let result = await pubnub.removeUser({ + userId: this.userId + }); + expect(result.status).to.equal(200); + this.user = result.data; +}); + +Then('I get a null user', async function() { + expect(this.user).to.be.null; +}); + +When('I attempt to fetch the user {string}', async function(userId) { + // ensure we fetch the existing specified user id + expect(userId).to.equal(this.userId); + + let pubnub = this.getPubnub({ + publishKey: this.keyset.publishKey, + subscribeKey: this.keyset.subscribeKey + }); + + try { + let result = await pubnub.fetchUser({ + userId: userId + }); + + this.removeStatus = result.status; + } catch (e: any) { + this.errorMessage = e.message; + } +}); + +Then('I get get a user not found error', async function() { + expect(this.errorMessage).to.equal('PubNub call failed, check status for details'); +}); diff --git a/test/contract/steps/user/user_update.ts b/test/contract/steps/user/user_update.ts new file mode 100644 index 000000000..cc3617981 --- /dev/null +++ b/test/contract/steps/user/user_update.ts @@ -0,0 +1,33 @@ +import { Given, When, Then } from '@cucumber/cucumber'; +import { expect } from 'chai'; + +Given('the desired user name {string}', async function(userName) { + this.userNameUpdated = userName; +}); + +When('I update the user', async function() { + let pubnub = this.getPubnub({ + publishKey: this.keyset.publishKey, + subscribeKey: this.keyset.subscribeKey + }); + + let result = await pubnub.updateUser({ + userId: this.userId, + data: { + name: this.userNameUpdated + } + }); + expect(result.status).to.equal(200); + this.updatedUser = result.data; +}); + +Then('I get an updated user object with', async function() { + expect(this.updatedUser).to.not.be.undefined; + + this.user = this.updatedUser +}); + +Then('Updated user name equal to {string}', async function(userName) { + expect(userName).to.equal(this.updatedUser.name); +}); + \ No newline at end of file diff --git a/test/contract/world.ts b/test/contract/world.ts index 3ffa6c2e5..1122b3bb3 100644 --- a/test/contract/world.ts +++ b/test/contract/world.ts @@ -34,7 +34,7 @@ class PubnubWorld extends World{ origin: 'localhost:8090', ssl: false, suppressLeaveEvents: true, - logVerbosity: false, + logVerbosity: true, uuid: 'myUUID' }, demoKeyset: {