mirror of
https://github.com/strapi/strapi.git
synced 2025-08-20 06:38:46 +00:00
* Implement deleteFile graphql mutation (#5292). Signed-off-by: François de Metz <francois@2metz.fr> * Test if the file exist before removing it. Signed-off-by: François de Metz <francois@2metz.fr> * Fix a typo. Signed-off-by: François de Metz <francois@2metz.fr>
This commit is contained in:
parent
6bc8662ff6
commit
645c0b8cf4
@ -58,7 +58,7 @@ describe('Single type Graphql support', () => {
|
||||
afterAll(() => modelsUtils.deleteContentType('home-page'), 60000);
|
||||
|
||||
describe('Queries', () => {
|
||||
test('No list avaialble', async () => {
|
||||
test('No list available', async () => {
|
||||
const res = await graphqlQuery({
|
||||
query: /* GraphQL */ `
|
||||
{
|
||||
|
@ -24,7 +24,6 @@ module.exports = {
|
||||
Mutation: {
|
||||
createFile: false,
|
||||
updateFile: false,
|
||||
deleteFile: false,
|
||||
upload: {
|
||||
description: 'Upload one file',
|
||||
resolverOf: 'plugins::upload.upload.upload',
|
||||
@ -57,6 +56,17 @@ module.exports = {
|
||||
return await strapi.plugins.upload.services.upload.updateFileInfo(id, info);
|
||||
},
|
||||
},
|
||||
deleteFile: {
|
||||
description: 'Delete one file',
|
||||
resolverOf: 'plugins::upload.upload.destroy',
|
||||
resolver: async (obj, options, { context }) => {
|
||||
const file = await strapi.plugins.upload.services.upload.fetch({ id: context.params.id });
|
||||
if (file) {
|
||||
const fileResult = await strapi.plugins.upload.services.upload.remove(file);
|
||||
return { file: fileResult };
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
@ -147,4 +147,64 @@ describe('Upload plugin end to end tests', () => {
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test('Delete a file', async () => {
|
||||
const res = await rq({
|
||||
url: '/graphql',
|
||||
method: 'POST',
|
||||
body: {
|
||||
query: /* GraphQL */ `
|
||||
mutation removeFile($id: ID!) {
|
||||
deleteFile(input: { where: { id: $id } }) {
|
||||
file {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
variables: {
|
||||
id: data.file.id,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(200);
|
||||
expect(res.body).toMatchObject({
|
||||
data: {
|
||||
deleteFile: {
|
||||
file: {
|
||||
id: data.file.id,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test('Delete a file that dont exist', async () => {
|
||||
const res = await rq({
|
||||
url: '/graphql',
|
||||
method: 'POST',
|
||||
body: {
|
||||
query: /* GraphQL */ `
|
||||
mutation removeFile($id: ID!) {
|
||||
deleteFile(input: { where: { id: $id } }) {
|
||||
file {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
variables: {
|
||||
id: '404',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(200);
|
||||
expect(res.body).toMatchObject({
|
||||
data: {
|
||||
deleteFile: null,
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user