Skip to content

Commit

Permalink
Improve and fix /api/v1/(channels/groups).roles tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cardoso committed Apr 27, 2018
1 parent 361ffe1 commit 436cc6c
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 8 deletions.
63 changes: 59 additions & 4 deletions tests/end-to-end/api/02-channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -629,17 +629,72 @@ describe('[Channels]', function() {
});

describe('/channels.roles', () => {
it('should return an array of roles by channel', (done) => {
let testChannel;
it('/channels.create', (done) => {
request.post(api('channels.create'))
.set(credentials)
.send({
name: `channel.roles.test.${ Date.now() }`
})
.end((err, res) => {
testChannel = res.body.channel;
done();
});
});
it('/channels.invite', async(done) => {
request.post(api('channels.invite'))
.set(credentials)
.send({
roomId: testChannel._id,
userId: 'rocket.cat'
})
.end(done);
});
it('/channels.addModerator', (done) => {
request.post(api('channels.addModerator'))
.set(credentials)
.send({
roomId: testChannel._id,
userId: 'rocket.cat'
})
.end(done);
});
it('/channels.addLeader', (done) => {
request.post(api('channels.addLeader'))
.set(credentials)
.send({
roomId: testChannel._id,
userId: 'rocket.cat'
})
.end(done);
});
it('should return an array of role <-> user relationships in a channel', (done) => {
request.get(api('channels.roles'))
.set(credentials)
.query({
roomId: channel._id
roomId: testChannel._id
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('roles').and.to.be.an('array');
expect(res.body).to.have.a.property('success', true);
expect(res.body).to.have.a.property('roles').that.is.an('array').that.has.lengthOf(2);

expect(res.body.roles[0]).to.have.a.property('_id').that.is.a('string');
expect(res.body.roles[0]).to.have.a.property('rid').that.is.equal(testChannel._id);
expect(res.body.roles[0]).to.have.a.property('roles').that.is.an('array').that.includes('moderator', 'leader');
expect(res.body.roles[0]).to.have.a.property('u').that.is.an('object');
expect(res.body.roles[0].u).to.have.a.property('_id').that.is.a('string');
expect(res.body.roles[0].u).to.have.a.property('username').that.is.a('string');
expect(res.body.roles[0].u).to.have.a.property('name');

expect(res.body.roles[1]).to.have.a.property('_id').that.is.a('string');
expect(res.body.roles[1]).to.have.a.property('rid').that.is.equal(testChannel._id);
expect(res.body.roles[1]).to.have.a.property('roles').that.is.an('array').that.includes('owner');
expect(res.body.roles[1]).to.have.a.property('u').that.is.an('object');
expect(res.body.roles[1].u).to.have.a.property('_id').that.is.a('string');
expect(res.body.roles[1].u).to.have.a.property('username').that.is.a('string');
expect(res.body.roles[1].u).to.have.a.property('name');
})
.end(done);
});
Expand Down
63 changes: 59 additions & 4 deletions tests/end-to-end/api/03-groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,17 +467,72 @@ describe('groups', function() {
});

describe('/groups.roles', () => {
it('should return an array of roles for a private group', (done) => {
let testGroup;
it('/groups.create', (done) => {
request.post(api('groups.create'))
.set(credentials)
.send({
name: `group.roles.test.${ Date.now() }`
})
.end((err, res) => {
testGroup = res.body.group;
done();
});
});
it('/groups.invite', async(done) => {
request.post(api('groups.invite'))
.set(credentials)
.send({
roomId: testGroup._id,
userId: 'rocket.cat'
})
.end(done);
});
it('/groups.addModerator', (done) => {
request.post(api('groups.addModerator'))
.set(credentials)
.send({
roomId: testGroup._id,
userId: 'rocket.cat'
})
.end(done);
});
it('/groups.addLeader', (done) => {
request.post(api('groups.addLeader'))
.set(credentials)
.send({
roomId: testGroup._id,
userId: 'rocket.cat'
})
.end(done);
});
it('should return an array of roles <-> user relationships in a private group', (done) => {
request.get(api('groups.roles'))
.set(credentials)
.query({
roomId: group._id
roomId: testGroup._id
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('roles').and.to.be.an('array');
expect(res.body).to.have.a.property('success', true);
expect(res.body).to.have.a.property('roles').that.is.an('array').that.has.lengthOf(2);

expect(res.body.roles[0]).to.have.a.property('_id').that.is.a('string');
expect(res.body.roles[0]).to.have.a.property('rid').that.is.equal(testGroup._id);
expect(res.body.roles[0]).to.have.a.property('roles').that.is.an('array').that.includes('moderator', 'leader');
expect(res.body.roles[0]).to.have.a.property('u').that.is.an('object');
expect(res.body.roles[0].u).to.have.a.property('_id').that.is.a('string');
expect(res.body.roles[0].u).to.have.a.property('username').that.is.a('string');
expect(res.body.roles[0].u).to.have.a.property('name');

expect(res.body.roles[1]).to.have.a.property('_id').that.is.a('string');
expect(res.body.roles[1]).to.have.a.property('rid').that.is.equal(testGroup._id);
expect(res.body.roles[1]).to.have.a.property('roles').that.is.an('array').that.includes('owner');
expect(res.body.roles[1]).to.have.a.property('u').that.is.an('object');
expect(res.body.roles[1].u).to.have.a.property('_id').that.is.a('string');
expect(res.body.roles[1].u).to.have.a.property('username').that.is.a('string');
expect(res.body.roles[1].u).to.have.a.property('name');
})
.end(done);
});
Expand Down

0 comments on commit 436cc6c

Please sign in to comment.