Skip to content

Commit

Permalink
Merge pull request #171 from contentstack/v4-beta/next
Browse files Browse the repository at this point in the history
notEqualTo query operator implementation
  • Loading branch information
harshithad0703 authored Apr 15, 2024
2 parents 50b82ba + f58d499 commit 8c6da72
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ jobs:
registry-url: 'https://npm.pkg.github.com'
scope: '@contentstack'
- run: npm ci
- run: npm publish --tag beta
- run: npm publish --tag latest
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## Change log

### Version: 4.0.0-beta.6
#### Date: April-09-2024
##### New Features:
- Query operators implementation-3

### Version: 4.0.0-beta.5
#### Date: March-26-2024
##### New Features:
Expand Down
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.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/delivery-sdk",
"version": "4.0.0-beta.5",
"version": "4.0.0-beta.6",
"type": "commonjs",
"main": "./dist/cjs/src/index.js",
"types": "./dist/types/src/index.d.ts",
Expand Down
19 changes: 18 additions & 1 deletion src/lib/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,24 @@ export class Query extends BaseQuery {
}

/**
* @method equalTo
* @method notEqualTo
* @memberof Query
* @description Returns the raw (JSON) query based on the filters applied on Query object.
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const query = await stack.contentType('contenttype_uid').Entry().query().notEqualTo('fieldUid', 'value').find();
*
* @returns {Query}
*/
notEqualTo(key: string, value: string | number | boolean): Query {
this._parameters[key] = { '$ne': value };
return this;;
}

/**
* @method referenceIn
* @memberof Query
* @description Returns the raw (JSON) query based on the filters applied on Query object.
* @example
Expand Down
12 changes: 12 additions & 0 deletions test/api/entry-queryables.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,17 @@ describe('Query Operators API test cases', () => {
}
});

it('should return entry not equal to the condition - notEqualTo', async () => {
const query = await makeEntries('contenttype_uid').query().notEqualTo('title', 'value').find<TEntry>();

if (query.entries) {
expect(query.entries[0]._version).toBeDefined();
expect(query.entries[0].locale).toBeDefined();
expect(query.entries[0].uid).toBeDefined();
expect(query.entries[0].title).not.toBe('value');
}
});

it('should return entry for referencedIn query', async () => {
const query = makeEntries('contenttype_uid').query().where('title', QueryOperation.EQUALS, 'value');
const entryQuery = await makeEntries('contenttype_uid').query().referenceIn('reference_uid', query).find<TEntry>();
Expand All @@ -127,6 +138,7 @@ describe('Query Operators API test cases', () => {
expect(entryQuery.entries[0].title).toBe('test');
}
});

it('should return entry for referenceNotIn query', async () => {
const query = makeEntries('contenttype_uid').query().where('title', QueryOperation.EQUALS, 'value');
const entryQuery = await makeEntries('contenttype_uid').query().referenceNotIn('reference_uid', query).find<TEntry>();
Expand Down
4 changes: 4 additions & 0 deletions test/unit/entry-queryable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ describe('Query Operators API test cases', () => {
const query = contentType.Entry().query().equalTo('fieldUID', 'value');
expect(query._parameters).toStrictEqual({ 'fieldUID': 'value' });
});
it('should return entry equal to the condition - notEqualTo', async () => {
const query = contentType.Entry().query().notEqualTo('fieldUID', 'value');
expect(query._parameters).toStrictEqual({ 'fieldUID': {'$ne': 'value'} });
});
it('should return entry for referenceIn query', async () => {
const query1 = contentType.Entry().query().where('fieldUID', QueryOperation.EQUALS, 'value');
const entryQuery = await contentType.Entry().query().referenceIn('reference_uid', query1);
Expand Down

0 comments on commit 8c6da72

Please sign in to comment.