Skip to content
This repository has been archived by the owner on Jan 12, 2021. It is now read-only.

Commit

Permalink
fix: Remove overwrite from payload when false
Browse files Browse the repository at this point in the history
Fixes #23
  • Loading branch information
bengourley committed Aug 1, 2018
1 parent 4b1b0d0 commit 4d11f1a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,14 @@ function prepareRequest(options) {
case 'tempDir': {
break;
}
case 'overwrite': {
// the presence of any value for this flag causes the API to interpret it as
// true, so only add it to the payload if it is truthy
if (options.overwrite) {
formData[name] = String(value);
}
break;
}
// Basic fields (strings/booleans) & future fields
default: {
formData[name] = String(value);
Expand Down
10 changes: 10 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const stripProjectRoot = require('./index').stripProjectRoot
const upload = require('./index').upload
const validateOptions = require('./index').validateOptions
const prepareRequest = require('./index').prepareRequest

test('upload function exists', () => {
expect(typeof upload).toBe('function');
Expand Down Expand Up @@ -71,3 +72,12 @@ describe('validateOptions', () => {
}).toThrow('You must provide a path to the source map you want to upload.');
});
});

describe('prepareRequest', () => {
test('removes options.overwrite when false', () => {
expect(prepareRequest({ overwrite: false }).formData).toEqual({});
});
test('does not remove options.overwrite when true', () => {
expect(prepareRequest({ overwrite: true }).formData).toEqual({ overwrite: 'true' });
});
});

0 comments on commit 4d11f1a

Please sign in to comment.