mirror of
https://github.com/strapi/strapi.git
synced 2025-12-26 14:44:31 +00:00
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:
parent
4987c1dbd9
commit
7baad9bbfd
@ -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);
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@ -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',
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user