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

Commit

Permalink
fix: specify type in uploadBase64
Browse files Browse the repository at this point in the history
fix #178
  • Loading branch information
kaimallea committed Apr 26, 2021
1 parent 84f6f40 commit 819a38f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
50 changes: 50 additions & 0 deletions __tests__/uploadBase64.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const imgur = require('../lib/imgur.js');

describe('uploadBase64()', () => {
describe('validation', () => {
test('should fail with input', () => {
const errMsg = 'Invalid Base64 input';

expect(imgur.uploadBase64()).rejects.toThrowError(errMsg);
});
});

describe("delegates to _imgurRequest('upload', ...)", () => {
const mockResult = { foo: 'bar' };
const testImage =
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==';

const _imgurRequestBackup = imgur._imgurRequest;

beforeEach(() => {
imgur._imgurRequest = jest
.fn()
.mockImplementation(() => Promise.resolve(mockResult));
});

afterEach(() => {
imgur._imgurRequest.mockClear();
imgur._imgurRequest = _imgurRequestBackup;
});

test('should delegate', () => {
const promise = imgur.uploadBase64(testImage);

expect(imgur._imgurRequest).toHaveBeenCalledWith('upload', testImage, {
type: 'base64',
});
expect(promise).resolves.toEqual(mockResult);
});

test('should propagate albumId', () => {
const albumId = '123';
const promise = imgur.uploadBase64(testImage, albumId);

expect(imgur._imgurRequest).toHaveBeenCalledWith('upload', testImage, {
album: albumId,
type: 'base64',
});
expect(promise).resolves.toEqual(mockResult);
});
});
});
2 changes: 1 addition & 1 deletion lib/imgur.js
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ imgur.uploadUrl = async (url, albumId, title, description) => {
* @returns {promise} - on resolve, returns the resulting image object from imgur
*/
imgur.uploadBase64 = async (base64, albumId, title, description) => {
const extraFormParams = {};
const extraFormParams = { type: 'base64' };

if (typeof albumId === 'string' && albumId.length) {
extraFormParams.album = albumId;
Expand Down

0 comments on commit 819a38f

Please sign in to comment.