Download spectrum/api/test/thread/mutations/deleteThread.test.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 2.32 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/spectrum/api/test/thread/mutations/deleteThread.test.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/spectrum/api/test/thread/mutations/deleteThread.test.js
-
curl -L -o deleteThread.test.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/spectrum/api/test/thread/mutations/deleteThread.test.js
2.32 kB
| //@flow | |
| import { request } from '../../utils'; | |
| import db from 'shared/testing/db'; | |
| import data from 'shared/testing/data'; | |
| const defaultThread = data.threads[0]; | |
| const owner = data.users.find(({ username }) => username === 'mxstbr'); | |
| const member = data.users.find(({ username }) => username === 'brian'); | |
| const noPermissionUser = data.users.find( | |
| ({ username }) => username === 'bad-boy' | |
| ); | |
| // before each test, makre sure the thread exists to test deletion | |
| beforeEach(async () => { | |
| const threadExists = await db | |
| .table('threads') | |
| .get(defaultThread.id) | |
| .run(); | |
| if (threadExists.deletedAt) { | |
| return db | |
| .table('threads') | |
| .get(defaultThread.id) | |
| .update({ | |
| deletedAt: db.literal(), | |
| }) | |
| .run(); | |
| } | |
| }); | |
| const variables = { | |
| threadId: defaultThread.id, | |
| }; | |
| it('should be able to delete self-published thread', async () => { | |
| const query = /* GraphQL */ ` | |
| mutation deleteThread($threadId: ID!) { | |
| deleteThread (threadId: $threadId) | |
| }, | |
| `; | |
| const context = { | |
| user: member, | |
| }; | |
| expect.assertions(1); | |
| const result = await request(query, { context, variables }); | |
| expect(result).toMatchSnapshot(); | |
| }); | |
| it('should be able to delete thread if user owns community', async () => { | |
| const query = /* GraphQL */ ` | |
| mutation deleteThread($threadId: ID!) { | |
| deleteThread (threadId: $threadId) | |
| }, | |
| `; | |
| const context = { | |
| user: owner, | |
| }; | |
| expect.assertions(1); | |
| const result = await request(query, { context, variables }); | |
| expect(result).toMatchSnapshot(); | |
| }); | |
| it("should not delete thread if user doesn't have permissions", async () => { | |
| const query = /* GraphQL */ ` | |
| mutation deleteThread($threadId: ID!) { | |
| deleteThread (threadId: $threadId) | |
| }, | |
| `; | |
| const context = { | |
| user: noPermissionUser, | |
| }; | |
| expect.assertions(1); | |
| const result = await request(query, { context, variables }); | |
| expect(result).toMatchSnapshot(); | |
| }); | |
| it('should not delete thread if user is not signed in', async () => { | |
| const query = /* GraphQL */ ` | |
| mutation deleteThread($threadId: ID!) { | |
| deleteThread (threadId: $threadId) | |
| }, | |
| `; | |
| const context = { | |
| user: null, | |
| }; | |
| expect.assertions(1); | |
| const result = await request(query, { context, variables }); | |
| expect(result).toMatchSnapshot(); | |
| }); | |