File size: 3,260 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
//@flow
import { request } from '../../utils';
import db from 'shared/testing/db';
import data from 'shared/testing/data';
// various permissions for Spectrum community
const owner = data.users.find(({ username }) => username === 'mxstbr');
const moderator = data.users.find(({ username }) => username === 'brian');
const noPermissionUser = data.users.find(({ username }) => username === 'bryn');
afterEach(() => {
return db
.table('channels')
.filter({ slug: 'test-channel' })
.delete()
.run();
});
const variables = {
input: {
name: 'test channel',
slug: 'test-channel',
description: 'test description',
isPrivate: false,
isDefault: false,
communityId: 'ce2b4488-4c75-47e0-8ebc-2539c1e6a191',
},
};
it('should create a channel if user is owner', async () => {
const query = /* GraphQL */ `
mutation createChannel($input: CreateChannelInput!) {
createChannel (input: $input) {
name
slug
description
isPrivate
}
},
`;
const context = {
user: owner,
};
expect.assertions(1);
const result = await request(query, { context, variables });
expect(result).toMatchSnapshot();
});
it('should prevent duplicate channel slugs in the same community', async () => {
const query = /* GraphQL */ `
mutation createChannel($input: CreateChannelInput!) {
createChannel (input: $input) {
id
name
slug
description
isPrivate
createdAt
}
},
`;
const context = {
user: owner,
};
expect.assertions(1);
const result = await request(query, {
context,
variables: {
input: {
...variables.input,
slug: 'general',
},
},
});
expect(result).toMatchSnapshot();
});
it('should prevent signed out users from creating a channel', async () => {
const query = /* GraphQL */ `
mutation createChannel($input: CreateChannelInput!) {
createChannel (input: $input) {
id
name
slug
description
isPrivate
createdAt
}
},
`;
const context = {
user: null,
};
expect.assertions(1);
const result = await request(query, { context, variables });
expect(result).toMatchSnapshot();
});
it('should prevent non owners from creating a channel', async () => {
const query = /* GraphQL */ `
mutation createChannel($input: CreateChannelInput!) {
createChannel (input: $input) {
id
name
slug
description
isPrivate
createdAt
}
},
`;
const context = {
user: noPermissionUser,
};
expect.assertions(1);
const result = await request(query, { context, variables });
expect(result).toMatchSnapshot();
});
it('should prevent moderators from creating a channel', async () => {
const query = /* GraphQL */ `
mutation createChannel($input: CreateChannelInput!) {
createChannel (input: $input) {
id
name
slug
description
isPrivate
createdAt
}
},
`;
const context = {
user: moderator,
};
expect.assertions(1);
const result = await request(query, { context, variables });
expect(result).toMatchSnapshot();
});
|