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.
feat(updateinfo): added the updateInfo method and included a new test…
… file for this method The updateInfo method takes a required id and optional title and description parameters. 106
- Loading branch information
Showing
2 changed files
with
90 additions
and
0 deletions.
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,63 @@ | ||
const imgur = require('../lib/imgur.js'); | ||
|
||
describe('updateInfo', () => { | ||
describe('update image metadata', () => { | ||
test('should fail when id is not passed', () => { | ||
const errMsg = 'image id is required'; | ||
expect(imgur.updateInfo()).rejects.toThrowError(errMsg); | ||
}); | ||
|
||
test('should fail when query is passed a boolean', () => { | ||
const errMsg = 'You did not pass a string as an id.'; | ||
expect(imgur.updateInfo(true)).rejects.toThrowError(errMsg); | ||
}); | ||
|
||
test('should fail when id passed is not a string', () => { | ||
const errMsg = 'You did not pass a string as an id.'; | ||
expect(imgur.updateInfo(1)).rejects.toThrowError(errMsg); | ||
}); | ||
}); | ||
|
||
describe("delegates to _imgurRequest('update', ...)", () => { | ||
const mockResult = { | ||
data: [], | ||
params: { | ||
id: 'V8svmob', | ||
title: 'image title', | ||
message: 'image description', | ||
}, | ||
}; | ||
const payload = 'V8svmob'; | ||
const _imgurRequestBackup = imgur._imgurRequest; | ||
|
||
beforeEach(() => { | ||
imgur._imgurRequest = jest | ||
.fn() | ||
.mockImplementation(() => Promise.resolve(mockResult)); | ||
}); | ||
|
||
afterEach(() => { | ||
imgur._imgurRequest.mockClear(); | ||
imgur._imgurRequest = _imgurRequestBackup; | ||
}); | ||
|
||
it('should delegate', () => { | ||
const params = { | ||
title: 'image title', | ||
description: 'image description', | ||
}; | ||
const promise = imgur.updateInfo( | ||
'V8svmob', | ||
params.title, | ||
params.description | ||
); | ||
|
||
expect(imgur._imgurRequest).toHaveBeenCalledWith( | ||
'update', | ||
payload, | ||
params | ||
); | ||
expect(promise).resolves.toMatchObject(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