Skip to content

Commit 5dd2e98

Browse files
committed
added memberships step definitions
1 parent ab5a518 commit 5dd2e98

File tree

4 files changed

+115
-0
lines changed

4 files changed

+115
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { Given, When, Then } from '@cucumber/cucumber';
2+
import { expect } from 'chai';
3+
4+
Given('the user ID {string} and space ID {string}', async function(userId, spaceId) {
5+
this.userId = userId;
6+
this.spaceId = spaceId;
7+
});
8+
9+
When('I add the membership', async function() {
10+
let pubnub = this.getPubnub({
11+
publishKey: this.keyset.publishKey,
12+
subscribeKey: this.keyset.subscribeKey
13+
});
14+
15+
let result = await pubnub.addMemberships({
16+
userId: this.userId,
17+
spaces: [ this.spaceId ]
18+
});
19+
expect(result.status).to.equal(200);
20+
this.memberships = result.data;
21+
});
22+
23+
Then('I get a list of memberships', async function() {
24+
expect(this.memberships).to.not.be.undefined;
25+
expect(this.memberships.length).to.be.greaterThan(0);
26+
27+
this.membership = this.memberships[0];
28+
});
29+
30+
Then('containing a membership with', async function() {
31+
expect(this.membership).to.not.be.undefined;
32+
});
33+
34+
Then('add membership space ID equal to {string}', async function(spaceId) {
35+
// this is an SDK bug 'channel' should be 'space'
36+
expect(this.membership.channel).to.not.be.undefined;
37+
expect(this.membership.channel.id).to.equal(spaceId);
38+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Given, When, Then } from '@cucumber/cucumber';
2+
import { expect } from 'chai';
3+
4+
Given('the user ID {string}', async function(userId) {
5+
this.userId = userId;
6+
});
7+
8+
When('I fetch the membership', async function() {
9+
let pubnub = this.getPubnub({
10+
publishKey: this.keyset.publishKey,
11+
subscribeKey: this.keyset.subscribeKey
12+
});
13+
14+
let result = await pubnub.fetchMemberships({
15+
userId: this.userId,
16+
include: {}
17+
});
18+
expect(result.status).to.equal(200);
19+
this.memberships = result.data;
20+
});
21+
22+
Then('fetch membership space ID equal to {string}', async function(spaceId) {
23+
expect(this.membership.space).to.not.be.undefined;
24+
expect(this.membership.space.id).to.equal(spaceId);
25+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Given, When, Then } from '@cucumber/cucumber';
2+
import { expect } from 'chai';
3+
4+
When('I remove the membership {string}', async function(spaceId) {
5+
let pubnub = this.getPubnub({
6+
publishKey: this.keyset.publishKey,
7+
subscribeKey: this.keyset.subscribeKey
8+
});
9+
10+
let result = await pubnub.removeMemberships({
11+
userId: this.userId,
12+
spaceIds: [ spaceId ]
13+
});
14+
expect(result.status).to.equal(200);
15+
this.memberships = result.data;
16+
});
17+
18+
Then('I get an empty list of memberships', async function() {
19+
expect(this.memberships.length).to.equal(0);
20+
});
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { Given, When, Then } from '@cucumber/cucumber';
2+
import { expect } from 'chai';
3+
4+
When('I update the membership to {string}', async function(spaceId) {
5+
let pubnub = this.getPubnub({
6+
publishKey: this.keyset.publishKey,
7+
subscribeKey: this.keyset.subscribeKey
8+
});
9+
10+
let result = await pubnub.updateMemberships({
11+
userId: this.userId,
12+
spaces: [ spaceId ]
13+
});
14+
expect(result.status).to.equal(200);
15+
this.updatedMemberships = result.data;
16+
});
17+
18+
Then('I get a list of updated memberships', async function() {
19+
expect(this.memberships).to.not.be.undefined;
20+
expect(this.memberships.length).to.be.greaterThan(0);
21+
22+
this.updatedMembership = this.updatedMemberships[0];
23+
});
24+
25+
Then('containing an updated membership with', async function() {
26+
expect(this.updatedMembership).to.not.be.undefined;
27+
});
28+
29+
Then('updated membership space ID equal to {string}', async function(spaceId) {
30+
expect(this.updatedMembership.channel).to.not.be.undefined;
31+
expect(this.updatedMembership.channel.id).to.equal(spaceId);
32+
});

0 commit comments

Comments
 (0)