Download spectrum/api/test/community/mutations/editCommunity.test.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 2.06 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/spectrum/api/test/community/mutations/editCommunity.test.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/spectrum/api/test/community/mutations/editCommunity.test.js
-
curl -L -o editCommunity.test.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/spectrum/api/test/community/mutations/editCommunity.test.js
2.06 kB
| //@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(); | |
| }); | |