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

Commit 76eae8a

Browse files
authored
Merge pull request #179 from kaimallea/fix-uploadBase64
fix: specify type in uploadBase64
2 parents 6db7b5e + 66f1401 commit 76eae8a

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

__tests__/uploadBase64.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
const imgur = require('../lib/imgur.js');
2+
3+
describe('uploadBase64()', () => {
4+
describe('validation', () => {
5+
test('should fail with input', () => {
6+
const errMsg = 'Invalid Base64 input';
7+
8+
expect(imgur.uploadBase64()).rejects.toThrowError(errMsg);
9+
});
10+
});
11+
12+
describe("delegates to _imgurRequest('upload', ...)", () => {
13+
const mockResult = { foo: 'bar' };
14+
const testImage =
15+
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==';
16+
17+
const _imgurRequestBackup = imgur._imgurRequest;
18+
19+
beforeEach(() => {
20+
imgur._imgurRequest = jest
21+
.fn()
22+
.mockImplementation(() => Promise.resolve(mockResult));
23+
});
24+
25+
afterEach(() => {
26+
imgur._imgurRequest.mockClear();
27+
imgur._imgurRequest = _imgurRequestBackup;
28+
});
29+
30+
test('should delegate', () => {
31+
const promise = imgur.uploadBase64(testImage);
32+
33+
expect(imgur._imgurRequest).toHaveBeenCalledWith('upload', testImage, {
34+
type: 'base64',
35+
});
36+
expect(promise).resolves.toEqual(mockResult);
37+
});
38+
39+
test('should propagate albumId', () => {
40+
const albumId = '123';
41+
const promise = imgur.uploadBase64(testImage, albumId);
42+
43+
expect(imgur._imgurRequest).toHaveBeenCalledWith('upload', testImage, {
44+
album: albumId,
45+
type: 'base64',
46+
});
47+
expect(promise).resolves.toEqual(mockResult);
48+
});
49+
});
50+
});

lib/imgur.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ imgur.uploadUrl = async (url, albumId, title, description) => {
579579
* @returns {promise} - on resolve, returns the resulting image object from imgur
580580
*/
581581
imgur.uploadBase64 = async (base64, albumId, title, description) => {
582-
const extraFormParams = {};
582+
const extraFormParams = { type: 'base64' };
583583

584584
if (typeof albumId === 'string' && albumId.length) {
585585
extraFormParams.album = albumId;

0 commit comments

Comments
 (0)