1+ import { AxiosInstance , httpClient } from '@contentstack/core' ;
2+ import { ContentType } from '../../src/lib/content-type' ;
3+ import MockAdapter from 'axios-mock-adapter' ;
4+ import { MOCK_CLIENT_OPTIONS } from '../utils/constant' ;
5+
6+
7+ describe ( 'Query Operators API test cases' , ( ) => {
8+ let contentType : ContentType ;
9+ let client : AxiosInstance ;
10+ let mockClient : MockAdapter ;
11+
12+ beforeAll ( ( ) => {
13+ client = httpClient ( MOCK_CLIENT_OPTIONS ) ;
14+ mockClient = new MockAdapter ( client as any ) ;
15+ } ) ;
16+
17+ beforeEach ( ( ) => {
18+ contentType = new ContentType ( client , 'contentTypeUid' ) ;
19+ } ) ;
20+ it ( 'should get entries which matches the fieldUid and values' , ( ) => {
21+ const query = contentType . Entry ( ) . query ( ) . containedIn ( 'fieldUID' , [ 'value' ] ) ;
22+ expect ( query . _parameters ) . toStrictEqual ( { 'fieldUID' : { '$in' : [ 'value' ] } } ) ;
23+ } ) ;
24+ it ( 'should get entries which does not match the fieldUid and values' , ( ) => {
25+ const query = contentType . Entry ( ) . query ( ) . notContainedIn ( 'fieldUID' , [ 'value' , 'value2' ] ) ;
26+ expect ( query . _parameters ) . toStrictEqual ( { 'fieldUID' : { '$nin' : [ 'value' , 'value2' ] } } ) ;
27+ } ) ;
28+ it ( 'should get entries which does not match the fieldUid - notExists' , ( ) => {
29+ const query = contentType . Entry ( ) . query ( ) . notExists ( 'fieldUID' ) ;
30+ expect ( query . _parameters ) . toStrictEqual ( { 'fieldUID' : { '$exists' : false } } ) ;
31+ } ) ;
32+ } ) ;
0 commit comments