Skip to content

Commit 158218d

Browse files
Merge branch 'master' into vishal/thread_participants_type
2 parents 9633387 + f0ec15b commit 158218d

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

test/integration/channels.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,98 @@ describe('Channels - members', function () {
570570
);
571571
});
572572
});
573+
574+
describe('leave channel permissions', () => {
575+
const minimalPermissions = [
576+
{
577+
action: 'Allow',
578+
name: 'Channel member permissions',
579+
resources: ['ReadChannel', 'CreateChannel'],
580+
roles: ['channel_member'],
581+
owner: false,
582+
priority: 70,
583+
},
584+
{
585+
action: 'Allow',
586+
name: 'Users can create channels',
587+
resources: ['CreateChannel'],
588+
roles: ['user'],
589+
owner: false,
590+
priority: 60,
591+
},
592+
{
593+
action: 'Deny',
594+
name: 'deny all policy',
595+
resources: ['*'],
596+
roles: ['*'],
597+
owner: false,
598+
priority: 1,
599+
},
600+
];
601+
let ssClient;
602+
let client;
603+
const user = uuidv4();
604+
before(async () => {
605+
ssClient = getTestClient(true);
606+
client = await getTestClientForUser(user);
607+
});
608+
it('no permissions to leave', async () => {
609+
const type = uuidv4();
610+
await ssClient.createChannelType({
611+
name: type,
612+
permissions: minimalPermissions,
613+
});
614+
const channel = client.channel(type, uuidv4(), { members: [user] });
615+
await channel.create();
616+
await expectHTTPErrorCode(403, channel.removeMembers([user]));
617+
});
618+
it('leave channel with RemoveOwnChannelMembership', async () => {
619+
const type = uuidv4();
620+
const permissions = minimalPermissions;
621+
permissions[0].resources = [
622+
...permissions[0].resources,
623+
'RemoveOwnChannelMembership',
624+
];
625+
await ssClient.createChannelType({
626+
name: type,
627+
permissions,
628+
});
629+
const channel = client.channel(type, uuidv4(), { members: [user] });
630+
await channel.create();
631+
await channel.removeMembers([user]);
632+
});
633+
it('leave channel with RemoveOwnChannelMembership', async () => {
634+
const type = uuidv4();
635+
const permissions = minimalPermissions;
636+
permissions[0].resources = [
637+
...permissions[0].resources,
638+
'UpdateChannelMembers',
639+
];
640+
await ssClient.createChannelType({
641+
name: type,
642+
permissions,
643+
});
644+
const channel = client.channel(type, uuidv4(), { members: [user] });
645+
await channel.create();
646+
await channel.removeMembers([user]);
647+
});
648+
it('leave channel with RemoveOwnChannelMembership and UpdateChannelMembers', async () => {
649+
const type = uuidv4();
650+
const permissions = minimalPermissions;
651+
permissions[0].resources = [
652+
...permissions[0].resources,
653+
'RemoveOwnChannelMembership',
654+
'UpdateChannelMembers',
655+
];
656+
await ssClient.createChannelType({
657+
name: type,
658+
permissions,
659+
});
660+
const channel = client.channel(type, uuidv4(), { members: [user] });
661+
await channel.create();
662+
await channel.removeMembers([user]);
663+
});
664+
});
573665
});
574666

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

0 commit comments

Comments
 (0)