This repository has been archived by the owner on Dec 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #179 from kaimallea/fix-uploadBase64
fix: specify type in uploadBase64
- Loading branch information
Showing
2 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters