Commit 9d90d5a3 authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Merge branch '347483-corpus-upload-zip-fix' into 'master'

Corpus Management Fix corrupt file upload (unreleased feature)

See merge request gitlab-org/gitlab!76870
parents 71becb2a 3a46ff4e
...@@ -19,13 +19,7 @@ export function publishPackage( ...@@ -19,13 +19,7 @@ export function publishPackage(
status: 'default', status: 'default',
}; };
const formData = new FormData(); return axios.put(url, files[0], {
formData.append('file', files[0]);
return axios.put(url, formData, {
headers: {
'Content-Type': 'multipart/form-data',
},
params: Object.assign(defaults, options), params: Object.assign(defaults, options),
...axiosOptions, ...axiosOptions,
}); });
......
...@@ -73,7 +73,7 @@ export default { ...@@ -73,7 +73,7 @@ export default {
cache.writeQuery({ query: getCorpusesQuery, data: targetData, variables: { projectPath } }); cache.writeQuery({ query: getCorpusesQuery, data: targetData, variables: { projectPath } });
publishPackage( publishPackage(
{ projectPath, name, version: 0, fileName: name, files }, { projectPath, name, version: 0, fileName: `${name}.zip`, files },
{ status: 'hidden', select: 'package_file' }, { status: 'hidden', select: 'package_file' },
{ onUploadProgress, cancelToken: source.token }, { onUploadProgress, cancelToken: source.token },
) )
......
...@@ -38,12 +38,17 @@ describe('Api', () => { ...@@ -38,12 +38,17 @@ describe('Api', () => {
mock.onPut(expectedUrl).replyOnce(httpStatus.OK, apiResponse); mock.onPut(expectedUrl).replyOnce(httpStatus.OK, apiResponse);
return publishPackage( return publishPackage(
{ projectPath, name, version: 0, fileName: name, files: [{}] }, {
projectPath,
name,
version: 0,
fileName: name,
files: [new File(['zip contents'], 'bar.zip')],
},
{ status: 'hidden', select: 'package_file' }, { status: 'hidden', select: 'package_file' },
).then(({ data }) => { ).then(({ data }) => {
expect(data).toEqual(apiResponse); expect(data).toEqual(apiResponse);
expect(axios.put).toHaveBeenCalledWith(expectedUrl, expect.any(FormData), { expect(axios.put).toHaveBeenCalledWith(expectedUrl, expect.any(File), {
headers: { 'Content-Type': 'multipart/form-data' },
params: { select: 'package_file', status: 'hidden' }, params: { select: 'package_file', status: 'hidden' },
}); });
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment