-
Notifications
You must be signed in to change notification settings - Fork 28
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 #14 from enduire/apikey-auth
Use temporary pull-request token for PRs from forks
- Loading branch information
Showing
7 changed files
with
108 additions
and
20 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
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
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,11 @@ | ||
import React from 'react'; | ||
|
||
export default [ | ||
{ | ||
component: 'Bar', | ||
variants: { | ||
one: () => <div>one</div>, | ||
two: () => <div>two</div>, | ||
}, | ||
}, | ||
]; |
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,36 +1,67 @@ | ||
import requireRelative from 'require-relative'; | ||
import request from 'request-promise-native'; | ||
|
||
import RemoteBrowserTarget from '../src/RemoteBrowserTarget'; | ||
import loadUserConfig from '../src/loadUserConfig'; | ||
|
||
jest.mock('request-promise-native'); | ||
jest.mock('require-relative'); | ||
|
||
it('yells if api tokens are missing', () => { | ||
it('yells if api tokens are missing', async () => { | ||
requireRelative.mockImplementation(() => ({})); | ||
expect(() => loadUserConfig('bogus')).toThrowError(/You need an `apiKey`/); | ||
await expect(loadUserConfig('bogus')).rejects.toThrow(/You need an `apiKey`/); | ||
}); | ||
|
||
it('yells if targets are missing', () => { | ||
it('yells if targets are missing', async () => { | ||
requireRelative.mockImplementation(() => ({ | ||
apiKey: '1', | ||
apiSecret: '2', | ||
targets: {}, | ||
})); | ||
expect(() => loadUserConfig('bogus')).toThrowError(/You need at least one target/); | ||
await expect(loadUserConfig('bogus')).rejects.toThrow(/You need at least one target/); | ||
}); | ||
|
||
it('does not yell if all required things are in place', () => { | ||
it('does not yell if all required things are in place', async () => { | ||
requireRelative.mockImplementation(() => ({ | ||
apiKey: '1', | ||
apiSecret: '2', | ||
targets: { | ||
firefox: new RemoteBrowserTarget('firefox', { viewport: '800x600' }), | ||
}, | ||
})); | ||
expect(() => loadUserConfig('bogus')).not.toThrowError(); | ||
expect(loadUserConfig('bogus').apiKey).toEqual('1'); | ||
expect(loadUserConfig('bogus').apiSecret).toEqual('2'); | ||
expect(loadUserConfig('bogus').targets).toEqual({ | ||
const config = await loadUserConfig('bogus'); | ||
expect(config.apiKey).toEqual('1'); | ||
expect(config.apiSecret).toEqual('2'); | ||
expect(config.targets).toEqual({ | ||
firefox: new RemoteBrowserTarget('firefox', { viewport: '800x600' }), | ||
}); | ||
}); | ||
|
||
describe('when CHANGE_URL is defined', () => { | ||
beforeEach(() => { | ||
requireRelative.mockImplementation(() => ({ | ||
targets: { | ||
firefox: new RemoteBrowserTarget('firefox', { viewport: '800x600' }), | ||
}, | ||
})); | ||
request.mockImplementation(() => Promise.resolve({ secret: 'yay' })); | ||
}); | ||
|
||
it('grabs a temporary secret', async () => { | ||
const config = await loadUserConfig('bogus', { CHANGE_URL: 'foo.bar' }); | ||
expect(config.apiKey).toEqual('foo.bar'); | ||
expect(config.apiSecret).toEqual('yay'); | ||
}); | ||
|
||
describe('when the API has an error response', () => { | ||
beforeEach(() => { | ||
request.mockImplementation(() => Promise.reject(new Error('nope'))); | ||
}); | ||
|
||
it('yells', async () => { | ||
await expect(loadUserConfig('bogus', { CHANGE_URL: 'foo.bar' })).rejects.toThrow( | ||
/Failed to obtain temporary pull-request token/, | ||
); | ||
}); | ||
}); | ||
}); |