tests: cleanup common variables
This commit is contained in:
+18
-18
@@ -13,7 +13,7 @@ const BoxError = require('../boxerror.js'),
|
||||
safe = require('safetydance');
|
||||
|
||||
describe('Groups', function () {
|
||||
const { setup, cleanup, ADMIN, USER } = common;
|
||||
const { setup, cleanup, admin, user } = common;
|
||||
|
||||
before(setup);
|
||||
after(cleanup);
|
||||
@@ -84,21 +84,21 @@ describe('Groups', function () {
|
||||
});
|
||||
|
||||
it('isMember returns false', async function () {
|
||||
const isMember = await groups.isMember(group0Object.id, ADMIN.id);
|
||||
const isMember = await groups.isMember(group0Object.id, admin.id);
|
||||
expect(isMember).to.be(false);
|
||||
});
|
||||
|
||||
it('can add member to the group', async function () {
|
||||
await groups.addMember(group0Object.id, ADMIN.id);
|
||||
await groups.addMember(group0Object.id, admin.id);
|
||||
});
|
||||
|
||||
it('cannot add same member to the group', async function () {
|
||||
const [error] = await safe(groups.addMember(group0Object.id, ADMIN.id));
|
||||
const [error] = await safe(groups.addMember(group0Object.id, admin.id));
|
||||
expect(error.reason).to.be(BoxError.ALREADY_EXISTS);
|
||||
});
|
||||
|
||||
it('isMember returns true', async function () {
|
||||
const isMember = await groups.isMember(group0Object.id, ADMIN.id);
|
||||
const isMember = await groups.isMember(group0Object.id, admin.id);
|
||||
expect(isMember).to.be(true);
|
||||
});
|
||||
|
||||
@@ -108,22 +108,22 @@ describe('Groups', function () {
|
||||
});
|
||||
|
||||
it('cannot add non-existent group', async function () {
|
||||
const [error] = await safe(groups.addMember('randomgroup', ADMIN.id));
|
||||
const [error] = await safe(groups.addMember('randomgroup', admin.id));
|
||||
expect(error.reason).to.be(BoxError.NOT_FOUND);
|
||||
});
|
||||
|
||||
it('can set members', async function () {
|
||||
await groups.setMembers(group0Object.id, [ ADMIN.id, USER.id ]);
|
||||
await groups.setMembers(group0Object.id, [ admin.id, user.id ]);
|
||||
});
|
||||
|
||||
it('cannot set duplicate members', async function () {
|
||||
const [error] = await safe(groups.setMembers(group0Object.id, [ ADMIN.id, USER.id, ADMIN.id ]));
|
||||
const [error] = await safe(groups.setMembers(group0Object.id, [ admin.id, user.id, admin.id ]));
|
||||
expect(error.reason).to.be(BoxError.CONFLICT);
|
||||
});
|
||||
|
||||
it('can list users of group', async function () {
|
||||
const result = await groups.getMembers(group0Object.id);
|
||||
expect(result).to.eql([ ADMIN.id, USER.id ]);
|
||||
expect(result).to.eql([ admin.id, user.id ]);
|
||||
});
|
||||
|
||||
it('cannot list members of non-existent group', async function () {
|
||||
@@ -137,35 +137,35 @@ describe('Groups', function () {
|
||||
});
|
||||
|
||||
it('cannot remove member from non-existent group', async function () {
|
||||
const [error] = await safe(groups.removeMember('randomgroup', ADMIN.id));
|
||||
const [error] = await safe(groups.removeMember('randomgroup', admin.id));
|
||||
expect(error.reason).to.be(BoxError.NOT_FOUND);
|
||||
});
|
||||
|
||||
it('can remove existing member', async function () {
|
||||
await groups.removeMember(group0Object.id, USER.id);
|
||||
await groups.removeMember(group0Object.id, user.id);
|
||||
});
|
||||
|
||||
it('can getWithMembers', async function () {
|
||||
const result = await groups.getWithMembers(group0Object.id);
|
||||
expect(result.name).to.be(group0Name);
|
||||
expect(result.userIds).to.eql([ ADMIN.id ]);
|
||||
expect(result.userIds).to.eql([ admin.id ]);
|
||||
});
|
||||
|
||||
it('can set groups', async function () {
|
||||
await groups.setMembership(ADMIN.id, [ group0Object.id ]);
|
||||
await groups.setMembership(admin.id, [ group0Object.id ]);
|
||||
});
|
||||
|
||||
it('cannot set user to same group twice', async function () {
|
||||
const [error] = await safe(groups.setMembership(ADMIN.id, [ group0Object.id, group0Object.id ]));
|
||||
const [error] = await safe(groups.setMembership(admin.id, [ group0Object.id, group0Object.id ]));
|
||||
expect(error.reason).to.be(BoxError.CONFLICT);
|
||||
});
|
||||
|
||||
it('can set user to multiple groups', async function () {
|
||||
await groups.setMembership(ADMIN.id, [ group0Object.id, group1Object.id ]);
|
||||
await groups.setMembership(admin.id, [ group0Object.id, group1Object.id ]);
|
||||
});
|
||||
|
||||
it('can get groups membership', async function () {
|
||||
const groupIds = await groups.getMembership(ADMIN.id);
|
||||
const groupIds = await groups.getMembership(admin.id);
|
||||
expect(groupIds.length).to.be(2);
|
||||
expect(groupIds.sort()).to.eql([ group0Object.id, group1Object.id ].sort());
|
||||
});
|
||||
@@ -181,7 +181,7 @@ describe('Groups', function () {
|
||||
const result = await groups.listWithMembers();
|
||||
expect(result.length).to.be(2);
|
||||
expect(result[0].name).to.be(group0Name);
|
||||
expect(result[1].userIds).to.eql([ ADMIN.id ]);
|
||||
expect(result[1].userIds).to.eql([ admin.id ]);
|
||||
expect(result[1].name).to.be(group1Name);
|
||||
});
|
||||
|
||||
@@ -191,7 +191,7 @@ describe('Groups', function () {
|
||||
});
|
||||
|
||||
it('can delete valid group', async function () {
|
||||
await groups.setMembers(group0Object.id, [ ADMIN.id, USER.id ]); // ensure group has some members
|
||||
await groups.setMembers(group0Object.id, [ admin.id, user.id ]); // ensure group has some members
|
||||
await groups.remove(group0Object.id);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user