Skip to content

Commit

Permalink
fix: added test cases for only and except filters
Browse files Browse the repository at this point in the history
  • Loading branch information
Vikram Kalta authored and Vikram Kalta committed Nov 12, 2024
1 parent 1895cbb commit 197c6dc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions src/lib/base-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,14 @@ export class BaseQuery extends Pagination {
requestParams = { ...this._queryParams, query: { ...this._parameters } };
}

const getRequestOptions: any = { params: requestParams };
const getRequestOptions: any = requestParams;

if (this._variants) {
getRequestOptions.headers = {
...getRequestOptions.headers,
'x-cs-variant-uid': this._variants
};
}

const response = await getData(this._client, this._urlPath, getRequestOptions);

return response as FindResponse<T>;
Expand Down
1 change: 0 additions & 1 deletion src/lib/entry-queryable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export class EntryQueryable extends BaseQuery {
} else {
this._queryParams["only[BASE][]"] = fieldUid;
}

return this;
}

Expand Down
22 changes: 22 additions & 0 deletions test/api/entry-queryables.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,28 @@ describe('Query Operators API test cases', () => {

}
});

it('should check for projected fields after only filter is applied', async () => {
const query = makeEntries('contenttype_uid2').only(['title', 'reference'])
const result = await query.find<TEntry>();
if (result.entries) {
expect(result.entries.length).toBeGreaterThan(0);
expect(result.entries[0].reference).toBeDefined();
expect(result.entries[0].title).toBeDefined();
expect(result.entries[0]._version).toBeUndefined();
}
});

it('should ignore fields after except filter is applied', async () => {
const query = makeEntries('contenttype_uid2').except(['title', 'reference'])
const result = await query.find<TEntry>();
if (result.entries) {
expect(result.entries.length).toBeGreaterThan(0);
expect(result.entries[0].reference).toBeUndefined();
expect(result.entries[0].title).toBeUndefined();
expect(result.entries[0]._version).toBeDefined();
}
});
});

function makeEntries(contentTypeUid = ''): Entries {
Expand Down

0 comments on commit 197c6dc

Please sign in to comment.