@@ -37,13 +37,14 @@ describe('Query Operators API test cases', () => {
37
37
expect ( ( query . entries [ 0 ] as any ) . multi_line ) . not . toBeDefined ( )
38
38
}
39
39
} ) ;
40
+
40
41
it ( 'should return entries matching any of the conditions - or' , async ( ) => {
41
42
const query1 : Query = await makeEntries ( 'contenttype_uid' ) . query ( ) . containedIn ( 'title' , [ 'value' ] ) ;
42
43
const query2 : Query = await makeEntries ( 'contenttype_uid' ) . query ( ) . where ( 'title' , QueryOperation . EQUALS , 'value2' ) ;
43
44
const query = await makeEntries ( 'contenttype_uid' ) . query ( ) . or ( query1 , query2 ) . find < TEntry > ( ) ;
44
45
45
46
if ( query . entries ) {
46
- expect ( query . entries ) . toHaveLength ( 2 ) ;
47
+ expect ( query . entries . length ) . toBeGreaterThan ( 0 ) ;
47
48
expect ( query . entries [ 0 ] . _version ) . toBeDefined ( ) ;
48
49
expect ( query . entries [ 0 ] . locale ) . toBeDefined ( ) ;
49
50
expect ( query . entries [ 0 ] . uid ) . toBeDefined ( ) ;
@@ -54,6 +55,45 @@ describe('Query Operators API test cases', () => {
54
55
expect ( query . entries [ 1 ] . title ) . toBe ( 'value' ) ;
55
56
}
56
57
} ) ;
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
+ } ) ;
57
97
} ) ;
58
98
59
99
function makeEntries ( contentTypeUid = '' ) : Entries {
0 commit comments