diff --git a/lib/stack/asset/index.js b/lib/stack/asset/index.js index 6de9eb9d..dbb06f9f 100644 --- a/lib/stack/asset/index.js +++ b/lib/stack/asset/index.js @@ -292,7 +292,11 @@ export function createFormData (data) { formData.append('asset[title]', data.title) } const uploadStream = createReadStream(data.upload) - formData.append('asset[upload]', uploadStream) + if (typeof data.content_type === 'string') { + formData.append('asset[upload]', uploadStream, { contentType: data.content_type }) + } else { + formData.append('asset[upload]', uploadStream) + } return formData } } diff --git a/test/api/asset-test.js b/test/api/asset-test.js index 78f91fce..0a534fa6 100644 --- a/test/api/asset-test.js +++ b/test/api/asset-test.js @@ -90,6 +90,30 @@ describe('Assets api Test', () => { }) .catch(done) }) + + it('Asset Upload in folder with contenttype', done => { + const asset = { + upload: path.join(__dirname, './mock/berries.jfif'), + title: 'customasset2 in Folder', + description: 'Custom Asset Desc in Folder', + parent_uid: folderUID, + tags: 'folder', + content_type: 'image/jpeg' + } + makeAsset().create(asset) + .then((asset) => { + publishAssetUID = asset.uid + expect(asset.uid).to.be.not.equal(null) + expect(asset.url).to.be.not.equal(null) + expect(asset.filename).to.be.equal('berries.jfif') + expect(asset.title).to.be.equal('customasset2 in Folder') + expect(asset.description).to.be.equal('Custom Asset Desc in Folder') + expect(asset.content_type).to.be.equal('image/jpeg') + expect(asset.parent_uid).to.be.equal(folderUID) + done() + }) + .catch(done) + }) it('Replace asset ', done => { const asset = { upload: path.join(__dirname, './mock/upload.html') diff --git a/test/api/mock/berries.jfif b/test/api/mock/berries.jfif new file mode 100644 index 00000000..f0e4c1a0 Binary files /dev/null and b/test/api/mock/berries.jfif differ diff --git a/test/unit/asset-test.js b/test/unit/asset-test.js index 184db299..30176aa2 100644 --- a/test/unit/asset-test.js +++ b/test/unit/asset-test.js @@ -154,7 +154,8 @@ describe('Contentstack Asset test', () => { title: 'customasset', description: 'Custom Asset Desc', tags: ['Custom'], - parent_uid: 'UID' + parent_uid: 'UID', + content_type: 'text/html' } const form = createFormData(assetUpload)() var boundary = form.getBoundary() @@ -322,7 +323,7 @@ function makeAsset (data) { function checkAsset (asset) { checkSystemFields(asset) - expect(asset.content_type).to.be.equal('image/png') + expect(asset.content_type).to.be.equal('text/html') expect(asset.file_size).to.be.equal('42670') expect(asset.tags.length).to.be.equal(0) expect(asset.filename).to.be.equal('file.png') diff --git a/test/unit/mock/objects.js b/test/unit/mock/objects.js index 0948d14f..95833432 100644 --- a/test/unit/mock/objects.js +++ b/test/unit/mock/objects.js @@ -212,7 +212,7 @@ const releaseMock = { const assetMock = { ...systemFieldsMock, ...systemFieldsUserMock, - content_type: 'image/png', + content_type: 'text/html', file_size: '42670', tags: [], filename: 'file.png', diff --git a/test/unit/user-test.js b/test/unit/user-test.js index 2d0c6318..13d599b3 100644 --- a/test/unit/user-test.js +++ b/test/unit/user-test.js @@ -162,26 +162,25 @@ describe('Contentstack User test', () => { }) user.getTasks() - .then((userTasks) => { - const assignment = userTasks.asassignments - expect(assignment.api_key).to.be.equal(stackHeadersMock.api_key) - expect(assignment.content_type).to.be.equal("CT_UID") - expect(assignment.entry_uid).to.be.equal("ETR_UID") - expect(assignment.locale).to.be.equal("en-us") - expect(assignment.org_uid).to.be.equal("orgUID") - expect(assignment.type).to.be.equal("workflow_stage") - expect(assignment.entry_locale).to.be.equal("en-us") - expect(assignment.version).to.be.equal(1) - expect(assignment.assigned_to[0]).to.be.equal("user_UID") - expect(assignment.assigned_at).to.be.equal("assign_date") - expect(assignment.assigned_by).to.be.equal("assign_by") - expect(assignment.due_date).to.be.equal("due_date") - done() - }) - .catch(done) + .then((userTasks) => { + const assignment = userTasks.asassignments + expect(assignment.api_key).to.be.equal(stackHeadersMock.api_key) + expect(assignment.content_type).to.be.equal('CT_UID') + expect(assignment.entry_uid).to.be.equal('ETR_UID') + expect(assignment.locale).to.be.equal('en-us') + expect(assignment.org_uid).to.be.equal('orgUID') + expect(assignment.type).to.be.equal('workflow_stage') + expect(assignment.entry_locale).to.be.equal('en-us') + expect(assignment.version).to.be.equal(1) + expect(assignment.assigned_to[0]).to.be.equal('user_UID') + expect(assignment.assigned_at).to.be.equal('assign_date') + expect(assignment.assigned_by).to.be.equal('assign_by') + expect(assignment.due_date).to.be.equal('due_date') + done() + }) + .catch(done) }) - it('User get task with params test', done => { var mock = new MockAdapter(Axios) mock.onGet('/user/assignments').reply(200, { @@ -194,24 +193,24 @@ describe('Contentstack User test', () => { } }) - user.getTasks({sort: 'sort'}) - .then((userTasks) => { - const assignment = userTasks.asassignments - expect(assignment.api_key).to.be.equal(stackHeadersMock.api_key) - expect(assignment.content_type).to.be.equal("CT_UID") - expect(assignment.entry_uid).to.be.equal("ETR_UID") - expect(assignment.locale).to.be.equal("en-us") - expect(assignment.org_uid).to.be.equal("orgUID") - expect(assignment.type).to.be.equal("workflow_stage") - expect(assignment.entry_locale).to.be.equal("en-us") - expect(assignment.version).to.be.equal(1) - expect(assignment.assigned_to[0]).to.be.equal("user_UID") - expect(assignment.assigned_at).to.be.equal("assign_date") - expect(assignment.assigned_by).to.be.equal("assign_by") - expect(assignment.due_date).to.be.equal("due_date") - done() - }) - .catch(done) + user.getTasks({ sort: 'sort' }) + .then((userTasks) => { + const assignment = userTasks.asassignments + expect(assignment.api_key).to.be.equal(stackHeadersMock.api_key) + expect(assignment.content_type).to.be.equal('CT_UID') + expect(assignment.entry_uid).to.be.equal('ETR_UID') + expect(assignment.locale).to.be.equal('en-us') + expect(assignment.org_uid).to.be.equal('orgUID') + expect(assignment.type).to.be.equal('workflow_stage') + expect(assignment.entry_locale).to.be.equal('en-us') + expect(assignment.version).to.be.equal(1) + expect(assignment.assigned_to[0]).to.be.equal('user_UID') + expect(assignment.assigned_at).to.be.equal('assign_date') + expect(assignment.assigned_by).to.be.equal('assign_by') + expect(assignment.due_date).to.be.equal('due_date') + done() + }) + .catch(done) }) })