File size: 2,062 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 |
//@flow
import { request } from '../../utils';
import db from 'shared/testing/db';
import data from 'shared/testing/data';
// various permissions for Spectrum community
const community = data.communities[0];
const owner = data.users.find(({ username }) => username === 'mxstbr');
const member = data.users.find(({ username }) => username === 'bryn');
afterEach(() => {
return db
.table('communities')
.filter({ slug: 'spectrum' })
.update({
name: community.name,
description: community.description,
})
.run();
});
const variables = {
input: {
name: 'new name',
description: 'new description',
communityId: community.id,
},
};
it('should edit a community name and description', async () => {
const query = /* GraphQL */ `
mutation editCommunity($input: EditCommunityInput!) {
editCommunity (input: $input) {
name
description
}
},
`;
const context = { user: owner };
expect.assertions(3);
const result = await request(query, { context, variables });
expect(result).toMatchSnapshot();
expect(result.data.editCommunity.name).toEqual(variables.input.name);
expect(result.data.editCommunity.description).toEqual(
variables.input.description
);
});
it('should prevent community from being edited by a non owner', async () => {
const query = /* GraphQL */ `
mutation editCommunity($input: EditCommunityInput!) {
editCommunity (input: $input) {
name
description
}
},
`;
const context = { user: member };
expect.assertions(1);
const result = await request(query, { context, variables });
expect(result).toMatchSnapshot();
});
it('should prevent community from being edited by a non user', async () => {
const query = /* GraphQL */ `
mutation editCommunity($input: EditCommunityInput!) {
editCommunity (input: $input) {
name
description
}
},
`;
expect.assertions(1);
const result = await request(query, { variables });
expect(result).toMatchSnapshot();
});
|