Skip to content

Commit

Permalink
feat: ensure getMultiple defaults to having a default max of null as …
Browse files Browse the repository at this point in the history
…before
  • Loading branch information
mikedsharp committed Jun 18, 2024
1 parent e24dda8 commit 569f5c6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/lib/components/ContentLink.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('ContentItem', () => {
it('should beable to return multiple items', () => {
jest.spyOn(connection, 'request').mockResolvedValue({});

contentLink.getMultiple(['123'], { pointer: '/fieldPointer', max: null });
contentLink.getMultiple(['123'], { pointer: '/fieldPointer' });

expect(connection.request).toHaveBeenCalledWith(
CONTENT_LINK.CONTENT_GET,
Expand Down
12 changes: 8 additions & 4 deletions src/lib/components/ContentLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,16 @@ export class ContentLink {
*/
getMultiple(
contentTypeIds: Array<string>,
options: ContentLinkOptions = { max: null, pointer: '' }
options: ContentLinkOptions
): Promise<ContentItemLink[]> {
if (options.max === undefined) {
options.max = null;
const defaultOptions = {
max: null
}
return this.fetchLinks(contentTypeIds, options.pointer, options.max);
const mergedOptions = {
...defaultOptions,
...options
}
return this.fetchLinks(contentTypeIds, mergedOptions.pointer, mergedOptions.max);
}
/**
* This method will trigger a content browser. It returns a promise that will resolve to the chosen Content Link.
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/ContentReference.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('ContentReference', () => {
it('should beable to return multiple items', async () => {
jest.spyOn(connection, 'request').mockResolvedValue({});

await expect(contentReference.getMultiple(['123'], { max: null, pointer: '/fieldPointer' })).resolves.toEqual({});
await expect(contentReference.getMultiple(['123'], { pointer: '/fieldPointer' })).resolves.toEqual({});

expect(connection.request).toHaveBeenCalledWith(
CONTENT_REFERENCE.CONTENT_REF_GET,
Expand Down
11 changes: 9 additions & 2 deletions src/lib/components/ContentReference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,16 @@ export class ContentReference {
*/
getMultiple(
contentTypeIds: Array<string>,
options: ContentReferenceOptions = { max: null, pointer: '' }
options: ContentReferenceOptions,
): Promise<ContentItemReference[]> {
return this.fetchReferences(contentTypeIds, options.pointer, options.max);
const defaultOptions = {
max: null
}
const mergedOptions = {
...defaultOptions,
...options
}
return this.fetchReferences(contentTypeIds, mergedOptions.pointer, mergedOptions.max);
}
/**
* This method will trigger a content browser. It returns a promise that will resolve to the chosen Content Reference.
Expand Down

0 comments on commit 569f5c6

Please sign in to comment.