fix(catalog): always pair \$count=true with ConsistencyLevel: eventual in advanced mode

Microsoft Graph requires \$count=true whenever the ConsistencyLevel: eventual
header is present, including plain listing requests with no \$filter or \$search.
The previous condition only added \$count when a filter or search was present,
causing the /groups endpoint to silently return an empty value array when
queryMode is set to advanced without a group filter.
Signed-off-by: pillaris <pillaris@adobe.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
pillaris
2026-04-24 12:21:00 +05:30
parent f1279ea2d6
commit 70adee104e
2 changed files with 21 additions and 6 deletions
@@ -75,6 +75,24 @@ describe('requestOnePage', () => {
);
});
it('adds ConsistencyLevel and $count for advanced mode without filter', async () => {
(client.requestApi as jest.Mock).mockResolvedValue(
makeResponse(200, { value: [] }),
);
await requestOnePage(client, 'groups', {
query: { top: 999 },
queryMode: 'advanced',
});
expect(client.requestApi).toHaveBeenCalledWith(
'groups',
expect.objectContaining({ count: true }),
{ ConsistencyLevel: 'eventual' },
undefined,
);
});
it('auto-promotes to advanced mode when $search is present', async () => {
(client.requestApi as jest.Mock).mockResolvedValue(
makeResponse(200, { value: [] }),
@@ -42,12 +42,9 @@ export async function requestOnePage<T>(
const { query, queryMode, nextLink, signal } = options;
const appliedQueryMode = query?.search ? 'advanced' : queryMode ?? 'basic';
// $count=true is required for advanced queries using ne/not in $filter or $search
if (
appliedQueryMode === 'advanced' &&
query &&
(query.filter || query.search)
) {
// Microsoft Graph requires $count=true whenever ConsistencyLevel: eventual is set,
// including plain listing requests with no $filter or $search.
if (appliedQueryMode === 'advanced' && query) {
query.count = true;
}