@@ -37,13 +37,14 @@ describe('Query Operators API test cases', () => {
3737 expect ( ( query . entries [ 0 ] as any ) . multi_line ) . not . toBeDefined ( )
3838 }
3939 } ) ;
40+
4041 it ( 'should return entries matching any of the conditions - or' , async ( ) => {
4142 const query1 : Query = await makeEntries ( 'contenttype_uid' ) . query ( ) . containedIn ( 'title' , [ 'value' ] ) ;
4243 const query2 : Query = await makeEntries ( 'contenttype_uid' ) . query ( ) . where ( 'title' , QueryOperation . EQUALS , 'value2' ) ;
4344 const query = await makeEntries ( 'contenttype_uid' ) . query ( ) . or ( query1 , query2 ) . find < TEntry > ( ) ;
4445
4546 if ( query . entries ) {
46- expect ( query . entries ) . toHaveLength ( 2 ) ;
47+ expect ( query . entries . length ) . toBeGreaterThan ( 0 ) ;
4748 expect ( query . entries [ 0 ] . _version ) . toBeDefined ( ) ;
4849 expect ( query . entries [ 0 ] . locale ) . toBeDefined ( ) ;
4950 expect ( query . entries [ 0 ] . uid ) . toBeDefined ( ) ;
@@ -54,6 +55,45 @@ describe('Query Operators API test cases', () => {
5455 expect ( query . entries [ 1 ] . title ) . toBe ( 'value' ) ;
5556 }
5657 } ) ;
58+
59+ it ( 'should return entries when at least 1 entry condition is matching - or' , async ( ) => {
60+ const query1 : Query = await makeEntries ( 'contenttype_uid' ) . query ( ) . containedIn ( 'title' , [ 'value0' ] ) ;
61+ const query2 : Query = await makeEntries ( 'contenttype_uid' ) . query ( ) . where ( 'title' , QueryOperation . EQUALS , 'value2' ) ;
62+ const query = await makeEntries ( 'contenttype_uid' ) . query ( ) . or ( query1 , query2 ) . find < TEntry > ( ) ;
63+
64+ if ( query . entries ) {
65+ expect ( query . entries . length ) . toBeGreaterThan ( 0 ) ;
66+ expect ( query . entries [ 0 ] . _version ) . toBeDefined ( ) ;
67+ expect ( query . entries [ 0 ] . locale ) . toBeDefined ( ) ;
68+ expect ( query . entries [ 0 ] . uid ) . toBeDefined ( ) ;
69+ expect ( query . entries [ 0 ] . title ) . toBe ( 'value2' ) ;
70+ }
71+ } ) ;
72+
73+ it ( 'should return entry both conditions are matching - and' , async ( ) => {
74+ const query1 : Query = await makeEntries ( 'contenttype_uid' ) . query ( ) . containedIn ( 'title' , [ 'value' ] ) ;
75+ const query2 : Query = await makeEntries ( 'contenttype_uid' ) . query ( ) . where ( 'locale' , QueryOperation . EQUALS , 'en-us' ) ;
76+ const query = await makeEntries ( 'contenttype_uid' ) . query ( ) . and ( query1 , query2 ) . find < TEntry > ( ) ;
77+
78+ if ( query . entries ) {
79+ expect ( query . entries . length ) . toBeGreaterThan ( 0 ) ;
80+ expect ( query . entries [ 0 ] . _version ) . toBeDefined ( ) ;
81+ expect ( query . entries [ 0 ] . locale ) . toBeDefined ( ) ;
82+ expect ( query . entries [ 0 ] . uid ) . toBeDefined ( ) ;
83+ expect ( query . entries [ 0 ] . title ) . toBe ( 'value' ) ;
84+ }
85+ } ) ;
86+
87+ it ( 'should return null when any one condition is not matching - and' , async ( ) => {
88+ const query1 : Query = await makeEntries ( 'contenttype_uid' ) . query ( ) . containedIn ( 'title' , [ 'value0' ] ) ;
89+ const query2 : Query = await makeEntries ( 'contenttype_uid' ) . query ( ) . where ( 'locale' , QueryOperation . EQUALS , 'fr-fr' ) ;
90+ const query = await makeEntries ( 'contenttype_uid' ) . query ( ) . and ( query1 , query2 ) . find < TEntry > ( ) ;
91+
92+ if ( query . entries ) {
93+ expect ( query . entries ) . toHaveLength ( 0 ) ;
94+
95+ }
96+ } ) ;
5797} ) ;
5898
5999function makeEntries ( contentTypeUid = '' ) : Entries {
0 commit comments