Update file info mutation (#7691)

* added new updateFileInfo mutation

Signed-off-by: Omar Garcia <omarcruz11@hotmail.com>

* added test

Signed-off-by: Omar Garcia <omarcruz11@hotmail.com>

* fixed test

Signed-off-by: Omar Garcia <omarcruz11@hotmail.com>

* Added fileInfoInput

Signed-off-by: Omar Garcia <omarcruz11@hotmail.com>
This commit is contained in:
Cr0s4k 2020-09-03 12:17:40 +02:00 committed by GitHub
parent 4987c1dbd9
commit 7baad9bbfd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 0 deletions

View File

@ -2,9 +2,17 @@ const _ = require('lodash');
const { streamToBuffer } = require('../utils/file');
module.exports = {
definition: `
input FileInfoInput {
name: String
alternativeText: String
caption: String
}
`,
mutation: `
upload(refId: ID, ref: String, field: String, source: String, file: Upload!): UploadFile!
multipleUpload(refId: ID, ref: String, field: String, source: String, files: [Upload]!): [UploadFile]!
updateFileInfo(id: ID!, info: FileInfoInput!): UploadFile!
`,
resolver: {
Query: {
@ -42,6 +50,13 @@ module.exports = {
return Promise.all(files.map(file => uploadService.uploadFileAndPersist(file)));
},
},
updateFileInfo: {
description: 'Update file information',
resolverOf: 'plugins::upload.upload.upload',
resolver: async (obj, { id, info }) => {
return await strapi.plugins.upload.services.upload.updateFileInfo(id, info);
},
},
},
},
};

View File

@ -27,6 +27,8 @@ const setConfigOptions = assign => {
});
};
const data = {};
describe('Upload plugin end to end tests', () => {
beforeAll(async () => {
const token = await registerAndLogin();
@ -79,6 +81,8 @@ describe('Upload plugin end to end tests', () => {
},
},
});
data.file = res.body.data.upload;
});
test('Upload multiple files', async () => {
@ -128,4 +132,43 @@ describe('Upload plugin end to end tests', () => {
},
});
});
test('Update file information', async () => {
const res = await rq({
url: '/graphql',
method: 'POST',
body: {
query: /* GraphQL */ `
mutation updateFileInfo($id: ID!, $info: FileInfoInput!) {
updateFileInfo(id: $id, info: $info) {
id
name
alternativeText
caption
}
}
`,
variables: {
id: data.file.id,
info: {
name: 'test name',
alternativeText: 'alternative text test',
caption: 'caption test',
},
},
},
});
expect(res.statusCode).toBe(200);
expect(res.body).toMatchObject({
data: {
updateFileInfo: {
id: data.file.id,
name: 'test name',
alternativeText: 'alternative text test',
caption: 'caption test',
},
},
});
});
});