Skip to content

Commit

Permalink
[CHAT-1510] Add more leave channel permission tests (GetStream#571)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnatolyRugalev authored Jan 4, 2021
1 parent 7db7855 commit f0ec15b
Showing 1 changed file with 92 additions and 0 deletions.
92 changes: 92 additions & 0 deletions test/integration/channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,98 @@ describe('Channels - members', function () {
);
});
});

describe('leave channel permissions', () => {
const minimalPermissions = [
{
action: 'Allow',
name: 'Channel member permissions',
resources: ['ReadChannel', 'CreateChannel'],
roles: ['channel_member'],
owner: false,
priority: 70,
},
{
action: 'Allow',
name: 'Users can create channels',
resources: ['CreateChannel'],
roles: ['user'],
owner: false,
priority: 60,
},
{
action: 'Deny',
name: 'deny all policy',
resources: ['*'],
roles: ['*'],
owner: false,
priority: 1,
},
];
let ssClient;
let client;
const user = uuidv4();
before(async () => {
ssClient = getTestClient(true);
client = await getTestClientForUser(user);
});
it('no permissions to leave', async () => {
const type = uuidv4();
await ssClient.createChannelType({
name: type,
permissions: minimalPermissions,
});
const channel = client.channel(type, uuidv4(), { members: [user] });
await channel.create();
await expectHTTPErrorCode(403, channel.removeMembers([user]));
});
it('leave channel with RemoveOwnChannelMembership', async () => {
const type = uuidv4();
const permissions = minimalPermissions;
permissions[0].resources = [
...permissions[0].resources,
'RemoveOwnChannelMembership',
];
await ssClient.createChannelType({
name: type,
permissions,
});
const channel = client.channel(type, uuidv4(), { members: [user] });
await channel.create();
await channel.removeMembers([user]);
});
it('leave channel with RemoveOwnChannelMembership', async () => {
const type = uuidv4();
const permissions = minimalPermissions;
permissions[0].resources = [
...permissions[0].resources,
'UpdateChannelMembers',
];
await ssClient.createChannelType({
name: type,
permissions,
});
const channel = client.channel(type, uuidv4(), { members: [user] });
await channel.create();
await channel.removeMembers([user]);
});
it('leave channel with RemoveOwnChannelMembership and UpdateChannelMembers', async () => {
const type = uuidv4();
const permissions = minimalPermissions;
permissions[0].resources = [
...permissions[0].resources,
'RemoveOwnChannelMembership',
'UpdateChannelMembers',
];
await ssClient.createChannelType({
name: type,
permissions,
});
const channel = client.channel(type, uuidv4(), { members: [user] });
await channel.create();
await channel.removeMembers([user]);
});
});
});

it('channel messages and last_message_at are correctly returned', async function () {
Expand Down

0 comments on commit f0ec15b

Please sign in to comment.