Skip to content

Instantly share code, notes, and snippets.

@ioncreature
Created November 30, 2016 15:28
Show Gist options
  • Save ioncreature/6335d58972e0dc7e78516283a3919e4d to your computer and use it in GitHub Desktop.
Save ioncreature/6335d58972e0dc7e78516283a3919e4d to your computer and use it in GitHub Desktop.
'use strict';
/**
* @namespace Glip.EndToEndTests.Groups.Remove
*/
/**
* @testcase Notification Group removed.
* @memberOf Glip.EndToEndTests.Groups.Remove
* @id GL-15524
* @keywords E2E
* @summary
* Goal: Current user is subscribed to group notifications.
* Using SEXIO Client remove for current user private team.
*/
const test = require('./lib/run-test');
test('GL-15524', {
description: 'Subscribe user to to group notifications.',
rcAccountScenario: 'pla_glip_10us'
}).run(async (log, company) => {
/**
* @step
* // action
* Get 4 random user ids from RC Account as primary and other users
* // result
* Got primary and other users
*/
let rcIds = company.getRandomUserIds(4);
log(`Got user ids: ${rcIds}`);
/**
* @step
* // action
* Authorize all users in Platform and Glip1
* // result
* All users authorized in Platform and Glip1
*/
let users = await company.getUsers(rcIds);
log(`Authorize users ${rcIds} in Platform and Glip1`);
let [primaryUser, ...otherUsers] = await Promise.all(users.map(u => u.authorize()));
let glipIds = users.map(u => u.glipId);
log('Users successfully authorized');
/**
* @step
* // action
* Create PubNub subscription for primary user
* // result
* Primary user subscribed to PubNub
*/
log(`Creating PubNub subscription for primary user (rcId=${primaryUser.rcId}, glipId= ${primaryUser.glipId}`);
await primaryUser.subscribeToPubNub();
log('Made subscription to PubNub');
/**
* @step
* // action
* Create a private team on behalf of the primary user in order to delete it after
* // result
* Team created
*/
log(`Creating group for glip users: ${glipIds}`);
let PrivateTeam = await primaryUser.glip1.team.create(`TestTeam_${Date.now()}`, glipIds);
log(`Created team (id={${PrivateTeam._id})`);
/**
* @step
* // action
* Expect PubNub notification got by the primary user
* // result
* Complete test if sufficient notification received, fail test otherwise
*/
log('Expecting PubNub notification for the primary user');
let expectMessage = primaryUser.expectPubNubMessage(message => {
const body = message.body;
return (
body.messageType === 'GroupRemoved' &&
body.group.id === PrivateTeam._id
);
});
/**
* @step
* // action
* Delete a private team on behalf of the primary user in order to get Notification
* // result
* Team deleted, notification generated
*/
log(`Delete group for glip users: [${glipIds}] by ${primaryUser.glipId}`);
let delPrivateTeam = primaryUser.glip1.team.del(PrivateTeam._id).then(p => log('Group deleted', p));
await Promise.all([expectMessage, delPrivateTeam]);
log('Successfully received PubNub notification');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment