-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
*/ | ||
|
||
import assign from 'lodash/assign' | ||
import axios from 'axios' | ||
import version from '../version' | ||
import {createHttpClient} from 'contentful-sdk-core' | ||
import createContentfulApi from './create-contentful-api' | ||
|
@@ -31,7 +32,7 @@ import createLinkResolver from './create-link-resolver' | |
* space: 'mySpaceId' | ||
* }) | ||
*/ | ||
export default function createClient (axios, params) { | ||
export function createClient (params) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Khaledgarbaya
Author
Contributor
|
||
if (!params.accessToken) { | ||
throw new TypeError('Expected parameter accessToken') | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +1,95 @@ | ||
import test from 'tape' | ||
import sinon from 'sinon' | ||
import createClient from '../../lib/contentful' | ||
|
||
const axios = {create: sinon.stub()} | ||
import {createClient, __RewireAPI__ as createClientRewireApi} from '../../lib/contentful' | ||
|
||
test('Throws if no accessToken is defined', (t) => { | ||
t.throws(() => { | ||
createClient(axios, {space: 'spaceid'}) | ||
createClient({space: 'spaceid'}) | ||
}, /Expected parameter accessToken/) | ||
t.end() | ||
}) | ||
|
||
test('Throws if no space is defined', (t) => { | ||
t.throws(() => { | ||
createClient(axios, {accessToken: 'accesstoken'}) | ||
createClient({accessToken: 'accesstoken'}) | ||
}, /Expected parameter space/) | ||
t.end() | ||
}) | ||
|
||
test('Passes along HTTP client parameters', (t) => { | ||
createClient.__Rewire__('version', 'version') | ||
createClientRewireApi.__Rewire__('axios', sinon.stub) | ||
createClientRewireApi.__Rewire__('version', 'version') | ||
const createHttpClientStub = sinon.stub() | ||
const rateLimitStub = sinon.stub() | ||
createClient.__Rewire__('createHttpClient', createHttpClientStub) | ||
createClient.__Rewire__('rateLimit', rateLimitStub) | ||
createClient(axios, {accessToken: 'accesstoken', space: 'spaceid'}) | ||
createClientRewireApi.__Rewire__('createHttpClient', createHttpClientStub) | ||
createClientRewireApi.__Rewire__('rateLimit', rateLimitStub) | ||
createClient({accessToken: 'accesstoken', space: 'spaceid'}) | ||
t.ok(createHttpClientStub.args[0][1].headers['Content-Type']) | ||
t.equals(createHttpClientStub.args[0][1].headers['X-Contentful-User-Agent'], 'contentful.js/version') | ||
createClient.__ResetDependency__('rateLimit') | ||
createClient.__ResetDependency__('createHttpClient') | ||
createClientRewireApi.__ResetDependency__('rateLimit') | ||
createClientRewireApi.__ResetDependency__('createHttpClient') | ||
createClientRewireApi.__ResetDependency__('axios') | ||
t.end() | ||
}) | ||
|
||
test('Returns a client instance', (t) => { | ||
const createHttpClientStub = sinon.stub() | ||
const rateLimitStub = sinon.stub() | ||
createClient.__Rewire__('createHttpClient', createHttpClientStub) | ||
createClient.__Rewire__('rateLimit', rateLimitStub) | ||
const client = createClient(axios, {accessToken: 'accesstoken', space: 'spaceid'}) | ||
createClientRewireApi.__Rewire__('createHttpClient', createHttpClientStub) | ||
createClientRewireApi.__Rewire__('rateLimit', rateLimitStub) | ||
const client = createClient({accessToken: 'accesstoken', space: 'spaceid'}) | ||
t.ok(client.getSpace, 'getSpace') | ||
t.ok(client.getEntry, 'getEntry') | ||
t.ok(client.getEntries, 'getEntries') | ||
t.ok(client.getContentType, 'getContentType') | ||
t.ok(client.getContentTypes, 'getContentTypes') | ||
t.ok(client.getAsset, 'getAsset') | ||
t.ok(client.getAssets, 'getAssets') | ||
createClient.__ResetDependency__('rateLimit') | ||
createClient.__ResetDependency__('createHttpClient') | ||
createClientRewireApi.__ResetDependency__('rateLimit') | ||
createClientRewireApi.__ResetDependency__('createHttpClient') | ||
t.end() | ||
}) | ||
|
||
test('Initializes API with link resolution turned on by default', (t) => { | ||
const createHttpClientStub = sinon.stub() | ||
const rateLimitStub = sinon.stub() | ||
createClient.__Rewire__('createHttpClient', createHttpClientStub) | ||
createClient.__Rewire__('rateLimit', rateLimitStub) | ||
createClientRewireApi.__Rewire__('createHttpClient', createHttpClientStub) | ||
createClientRewireApi.__Rewire__('rateLimit', rateLimitStub) | ||
const apiStub = sinon.stub().returns({}) | ||
createClient.__Rewire__('createContentfulApi', apiStub) | ||
createClient(axios, {accessToken: 'accesstoken', space: 'spaceid'}) | ||
createClientRewireApi.__Rewire__('createContentfulApi', apiStub) | ||
createClient({accessToken: 'accesstoken', space: 'spaceid'}) | ||
t.ok(apiStub.args[0][0].shouldLinksResolve({}), 'not overriden by query') | ||
t.notOk(apiStub.args[0][0].shouldLinksResolve({resolveLinks: false}), 'overriden by query') | ||
createClient.__ResetDependency__('createHttpClient') | ||
createClient.__ResetDependency__('rateLimit') | ||
createClientRewireApi.__ResetDependency__('createHttpClient') | ||
createClientRewireApi.__ResetDependency__('rateLimit') | ||
t.end() | ||
}) | ||
|
||
test('Initializes API with link resolution turned on explicitly', (t) => { | ||
const createHttpClientStub = sinon.stub() | ||
const rateLimitStub = sinon.stub() | ||
createClient.__Rewire__('createHttpClient', createHttpClientStub) | ||
createClient.__Rewire__('rateLimit', rateLimitStub) | ||
createClientRewireApi.__Rewire__('createHttpClient', createHttpClientStub) | ||
createClientRewireApi.__Rewire__('rateLimit', rateLimitStub) | ||
const apiStub = sinon.stub().returns({}) | ||
createClient.__Rewire__('createContentfulApi', apiStub) | ||
createClient(axios, {accessToken: 'accesstoken', space: 'spaceid', resolveLinks: true}) | ||
createClientRewireApi.__Rewire__('createContentfulApi', apiStub) | ||
createClient({accessToken: 'accesstoken', space: 'spaceid', resolveLinks: true}) | ||
t.ok(apiStub.args[0][0].shouldLinksResolve({}), 'not overriden by query') | ||
t.notOk(apiStub.args[0][0].shouldLinksResolve({resolveLinks: false}), 'overriden by query') | ||
createClient.__ResetDependency__('createHttpClient') | ||
createClient.__ResetDependency__('rateLimit') | ||
createClientRewireApi.__ResetDependency__('createHttpClient') | ||
createClientRewireApi.__ResetDependency__('rateLimit') | ||
t.end() | ||
}) | ||
|
||
test('Initializes API with link resolution turned off explicitly', (t) => { | ||
const createHttpClientStub = sinon.stub() | ||
const rateLimitStub = sinon.stub() | ||
createClient.__Rewire__('createHttpClient', createHttpClientStub) | ||
createClient.__Rewire__('rateLimit', rateLimitStub) | ||
createClientRewireApi.__Rewire__('createHttpClient', createHttpClientStub) | ||
createClientRewireApi.__Rewire__('rateLimit', rateLimitStub) | ||
const apiStub = sinon.stub().returns({}) | ||
createClient.__Rewire__('createContentfulApi', apiStub) | ||
createClient(axios, {accessToken: 'accesstoken', space: 'spaceid', resolveLinks: false}) | ||
createClientRewireApi.__Rewire__('createContentfulApi', apiStub) | ||
createClient({accessToken: 'accesstoken', space: 'spaceid', resolveLinks: false}) | ||
t.notOk(apiStub.args[0][0].resolveLinksGlobalSetting) | ||
createClient.__ResetDependency__('createHttpClient') | ||
createClient.__ResetDependency__('rateLimit') | ||
createClientRewireApi.__ResetDependency__('createHttpClient') | ||
createClientRewireApi.__ResetDependency__('rateLimit') | ||
t.end() | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
module.exports = '' | ||
module.exports = '4.1.0' |
@Khaledgarbaya FYI this was a breaking change in a patch release