|
| 1 | +import { Given, When, Then } from '@cucumber/cucumber'; |
| 2 | +import { expect } from 'chai'; |
| 3 | + |
| 4 | +Given('there is a user with ID {string}, name {string}', async function(userId, userName) { |
| 5 | + // remember the channel we subscribed to |
| 6 | + this.userId = userId; |
| 7 | + this.userName = userName; |
| 8 | +}); |
| 9 | + |
| 10 | +When('I fetch the user {string}', async function(userId) { |
| 11 | + // ensure we fetch the existing specified user id |
| 12 | + expect(userId).to.equal(this.userId); |
| 13 | + |
| 14 | + let pubnub = this.getPubnub({ |
| 15 | + publishKey: this.keyset.publishKey, |
| 16 | + subscribeKey: this.keyset.subscribeKey |
| 17 | + }); |
| 18 | + |
| 19 | + let result = await pubnub.fetchUser({ |
| 20 | + userId: userId |
| 21 | + }); |
| 22 | + expect(result.status).to.equal(200); |
| 23 | + this.user = result.data; |
| 24 | +}); |
| 25 | + |
| 26 | +When('I fetch all users', async function() { |
| 27 | + let pubnub = this.getPubnub({ |
| 28 | + publishKey: this.keyset.publishKey, |
| 29 | + subscribeKey: this.keyset.subscribeKey |
| 30 | + }); |
| 31 | + |
| 32 | + let result = await pubnub.fetchUsers(); |
| 33 | + expect(result.status).to.equal(200); |
| 34 | + this.users = result.data; |
| 35 | +}); |
| 36 | + |
| 37 | +Then('I get a list of user objects', async function() { |
| 38 | + expect(this.users).to.not.be.undefined; |
| 39 | + |
| 40 | + this.user = this.users[0]; |
| 41 | +}); |
| 42 | + |
| 43 | +Then('I get a user object with', async function() { |
| 44 | + expect(this.user).to.not.be.undefined; |
| 45 | +}); |
| 46 | + |
| 47 | +Then('ID equal to {string}', async function(userId) { |
| 48 | + expect(userId).to.equal(this.user.id); |
| 49 | +}); |
| 50 | + |
| 51 | +Then('Name equal to {string}', async function(userName) { |
| 52 | + expect(userName).to.equal(this.user.name); |
| 53 | +}); |
0 commit comments