Skip to content

Commit ab5a518

Browse files
committed
testing spaces
1 parent a31b9a7 commit ab5a518

File tree

9 files changed

+233
-5
lines changed

9 files changed

+233
-5
lines changed
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 space ID {string}, name {string}, description {string}', async function(spaceId, spaceName, spaceDescription) {
5+
this.spaceId = spaceId;
6+
this.spaceName = spaceName;
7+
this.spaceDescription = spaceDescription;
8+
});
9+
10+
When('I create the space', async function() {
11+
let pubnub = this.getPubnub({
12+
publishKey: this.keyset.publishKey,
13+
subscribeKey: this.keyset.subscribeKey
14+
});
15+
16+
let result = await pubnub.createSpace({
17+
spaceId: this.spaceId,
18+
data: {
19+
name: this.spaceName,
20+
description: this.spaceDescription,
21+
}
22+
});
23+
expect(result.status).to.equal(200);
24+
this.space = result.data;
25+
});
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { Given, When, Then } from '@cucumber/cucumber';
2+
import { expect } from 'chai';
3+
4+
Given('there is a space with ID {string}, name {string}, description {string}', async function(spaceId, spaceName, spaceDescription) {
5+
this.spaceId = spaceId;
6+
this.spaceName = spaceName;
7+
this.spaceDescription = spaceDescription;
8+
});
9+
10+
When('I fetch the space {string}', async function(spaceId) {
11+
// ensure we fetch the existing specified space id
12+
expect(spaceId).to.equal(this.spaceId);
13+
14+
let pubnub = this.getPubnub({
15+
publishKey: this.keyset.publishKey,
16+
subscribeKey: this.keyset.subscribeKey
17+
});
18+
19+
let result = await pubnub.fetchSpace({
20+
spaceId: spaceId
21+
});
22+
expect(result.status).to.equal(200);
23+
this.space = result.data;
24+
});
25+
26+
When('I fetch all spaces', async function() {
27+
let pubnub = this.getPubnub({
28+
publishKey: this.keyset.publishKey,
29+
subscribeKey: this.keyset.subscribeKey
30+
});
31+
32+
let result = await pubnub.fetchSpaces();
33+
expect(result.status).to.equal(200);
34+
this.spaces = result.data;
35+
});
36+
37+
Then('I get a list of space objects', async function() {
38+
expect(this.spaces).to.not.be.undefined;
39+
40+
this.space = this.spaces[0];
41+
});
42+
43+
Then('I get a space object with', async function() {
44+
expect(this.space).to.not.be.undefined;
45+
});
46+
47+
Then('Space ID equal to {string}', async function(spaceId) {
48+
expect(spaceId).to.equal(this.space.id);
49+
});
50+
51+
Then('Space name equal to {string}', async function(spaceName) {
52+
expect(spaceName).to.equal(this.space.name);
53+
});
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { Given, When, Then } from '@cucumber/cucumber';
2+
import { expect } from 'chai';
3+
4+
When('I remove the space', async function() {
5+
let pubnub = this.getPubnub({
6+
publishKey: this.keyset.publishKey,
7+
subscribeKey: this.keyset.subscribeKey
8+
});
9+
10+
let result = await pubnub.removeSpace({
11+
spaceId: this.spaceId
12+
});
13+
expect(result.status).to.equal(200);
14+
this.space = result.data;
15+
});
16+
17+
Then('I get a null space', async function() {
18+
expect(this.space).to.be.null;
19+
});
20+
21+
When('I attempt to fetch the space {string}', async function(spaceId) {
22+
// ensure we fetch the existing specified space id
23+
expect(spaceId).to.equal(this.spaceId);
24+
25+
let pubnub = this.getPubnub({
26+
publishKey: this.keyset.publishKey,
27+
subscribeKey: this.keyset.subscribeKey
28+
});
29+
30+
try {
31+
let result = await pubnub.fetchSpace({
32+
spaceId: spaceId
33+
});
34+
35+
this.removeStatus = result.status;
36+
} catch (e: any) {
37+
this.errorMessage = e.message;
38+
}
39+
});
40+
41+
Then('I get get a space not found error', async function() {
42+
expect(this.errorMessage).to.equal('PubNub call failed, check status for details');
43+
});
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { Given, When, Then } from '@cucumber/cucumber';
2+
import { expect } from 'chai';
3+
4+
Given('the desired space name {string}', async function(spaceName) {
5+
this.spaceNameUpdated = spaceName;
6+
});
7+
8+
When('I update the space', async function() {
9+
let pubnub = this.getPubnub({
10+
publishKey: this.keyset.publishKey,
11+
subscribeKey: this.keyset.subscribeKey
12+
});
13+
14+
let result = await pubnub.updateSpace({
15+
spaceId: this.spaceId,
16+
data: {
17+
name: this.spaceNameUpdated
18+
}
19+
});
20+
expect(result.status).to.equal(200);
21+
this.updatedSpace = result.data;
22+
});
23+
24+
Then('I get an updated space object with', async function() {
25+
expect(this.updatedSpace).to.not.be.undefined;
26+
27+
this.space = this.updatedSpace
28+
});
29+
30+
Then('Updated space name equal to {string}', async function(spaceName) {
31+
expect(spaceName).to.equal(this.updatedSpace.name);
32+
});
33+

test/contract/steps/user/user_create.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Given, When, Then } from '@cucumber/cucumber';
22
import { expect } from 'chai';
33

44
Given('the user ID {string}, name {string}', async function(userId, userName) {
5-
// remember the channel we subscribed to
65
this.userId = userId;
76
this.userName = userName;
87
});

test/contract/steps/user/user_fetch.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Given, When, Then } from '@cucumber/cucumber';
22
import { expect } from 'chai';
33

44
Given('there is a user with ID {string}, name {string}', async function(userId, userName) {
5-
// remember the channel we subscribed to
65
this.userId = userId;
76
this.userName = userName;
87
});
@@ -44,10 +43,10 @@ Then('I get a user object with', async function() {
4443
expect(this.user).to.not.be.undefined;
4544
});
4645

47-
Then('ID equal to {string}', async function(userId) {
46+
Then('User ID equal to {string}', async function(userId) {
4847
expect(userId).to.equal(this.user.id);
4948
});
5049

51-
Then('Name equal to {string}', async function(userName) {
50+
Then('User name equal to {string}', async function(userName) {
5251
expect(userName).to.equal(this.user.name);
5352
});
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { Given, When, Then } from '@cucumber/cucumber';
2+
import { expect } from 'chai';
3+
4+
When('I remove the user', async function() {
5+
let pubnub = this.getPubnub({
6+
publishKey: this.keyset.publishKey,
7+
subscribeKey: this.keyset.subscribeKey
8+
});
9+
10+
let result = await pubnub.removeUser({
11+
userId: this.userId
12+
});
13+
expect(result.status).to.equal(200);
14+
this.user = result.data;
15+
});
16+
17+
Then('I get a null user', async function() {
18+
expect(this.user).to.be.null;
19+
});
20+
21+
When('I attempt to fetch the user {string}', async function(userId) {
22+
// ensure we fetch the existing specified user id
23+
expect(userId).to.equal(this.userId);
24+
25+
let pubnub = this.getPubnub({
26+
publishKey: this.keyset.publishKey,
27+
subscribeKey: this.keyset.subscribeKey
28+
});
29+
30+
try {
31+
let result = await pubnub.fetchUser({
32+
userId: userId
33+
});
34+
35+
this.removeStatus = result.status;
36+
} catch (e: any) {
37+
this.errorMessage = e.message;
38+
}
39+
});
40+
41+
Then('I get get a user not found error', async function() {
42+
expect(this.errorMessage).to.equal('PubNub call failed, check status for details');
43+
});
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { Given, When, Then } from '@cucumber/cucumber';
2+
import { expect } from 'chai';
3+
4+
Given('the desired user name {string}', async function(userName) {
5+
this.userNameUpdated = userName;
6+
});
7+
8+
When('I update the user', async function() {
9+
let pubnub = this.getPubnub({
10+
publishKey: this.keyset.publishKey,
11+
subscribeKey: this.keyset.subscribeKey
12+
});
13+
14+
let result = await pubnub.updateUser({
15+
userId: this.userId,
16+
data: {
17+
name: this.userNameUpdated
18+
}
19+
});
20+
expect(result.status).to.equal(200);
21+
this.updatedUser = result.data;
22+
});
23+
24+
Then('I get an updated user object with', async function() {
25+
expect(this.updatedUser).to.not.be.undefined;
26+
27+
this.user = this.updatedUser
28+
});
29+
30+
Then('Updated user name equal to {string}', async function(userName) {
31+
expect(userName).to.equal(this.updatedUser.name);
32+
});
33+

test/contract/world.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class PubnubWorld extends World{
3434
origin: 'localhost:8090',
3535
ssl: false,
3636
suppressLeaveEvents: true,
37-
logVerbosity: false,
37+
logVerbosity: true,
3838
uuid: 'myUUID'
3939
},
4040
demoKeyset: {

0 commit comments

Comments
 (0)