forked from dan1elhughes/forecast-promise
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dan Hughes
committed
Aug 2, 2018
1 parent
0630e55
commit 263f957
Showing
2 changed files
with
39 additions
and
3 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
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 |
---|---|---|
@@ -1,5 +1,41 @@ | ||
const axios = require('axios'); | ||
const Forecast = require('./index'); | ||
|
||
jest.mock('axios'); | ||
|
||
const MOCK_CREDENTIALS = { | ||
accountId: 'mock__accountId', | ||
token: 'mock__token', | ||
}; | ||
|
||
describe('forecast-promise', () => { | ||
it('passes dummy test', () => { | ||
expect(true).toBe(true); | ||
it('crashes with no input', () => { | ||
expect(() => new Forecast()).toThrow( | ||
'Forecast module requires accountId and token to be configured.' | ||
); | ||
}); | ||
|
||
it('crashes with only one input', () => { | ||
expect( | ||
() => new Forecast({ accountId: MOCK_CREDENTIALS.accountId }) | ||
).toThrow('Forecast module requires accountId and token to be configured.'); | ||
|
||
expect(() => new Forecast({ token: MOCK_CREDENTIALS.token })).toThrow( | ||
'Forecast module requires accountId and token to be configured.' | ||
); | ||
}); | ||
|
||
it('instantiates axios with valid input', () => { | ||
axios.create.mockImplementation(args => args); | ||
const f = new Forecast(MOCK_CREDENTIALS); | ||
|
||
expect(f.instance).toEqual({ | ||
baseURL: 'https://api.forecastapp.com/', | ||
headers: { | ||
Authorization: `Bearer ${MOCK_CREDENTIALS.token}`, | ||
'Forecast-Account-Id': MOCK_CREDENTIALS.accountId, | ||
'User-Agent': 'https://www.npmjs.com/package/forecast-promise', | ||
}, | ||
}); | ||
}); | ||
}); |