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(getgalleryinfo): added tests and handler mocks for getGalleryInfo
- Loading branch information
Showing
2 changed files
with
64 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,52 @@ | ||
const imgur = require('../lib/imgur.js'); | ||
|
||
beforeAll(() => imgur.setClientId('abc123')); | ||
|
||
describe('getGalleryInfo', () => { | ||
describe('get gallery info response', () => { | ||
test('should fail when id is not passed', () => { | ||
const errMsg = 'Invalid gallery ID'; | ||
expect(imgur.getGalleryInfo()).rejects.toThrowError(errMsg); | ||
}); | ||
|
||
test('gallery info is returned', async () => { | ||
const resp = await imgur.getGalleryInfo('JK9ybyj'); | ||
expect(resp).toMatchInlineSnapshot(` | ||
Object { | ||
"description": "gallery-description", | ||
"id": "JK9ybyj", | ||
"title": "gallery-title", | ||
} | ||
`); | ||
}); | ||
}); | ||
|
||
describe("delegates to _imgurRequest('gallery', ...)", () => { | ||
const mockResult = { | ||
data: [], | ||
params: { | ||
id: 'JK9ybyj', | ||
}, | ||
}; | ||
const payload = 'JK9ybyj'; | ||
const _imgurRequestBackup = imgur._imgurRequest; | ||
|
||
beforeEach(() => { | ||
imgur._imgurRequest = jest | ||
.fn() | ||
.mockImplementation(() => Promise.resolve(mockResult)); | ||
}); | ||
|
||
afterEach(() => { | ||
imgur._imgurRequest.mockClear(); | ||
imgur._imgurRequest = _imgurRequestBackup; | ||
}); | ||
|
||
it('should delegate', () => { | ||
const promise = imgur.getGalleryInfo('JK9ybyj'); | ||
|
||
expect(imgur._imgurRequest).toHaveBeenCalledWith('gallery', payload); | ||
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