Skip to content

Commit 4fe8bdd

Browse files
authored
test: step definitions for objectsV2 featureSet (pubnub#292)
* contract tests step definitions for objectsV2 featureSet * reafctor: step clause and file name
1 parent 23493d7 commit 4fe8bdd

File tree

8 files changed

+384
-4
lines changed

8 files changed

+384
-4
lines changed

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"contract:test": "cucumber-js --require dist/cucumber dist/contract/contract/features --tags 'not @na=js and not @beta'",
2424
"contract:test-beta": "cucumber-js --require dist/cucumber dist/contract/contract/features --tags 'not @na=js and @beta'",
2525
"contract:test-access": "cucumber-js --require dist/cucumber dist/contract/contract/features --tags '@featureSet=access and not @na=js and not @beta'",
26+
"contract:test-objectsV2": "cucumber-js --require dist/cucumber dist/contract/contract/features --tags '@featureSet=objectsV2 and not @na=js and not @beta'",
2627
"contract:test-access-beta": "cucumber-js --require dist/cucumber dist/contract/contract/features --tags '@featureSet=access and not @na=js and @beta'"
2728
},
2829
"main": "./lib/node/index.js",
+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import { When, Then, Given } from '@cucumber/cucumber';
2+
import { expect } from 'chai';
3+
4+
Given('the id for {string} channel', function (channel) {
5+
const channelMetadata = this.getFixture(channel);
6+
this.parameter = { ...this.parameter, channel: channelMetadata.id };
7+
});
8+
9+
Given('the data for {string} channel', async function (channel) {
10+
const channelMetadata = this.getFixture(channel);
11+
this.parameter = {
12+
...this.parameter,
13+
channel: channelMetadata.id,
14+
data: {
15+
name: channelMetadata.name,
16+
description: channelMetadata.description,
17+
type: channelMetadata.type,
18+
status: channelMetadata.status,
19+
},
20+
};
21+
});
22+
23+
When('I get the channel metadata', async function () {
24+
const pubnub = await this.getPubnub({
25+
publishKey: this.keyset.publishKey,
26+
subscribeKey: this.keyset.subscribeKey,
27+
});
28+
this.response = await pubnub.objects.getChannelMetadata({ ...this.parameter, include: { customFields: false } });
29+
});
30+
31+
When('I set the channel metadata', async function () {
32+
const pubnub = await this.getPubnub({
33+
publishKey: this.keyset.publishKey,
34+
subscribeKey: this.keyset.subscribeKey,
35+
});
36+
37+
this.response = await pubnub.objects.setChannelMetadata(this.parameter);
38+
});
39+
40+
When('I remove the channel metadata', async function () {
41+
const pubnub = await this.getPubnub({
42+
publishKey: this.keyset.publishKey,
43+
subscribeKey: this.keyset.subscribeKey,
44+
});
45+
46+
this.response = await pubnub.objects.removeChannelMetadata(this.parameter);
47+
});
48+
49+
Then('the channel metadata for {string} channel', function (channel) {
50+
const actual = this.response.data;
51+
const expected = this.getFixture(channel);
52+
expect(actual).to.deep.equal(expected);
53+
});
54+
55+
Then('the channel metadata for {string} channel contains updated', function (channel) {
56+
const actual = this.response.data;
57+
const expected = this.getFixture(channel);
58+
expect(actual).to.deep.equal(expected);
59+
});
60+
61+
When('I get the channel metadata with custom', async function () {
62+
const pubnub = await this.getPubnub({
63+
publishKey: this.keyset.publishKey,
64+
subscribeKey: this.keyset.subscribeKey,
65+
});
66+
this.response = await pubnub.objects.getChannelMetadata({ ...this.parameter, include: { customFields: true } });
67+
});
68+
69+
When('I get all channel metadata', async function () {
70+
const pubnub = await this.getPubnub({
71+
publishKey: this.keyset.publishKey,
72+
subscribeKey: this.keyset.subscribeKey,
73+
});
74+
75+
this.response = await pubnub.objects.getAllChannelMetadata();
76+
});
77+
78+
Then('the response contains list with {string} and {string} channel metadata', function (firstChannel, secondChannel) {
79+
const firstChannelData = this.getFixture(firstChannel);
80+
const secondChannelData = this.getFixture(secondChannel);
81+
const actual = this.response.data;
82+
expect(actual).to.have.lengthOf(2);
83+
expect(actual).to.deep.include(firstChannelData);
84+
expect(actual).to.deep.include(secondChannelData);
85+
});
86+
87+
When('I get all channel metadata with custom', async function () {
88+
const pubnub = await this.getPubnub({
89+
publishKey: this.keyset.publishKey,
90+
subscribeKey: this.keyset.subscribeKey,
91+
});
92+
93+
this.response = await pubnub.objects.getAllChannelMetadata({ include: { customFields: true } });
94+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { When, Then, Given } from '@cucumber/cucumber';
2+
import { expect } from 'chai';
3+
4+
Given('the data for {string} member', function (member) {
5+
const memberData = this.getFixture(member);
6+
this.parameter = { ...this.parameter, uuids: [{ id: memberData.uuid.id, custom: memberData.custom }] };
7+
});
8+
9+
When('I get the channel members', async function () {
10+
const pubnub = await this.getPubnub({
11+
publishKey: this.keyset.publishKey,
12+
subscribeKey: this.keyset.subscribeKey,
13+
});
14+
this.response = await pubnub.objects.getChannelMembers(this.parameter);
15+
});
16+
17+
When('I get the channel members including custom and UUID custom information', async function () {
18+
const pubnub = await this.getPubnub({
19+
publishKey: this.keyset.publishKey,
20+
subscribeKey: this.keyset.subscribeKey,
21+
});
22+
this.response = await pubnub.objects.getChannelMembers({
23+
...this.parameter,
24+
include: { customFields: true, customUUIDFields: true },
25+
});
26+
});
27+
28+
When('I set a channel member', async function () {
29+
const pubnub = await this.getPubnub({
30+
publishKey: this.keyset.publishKey,
31+
subscribeKey: this.keyset.subscribeKey,
32+
});
33+
this.response = await pubnub.objects.setChannelMembers(this.parameter);
34+
});
35+
36+
When('I set a channel member including custom and UUID with custom', async function () {
37+
const pubnub = await this.getPubnub({
38+
publishKey: this.keyset.publishKey,
39+
subscribeKey: this.keyset.subscribeKey,
40+
});
41+
this.response = await pubnub.objects.setChannelMembers({
42+
...this.parameter,
43+
include: { customFields: true, customUUIDFields: true },
44+
});
45+
});
46+
47+
Then('the response contains list with {string} and {string} members', function (firstMember, secondMember) {
48+
const actual = this.response.data;
49+
const firstMemberData = this.getFixture(firstMember);
50+
const secondMemberData = this.getFixture(secondMember);
51+
expect(actual).to.deep.include(firstMemberData);
52+
expect(actual).to.deep.include(secondMemberData);
53+
});
54+
55+
Then('the response contains list with {string} member', function (member) {
56+
const actual = this.response.data;
57+
const memberData = this.getFixture(member);
58+
expect(actual).to.deep.include(memberData);
59+
});
60+
61+
When('I remove a channel member', async function () {
62+
const pubnub = await this.getPubnub({
63+
publishKey: this.keyset.publishKey,
64+
subscribeKey: this.keyset.subscribeKey,
65+
});
66+
this.response = await pubnub.objects.removeChannelMembers(this.parameter);
67+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { When, Then, Given } from '@cucumber/cucumber';
2+
import { expect } from 'chai';
3+
4+
Given('the data for {string} membership', function (membership) {
5+
const membershipData = this.getFixture(membership);
6+
this.parameter = { ...this.parameter, channels: [{ id: membershipData.channel.id }] };
7+
});
8+
9+
When('I set the membership', async function () {
10+
const pubnub = await this.getPubnub({
11+
publishKey: this.keyset.publishKey,
12+
subscribeKey: this.keyset.subscribeKey,
13+
});
14+
this.response = await pubnub.objects.setMemberships(this.parameter);
15+
});
16+
17+
When('I get the memberships', async function () {
18+
const pubnub = await this.getPubnub({
19+
publishKey: this.keyset.publishKey,
20+
subscribeKey: this.keyset.subscribeKey,
21+
});
22+
this.response = await pubnub.objects.getMemberships(this.parameter);
23+
});
24+
25+
When('I get the memberships for current user', async function () {
26+
const pubnub = await this.getPubnub({
27+
publishKey: this.keyset.publishKey,
28+
subscribeKey: this.keyset.subscribeKey,
29+
uuid: this.currentUuid,
30+
});
31+
this.response = await pubnub.objects.getMemberships();
32+
});
33+
34+
When('I get the memberships including custom and channel custom information', async function (){
35+
const pubnub = await this.getPubnub({
36+
publishKey: this.keyset.publishKey,
37+
subscribeKey: this.keyset.subscribeKey,
38+
});
39+
this.response = await pubnub.objects.getMemberships({
40+
...this.parameter,
41+
include: { customFields: true, customChannelFields: true },
42+
});
43+
});
44+
45+
When('I set the membership for current user', async function () {
46+
const pubnub = await this.getPubnub({
47+
publishKey: this.keyset.publishKey,
48+
subscribeKey: this.keyset.subscribeKey,
49+
uuid: this.currentUuid,
50+
});
51+
this.response = await pubnub.objects.setMemberships(this.parameter);
52+
});
53+
54+
When('I remove the membership', async function () {
55+
const pubnub = await this.getPubnub({
56+
publishKey: this.keyset.publishKey,
57+
subscribeKey: this.keyset.subscribeKey,
58+
});
59+
this.response = await pubnub.objects.removeMemberships(this.parameter);
60+
});
61+
62+
When('I remove the membership for current user', async function () {
63+
const pubnub = await this.getPubnub({
64+
publishKey: this.keyset.publishKey,
65+
subscribeKey: this.keyset.subscribeKey,
66+
uuid: this.currentUuid,
67+
});
68+
this.response = await pubnub.objects.removeMemberships(this.parameter);
69+
});
70+
71+
Then('the response contains list with {string} and {string} memberships', function (firstMembership, secondMembership) {
72+
const actual = this.response.data;
73+
const firstMembershipData = this.getFixture(firstMembership);
74+
const secondMembershipData = this.getFixture(secondMembership);
75+
expect(actual).to.deep.include(firstMembershipData);
76+
expect(actual).to.deep.include(secondMembershipData);
77+
});
78+
79+
Then('the response contains list with {string} membership', function (membership) {
80+
const actual = this.response.data;
81+
const membershipData = this.getFixture(membership);
82+
expect(actual).to.deep.include(membershipData);
83+
});

test/contract/steps/objectsv2/uuid.ts

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import { When, Then, Given } from '@cucumber/cucumber';
2+
import { expect } from 'chai';
3+
4+
Given('I have a keyset with Objects V2 enabled', function () {
5+
this.keyset = this.fixtures.demoKeyset;
6+
});
7+
8+
Given('the id for {string} persona', async function (persona) {
9+
const user = this.getFixture(persona);
10+
this.parameter = { ...this.parameter, uuid: user.id };
11+
});
12+
13+
Given('the data for {string} persona', async function (persona) {
14+
const user = this.getFixture(persona);
15+
this.parameter = {
16+
...this.parameter,
17+
uuid: user.id,
18+
data: {
19+
name: user.name,
20+
email: user.email,
21+
custom: user.custom,
22+
externalId: user.externalId,
23+
profileUrl: user.profileUrl,
24+
},
25+
};
26+
});
27+
28+
Given('current user is {string} persona', async function (persona) {
29+
this.currentUuid = this.getFixture(persona).id;
30+
});
31+
32+
When('I get the UUID metadata', async function () {
33+
const pubnub = await this.getPubnub({
34+
publishKey: this.keyset.publishKey,
35+
subscribeKey: this.keyset.subscribeKey,
36+
});
37+
this.response = await pubnub.objects.getUUIDMetadata(this.parameter);
38+
});
39+
40+
When('I set the UUID metadata', async function () {
41+
const pubnub = await this.getPubnub({
42+
publishKey: this.keyset.publishKey,
43+
subscribeKey: this.keyset.subscribeKey,
44+
});
45+
46+
this.response = await pubnub.objects.setUUIDMetadata(this.parameter);
47+
});
48+
49+
When('I get the UUID metadata with custom for current user', async function () {
50+
const pubnub = await this.getPubnub({
51+
publishKey: this.keyset.publishKey,
52+
subscribeKey: this.keyset.subscribeKey,
53+
uuid: this.currentUuid,
54+
});
55+
this.response = await pubnub.objects.getUUIDMetadata({ incldue: { customFields: true } });
56+
});
57+
58+
When('I remove the UUID metadata', async function () {
59+
const pubnub = await this.getPubnub({
60+
publishKey: this.keyset.publishKey,
61+
subscribeKey: this.keyset.subscribeKey,
62+
});
63+
64+
this.response = await pubnub.objects.removeUUIDMetadata(this.parameter);
65+
});
66+
67+
When('I remove the UUID metadata for current user', async function () {
68+
const pubnub = await this.getPubnub({
69+
publishKey: this.keyset.publishKey,
70+
subscribeKey: this.keyset.subscribeKey,
71+
uuid: this.currentUuid,
72+
});
73+
74+
this.response = await pubnub.objects.removeUUIDMetadata();
75+
});
76+
77+
When('I get all UUID metadata', async function () {
78+
const pubnub = await this.getPubnub({
79+
publishKey: this.keyset.publishKey,
80+
subscribeKey: this.keyset.subscribeKey,
81+
});
82+
83+
this.response = await pubnub.objects.getAllUUIDMetadata();
84+
});
85+
86+
When('I get all UUID metadata with custom', async function () {
87+
const pubnub = await this.getPubnub({
88+
publishKey: this.keyset.publishKey,
89+
subscribeKey: this.keyset.subscribeKey,
90+
});
91+
92+
this.response = await pubnub.objects.getAllUUIDMetadata({ include: { customFields: true } });
93+
});
94+
95+
Then('the UUID metadata for {string} persona', async function (persona) {
96+
const actual = this.response.data;
97+
const expected = this.getFixture(persona);
98+
expect(actual).to.deep.equal(expected);
99+
});
100+
101+
Then('the UUID metadata for {string} persona contains updated', async function (persona) {
102+
const actual = this.response.data;
103+
const expected = this.getFixture(persona);
104+
expect(actual).to.deep.equal(expected);
105+
});
106+
107+
Then('I receive a successful response', function () {
108+
expect(this.response.status).to.equal(200);
109+
});
110+
111+
Then('the response contains list with {string} and {string} UUID metadata', function (firstPersona, secondPersona) {
112+
const firstPersonaData = this.getFixture(firstPersona);
113+
const secondPersonaData = this.getFixture(secondPersona);
114+
const actual = this.response.data;
115+
expect(actual).to.have.lengthOf(2);
116+
expect(actual).to.deep.include(firstPersonaData);
117+
expect(actual).to.deep.include(secondPersonaData);
118+
});

test/contract/utils.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import fs from 'fs';
2+
3+
export function loadFixtureFile(persona) {
4+
const fileData = fs.readFileSync(
5+
`${process.cwd()}/dist/contract/contract/features/data/${persona.toLowerCase()}.json`,
6+
'utf8',
7+
);
8+
return JSON.parse(fileData);
9+
}

0 commit comments

Comments
 (0)