-
-
Notifications
You must be signed in to change notification settings - Fork 52
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
Showing
6 changed files
with
114 additions
and
212 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,54 @@ | ||
import test from 'ava'; | ||
import got from 'got'; | ||
import sinon from 'sinon'; | ||
import fetchMock from 'fetch-mock'; | ||
import getClient from './helpers/get-client.js'; | ||
|
||
test.beforeEach('Setup Sinon Sandbox', t => { | ||
test.beforeEach(t => { | ||
fetchMock.reset(); | ||
t.context = { | ||
sandbox: sinon.createSandbox(), | ||
client: getClient(), | ||
}; | ||
}); | ||
|
||
test.afterEach('Reset Sinon Sandbox', t => { | ||
t.context.sandbox.restore(); | ||
}); | ||
|
||
// TODO: Find a better way of handling stubbing, to eliminate the need | ||
// to run tests serially - https://github.com/avajs/ava/issues/295#issuecomment-161123805 | ||
|
||
test.serial('Get uses default projection when not provided', async t => { | ||
t.plan(1); | ||
|
||
const { client, sandbox } = t.context; | ||
const defaultProjection = 'DRAFT'; | ||
|
||
sandbox.stub(got, 'get').callsFake(uri => { | ||
t.is(new URL(uri).searchParams.get('projection'), defaultProjection); | ||
|
||
return { | ||
json: sandbox.stub().resolves({}), | ||
}; | ||
}); | ||
test('Get uses default projection when not provided', async t => { | ||
const { client } = t.context; | ||
|
||
const mock = fetchMock.getOnce('begin:https://www.googleapis.com', {}); | ||
await client.get(undefined, 'token'); | ||
}); | ||
|
||
test.serial('Get does not fetch token when provided', async t => { | ||
const { client, sandbox } = t.context; | ||
|
||
sandbox.stub(got, 'get').callsFake(uri => { | ||
if (uri === 'https://accounts.google.com/o/oauth2/token') { | ||
return t.fail('Token should not have been fetched'); | ||
} | ||
t.is( | ||
mock.lastUrl(), | ||
'https://www.googleapis.com/chromewebstore/v1.1/items/foo?projection=DRAFT', | ||
); | ||
}); | ||
|
||
return { | ||
json: sandbox.stub().resolves({}), | ||
}; | ||
}); | ||
test('Get does not fetch token when provided', async t => { | ||
t.plan(0); | ||
const { client } = t.context; | ||
|
||
fetchMock.getOnce('begin:https://www.googleapis.com/chromewebstore/v1.1/items/', {}); | ||
await client.get(undefined, 'token'); | ||
t.pass('Did not fetch token'); | ||
}); | ||
|
||
test.serial('Get uses token for auth', async t => { | ||
t.plan(1); | ||
test('Get uses token for auth', async t => { | ||
t.plan(0); | ||
|
||
const { client, sandbox } = t.context; | ||
const { client } = t.context; | ||
const token = 'token'; | ||
|
||
sandbox.stub(got, 'get').callsFake((uri, { headers }) => { | ||
t.is(headers.Authorization, `Bearer ${token}`); | ||
return { | ||
json: sandbox.stub().resolves({}), | ||
}; | ||
}); | ||
fetchMock.getOnce({ | ||
url: 'begin:https://www.googleapis.com/', | ||
headers: { Authorization: `Bearer ${token}` }, | ||
}, {}); | ||
|
||
await client.get(undefined, token); | ||
}); | ||
|
||
test.serial('Get uses provided extension ID', async t => { | ||
t.plan(1); | ||
|
||
const { client, sandbox } = t.context; | ||
test('Get uses provided extension ID', async t => { | ||
const { client } = t.context; | ||
const { extensionId } = client; | ||
|
||
sandbox.stub(got, 'get').callsFake(uri => { | ||
t.true(uri.includes(`/items/${extensionId}`)); | ||
|
||
return { | ||
json: sandbox.stub().resolves({}), | ||
}; | ||
}); | ||
fetchMock.getOnce(`path:/chromewebstore/v1.1/items/${extensionId}`, {}); | ||
|
||
await client.get(undefined, 'token'); | ||
t.pass(); | ||
}); |
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
Oops, something went wrong.