fix: empty file tags cause upload error for some providers (#7300)

* fix: empty file tags cause upload error for some providers

DigitalOcean and Linode object storage solutions do not accept `tags` option while uploading a file. Previously, tags option was set to default empty object. Now, we do not include it if it is empty.

* chore: add tests for saving a file with/without tags

* chore: update file tags handling to make tests pass

* chore: refactor file tag tests

* chore: update file tag tests

* chore: update changelog

* chore: update changelog entry

* chore: remove duplicated changelog entry
This commit is contained in:
Ali Oğuzhan Yıldız
2021-04-02 18:29:46 +03:00
committed by GitHub
parent 626352d594
commit 4d167026ae
3 changed files with 40 additions and 4 deletions

View File

@@ -3,6 +3,7 @@
'use strict';
const { FilesController } = require('../lib/Controllers/FilesController');
const request = require('../lib/request');
const str = 'Hello World!';
@@ -205,6 +206,34 @@ describe('Parse.File testing', () => {
notEqual(file.name(), 'hello.txt');
});
it('saves the file with tags', async () => {
spyOn(FilesController.prototype, 'createFile').and.callThrough();
const file = new Parse.File('hello.txt', data, 'text/plain');
const tags = { hello: 'world' };
file.setTags(tags);
expect(file.url()).toBeUndefined();
const result = await file.save();
expect(file.name()).toBeDefined();
expect(file.url()).toBeDefined();
expect(result.tags()).toEqual(tags);
expect(FilesController.prototype.createFile.calls.argsFor(0)[4]).toEqual({
tags: tags,
metadata: {},
});
});
it('does not pass empty file tags while saving', async () => {
spyOn(FilesController.prototype, 'createFile').and.callThrough();
const file = new Parse.File('hello.txt', data, 'text/plain');
expect(file.url()).toBeUndefined();
expect(file.name()).toBeDefined();
await file.save();
expect(file.url()).toBeDefined();
expect(FilesController.prototype.createFile.calls.argsFor(0)[4]).toEqual({
metadata: {},
});
});
it('save file in object', async done => {
const file = new Parse.File('hello.txt', data, 'text/plain');
ok(!file.url());