Skip to content

Commit e611418

Browse files
committed
feat: adding unit tests for publishedWithCursor methods for Asset and Entry, adding function level comments for new publishedWithCursor methods [CAPI-2387]
1 parent 3e19960 commit e611418

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

lib/create-environment-api.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,24 @@ export default function createEnvironmentApi(makeRequest: MakeRequest) {
853853
}).then((data) => wrapEntryCollection(makeRequest, data))
854854
},
855855

856+
/**
857+
* Gets a collection of published Entries with cursor based pagination
858+
* @param query - Object with cursor pagination parameters. Check the <a href="https://www.contentful.com/developers/docs/references/content-management-api/#/introduction/cursor-pagination">REST API reference</a> for more details.
859+
* @return Promise for a collection of published Entries
860+
* @example ```javascript
861+
* const contentful = require('contentful-management')
862+
*
863+
* const client = contentful.createClient({
864+
* accessToken: '<content_management_api_key>'
865+
* })
866+
*
867+
* client.getSpace('<space_id>')
868+
* .then((space) => space.getEnvironment('<environment-id>'))
869+
* .then((environment) => environment.getPublishedEntriesWithCursor())
870+
* .then((response) => console.log(response.items))
871+
* .catch(console.error)
872+
* ```
873+
*/
856874
getPublishedEntriesWithCursor(query: BasicCursorPaginationOptions = {}) {
857875
const raw = this.toPlainObject() as EnvironmentProps
858876
const normalizedQueryParams = normalizeCursorPaginationParameters(query)
@@ -1127,6 +1145,24 @@ export default function createEnvironmentApi(makeRequest: MakeRequest) {
11271145
}).then((data) => wrapAssetCollection(makeRequest, data))
11281146
},
11291147

1148+
/**
1149+
* Gets a collection of published Assets with cursor based pagination
1150+
* @param query - Object with cursor pagination parameters. Check the <a href="https://www.contentful.com/developers/docs/references/content-management-api/#/introduction/cursor-pagination">REST API reference</a> for more details.
1151+
* @return Promise for a collection of published Assets
1152+
* @example ```javascript
1153+
* const contentful = require('contentful-management')
1154+
*
1155+
* const client = contentful.createClient({
1156+
* accessToken: '<content_management_api_key>'
1157+
* })
1158+
*
1159+
* client.getSpace('<space_id>')
1160+
* .then((space) => space.getEnvironment('<environment-id>'))
1161+
* .then((environment) => environment.getPublishedAssetsWithCursor())
1162+
* .then((response) => console.log(response.items))
1163+
* .catch(console.error)
1164+
* ```
1165+
*/
11301166
getPublishedAssetsWithCursor(query: BasicCursorPaginationOptions = {}) {
11311167
const raw = this.toPlainObject() as EnvironmentProps
11321168
const normalizedQueryParams = normalizeCursorPaginationParameters(query)

test/unit/create-environment-api.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,21 @@ describe('A createEnvironmentApi', () => {
287287
})
288288
})
289289

290+
test('API call getPublishedEntriesWithCursor', async () => {
291+
return makeGetPaginatedCollectionTest(setup, {
292+
entityType: 'entry',
293+
mockToReturn: mockCursorPaginatedCollection<EntryProps>(entryMock),
294+
methodToTest: 'getPublishedEntriesWithCursor',
295+
})
296+
})
297+
298+
test('API call getPublishedEntriesWithCursor fails', async () => {
299+
return makeEntityMethodFailingTest(setup, {
300+
methodToTest: 'getPublishedEntriesWithCursor',
301+
})
302+
})
303+
304+
290305
test('API call createEntry', async () => {
291306
const { api, makeRequest, entitiesMock } = setup(Promise.resolve(entryMock))
292307
entitiesMock.entry.wrapEntry.mockReturnValue(entryMock)
@@ -373,6 +388,20 @@ describe('A createEnvironmentApi', () => {
373388
})
374389
})
375390

391+
test('API call getPublishedAssetsWithCursor', async () => {
392+
return makeGetPaginatedCollectionTest(setup, {
393+
entityType: 'asset',
394+
mockToReturn: mockCursorPaginatedCollection<AssetProps>(assetMock),
395+
methodToTest: 'getPublishedAssetsWithCursor',
396+
})
397+
})
398+
399+
test('API call getPublishedAssetsWithCursor fails', async () => {
400+
return makeEntityMethodFailingTest(setup, {
401+
methodToTest: 'getPublishedAssetsWithCursor',
402+
})
403+
})
404+
376405
test('API call createAsset', async () => {
377406
return makeCreateEntityTest(setup, {
378407
entityType: 'asset',

0 commit comments

Comments
 (0)