Skip to content

Commit bbb00d8

Browse files
#145: add start and limit properties for contentChildrenAndDescendants.getContentChildren (#148)
1 parent fcdbb74 commit bbb00d8

File tree

4 files changed

+65
-1
lines changed

4 files changed

+65
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
- Added `key` property to `longRunningTask.getTasks`
3636
- Added `sitePermissionTypeFilter` property to `search.searchUser`
3737
- Added `alias` property to both `space.createSpace` and `space.createPrivateSpace`
38+
- #145 Added `start` and `limit` properties to `contentChildrenAndDescendants.getContentChildren`. Thanks to @javierbrea for requesting this feature.
3839

3940
### **API Changes** 🔄
4041
- **Experimental methods moved**:

src/api/contentChildrenAndDescendants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ export class ContentChildrenAndDescendants {
6565
params: {
6666
expand: parameters.expand,
6767
parentVersion: parameters.parentVersion,
68+
start: parameters.start,
69+
limit: parameters.limit,
6870
},
6971
};
7072

src/api/parameters/getContentChildren.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { OneOrMany } from '../../interfaces';
2+
13
export interface GetContentChildren {
24
/** The ID of the content to be queried for its children. */
35
id: string;
@@ -9,7 +11,11 @@ export interface GetContentChildren {
911
* - `page` returns all child pages of the content.
1012
* - Custom content types that are provided by apps are also supported.
1113
*/
12-
expand?: string[];
14+
expand?: OneOrMany<'attachment' | 'comments' | 'page' | string>;
1315
/** The version of the parent content to retrieve children for. Currently, this only works for the latest version. */
1416
parentVersion?: number;
17+
/** The starting index of the returned content children. */
18+
start?: number;
19+
/** The maximum number of content children to return per page. */
20+
limit?: number;
1521
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { describe, it, expect, vi, beforeEach } from 'vitest';
2+
import { ContentChildrenAndDescendants } from '~/api/contentChildrenAndDescendants';
3+
import type { RequestConfig } from '~/requestConfig';
4+
5+
describe('getContentChildren', () => {
6+
let client: ContentChildrenAndDescendants;
7+
const mockSendRequest = vi.fn();
8+
9+
beforeEach(() => {
10+
// Create a fresh instance for each test
11+
mockSendRequest.mockReset();
12+
mockSendRequest.mockResolvedValue({});
13+
client = new ContentChildrenAndDescendants({
14+
sendRequest: mockSendRequest,
15+
});
16+
});
17+
18+
it('should use all parameters in the request config', async () => {
19+
// Arrange
20+
const testParams = {
21+
id: '12345',
22+
expand: ['body.view', 'version'],
23+
parentVersion: 2,
24+
start: 10,
25+
limit: 25,
26+
};
27+
28+
// Mock the successful response
29+
mockSendRequest.mockResolvedValue({
30+
page: [],
31+
comment: [],
32+
attachment: [],
33+
});
34+
35+
// Act
36+
await client.getContentChildren(testParams);
37+
38+
// Assert
39+
expect(mockSendRequest).toHaveBeenCalledTimes(1);
40+
41+
const calledConfig: RequestConfig = mockSendRequest.mock.calls[0][0];
42+
43+
// Verify URL construction with content ID
44+
expect(calledConfig.url).toBe(`/api/content/${testParams.id}/child`);
45+
expect(calledConfig.method).toBe('GET');
46+
47+
// Verify all query parameters
48+
expect(calledConfig.params).toEqual({
49+
expand: testParams.expand,
50+
parentVersion: testParams.parentVersion,
51+
start: testParams.start,
52+
limit: testParams.limit,
53+
});
54+
});
55+
});

0 commit comments

Comments
 (0)