Skip to content

Commit 2ac89a8

Browse files
committed
chore: fix tests
1 parent 6ab00d1 commit 2ac89a8

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

lib/contentful.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
* with access to the Contentful Content Delivery API.
44
*/
55

6+
import type { AxiosAdapter, AxiosRequestConfig, AxiosResponse } from 'axios'
67
import axios from 'axios'
78
import { createHttpClient, getUserAgentHeader } from 'contentful-sdk-core'
89
import { createGlobalOptions } from './create-global-options'
910
import { makeClient } from './make-client'
10-
import type { AxiosAdapter, AxiosRequestConfig, AxiosResponse } from 'axios'
11-
import { validateRemoveUnresolvedParam, validateResolveLinksParam } from './utils/validate-params'
1211
import { ContentfulClientApi } from './types'
12+
import { validateRemoveUnresolvedParam, validateResolveLinksParam } from './utils/validate-params'
1313

1414
/**
1515
* @category Client

lib/create-contentful-api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ export default function createContentfulApi<OptionType extends ChainOptions>(
9797
return baseUrl
9898
}
9999

100-
const alphaFeatures = (http.httpClientParams as any as CreateClientParams).alphaFeatures
100+
const alphaFeatures = (http.httpClientParams as any as CreateClientParams)?.alphaFeatures
101101

102102
function maybeEnableSourceMaps(query: Record<string, any> = {}): Record<string, any> {
103103
if (alphaFeatures?.withContentSourceMaps) {
104-
query.withContentSourceMaps = true
104+
query.includeContentSourceMaps = true
105105
}
106106
return query
107107
}

test/unit/contentful.test.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { createClient, CreateClientParams } from '../../lib/contentful'
21
import * as SdkCore from 'contentful-sdk-core'
2+
import { createClient } from '../../lib/contentful'
33
import * as CreateContentfulApi from '../../lib/create-contentful-api'
44

55
// eslint-disable-next-line @typescript-eslint/no-var-requires
@@ -33,6 +33,7 @@ describe('contentful', () => {
3333

3434
afterEach(() => {
3535
createHttpClientMock.mockReset()
36+
createContentfulApiMock.mockReset()
3637
})
3738

3839
test('Throws if no accessToken is defined', () => {
@@ -104,29 +105,27 @@ describe('contentful', () => {
104105
)
105106
})
106107

107-
test.only('Initializes API with alpha features', () => {
108+
test('Initializes API and attaches custom environment', () => {
108109
createClient({
109110
accessToken: 'accessToken',
110111
space: 'spaceId',
111-
alphaFeatures: { withContentSourceMaps: true },
112+
environment: 'stage',
112113
})
113114
const callConfig = createContentfulApiMock.mock.calls[0]
114-
115-
const alphaFeatures = (callConfig[0].http.httpClientParams as any as CreateClientParams)
116-
.alphaFeatures
117-
expect(alphaFeatures).toEqual({ withContentSourceMaps: true })
115+
expect(callConfig[0].http.defaults.baseURL).toEqual(
116+
'http://some-base-url.com/environments/stage',
117+
)
118118
})
119119

120-
// fails, not sure if it because of wrong mocking
121-
test.skip('Initializes API and attaches custom environment', () => {
120+
test('Initializes API with alpha features', () => {
122121
createClient({
123122
accessToken: 'accessToken',
124123
space: 'spaceId',
125-
environment: 'stage',
124+
alphaFeatures: { withContentSourceMaps: true },
126125
})
127-
const callConfig = createContentfulApiMock.mock.calls[0]
128-
expect(callConfig[0].http.defaults.baseURL).toEqual(
129-
'http://some-base-url.com/environments/stage',
130-
)
126+
const callConfig = createHttpClientMock.mock.calls[0]
127+
128+
const alphaFeatures = callConfig[1].alphaFeatures
129+
expect(alphaFeatures).toEqual({ withContentSourceMaps: true })
131130
})
132131
})

0 commit comments

Comments
 (0)