|
| 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 | +}); |
0 commit comments