@@ -18,6 +18,13 @@ const stack = stackInstance();
1818const BLOG_POST_CT = process . env . MEDIUM_CONTENT_TYPE_UID || 'article' ;
1919const SOURCE_CT = process . env . COMPLEX_CONTENT_TYPE_UID || 'cybersecurity' ;
2020
21+ // Taxonomy test data - uses real taxonomy terms from the test stack
22+ // USA taxonomy: california > san_diago, san_jose
23+ // India taxonomy: maharashtra > mumbai, pune
24+ const TAX_FIELD = 'taxonomies.usa' ;
25+ const TAX_TERM = process . env . TAX_USA_STATE || 'california' ;
26+ const TAX_CHILD_TERM = 'san_diago' ;
27+
2128describe ( "Entries API test cases" , ( ) => {
2229 it ( "should check for entries is defined" , async ( ) => {
2330 const result = await makeEntries ( BLOG_POST_CT ) . find < TEntry > ( ) ;
@@ -113,60 +120,55 @@ describe("Entries API test cases", () => {
113120 } ) ;
114121
115122 it ( "CT Taxonomies Query: Get Entries With One Term" , async ( ) => {
116- let Query = makeEntries ( SOURCE_CT ) . query ( ) . where ( "taxonomies.one" , QueryOperation . EQUALS , "term_one" ) ;
123+ let Query = makeEntries ( SOURCE_CT ) . query ( ) . where ( TAX_FIELD , QueryOperation . EQUALS , TAX_TERM ) ;
117124 const data = await Query . find < TEntries > ( ) ;
118125 if ( data . entries ) expect ( data . entries . length ) . toBeGreaterThan ( 0 ) ;
119126 } ) ;
120127
121128 it ( "CT Taxonomies Query: Get Entries With Any Term ($in)" , async ( ) => {
122- let Query = makeEntries ( SOURCE_CT ) . query ( ) . where ( "taxonomies.one" , QueryOperation . INCLUDES , [ "term_one" , "term_two" , ] ) ;
129+ let Query = makeEntries ( SOURCE_CT ) . query ( ) . where ( TAX_FIELD , QueryOperation . INCLUDES , [ TAX_TERM , TAX_CHILD_TERM ] ) ;
123130 const data = await Query . find < TEntries > ( ) ;
124131 if ( data . entries ) expect ( data . entries . length ) . toBeGreaterThan ( 0 ) ;
125132 } ) ;
126133
127134 it ( "CT Taxonomies Query: Get Entries With Any Term ($or)" , async ( ) => {
128- let Query1 = makeEntries ( SOURCE_CT ) . query ( ) . where ( "taxonomies.one" , QueryOperation . EQUALS , "term_one" ) ;
129- let Query2 = makeEntries ( SOURCE_CT ) . query ( ) . where ( "taxonomies.two " , QueryOperation . EQUALS , "term_two ") ;
135+ let Query1 = makeEntries ( SOURCE_CT ) . query ( ) . where ( TAX_FIELD , QueryOperation . EQUALS , TAX_TERM ) ;
136+ let Query2 = makeEntries ( SOURCE_CT ) . query ( ) . where ( "taxonomies.india " , QueryOperation . EQUALS , process . env . TAX_INDIA_STATE || "maharashtra ") ;
130137 let Query = makeEntries ( SOURCE_CT ) . query ( ) . queryOperator ( QueryOperator . OR , Query1 , Query2 ) ;
131138 const data = await Query . find < TEntries > ( ) ;
132139 if ( data . entries ) expect ( data . entries . length ) . toBeGreaterThan ( 0 ) ;
133140 } ) ;
134141
135142 it ( "CT Taxonomies Query: Get Entries With All Terms ($and)" , async ( ) => {
136- let Query1 = makeEntries ( SOURCE_CT ) . query ( ) . where ( "taxonomies.one" , QueryOperation . EQUALS , "term_one" ) ;
137- let Query2 = makeEntries ( SOURCE_CT ) . query ( ) . where ( "taxonomies.two" , QueryOperation . EQUALS , "term_two" ) ;
143+ let Query1 = makeEntries ( SOURCE_CT ) . query ( ) . where ( TAX_FIELD , QueryOperation . EQUALS , TAX_TERM ) ;
144+ let Query2 = makeEntries ( SOURCE_CT ) . query ( ) . where ( TAX_FIELD , QueryOperation . EXISTS , true ) ;
138145 let Query = makeEntries ( SOURCE_CT ) . query ( ) . queryOperator ( QueryOperator . AND , Query1 , Query2 ) ;
139146 const data = await Query . find < TEntries > ( ) ;
140147 if ( data . entries ) expect ( data . entries . length ) . toBeGreaterThan ( 0 ) ;
141148 } ) ;
142149
143150 it ( "CT Taxonomies Query: Get Entries With Any Taxonomy Terms ($exists)" , async ( ) => {
144- let Query = makeEntries ( SOURCE_CT ) . query ( ) . where ( "taxonomies.one" , QueryOperation . EXISTS , true ) ;
151+ let Query = makeEntries ( SOURCE_CT ) . query ( ) . where ( TAX_FIELD , QueryOperation . EXISTS , true ) ;
145152 const data = await Query . find < TEntries > ( ) ;
146153 if ( data . entries ) expect ( data . entries . length ) . toBeGreaterThan ( 0 ) ;
147154 } ) ;
148155
149156 it ( "CT Taxonomies Query: Get Entries With Taxonomy Terms and Also Matching Its Children Term ($eq_below, level)" , async ( ) => {
150- let Query = makeEntries ( SOURCE_CT ) . query ( ) . where ( "taxonomies.one" , TaxonomyQueryOperation . EQ_BELOW , "term_one" , { levels : 1 ,
151- } ) ;
157+ let Query = makeEntries ( SOURCE_CT ) . query ( ) . where ( TAX_FIELD , TaxonomyQueryOperation . EQ_BELOW , TAX_TERM , { levels : 1 } ) ;
152158 const data = await Query . find < TEntries > ( ) ;
153159 if ( data . entries ) expect ( data . entries . length ) . toBeGreaterThan ( 0 ) ;
154160 } ) ;
155161
156162 it ( "CT Taxonomies Query: Get Entries With Taxonomy Terms Children's and Excluding the term itself ($below, level)" , async ( ) => {
157- let Query = makeEntries ( SOURCE_CT ) . query ( ) . where ( "taxonomies.one" , TaxonomyQueryOperation . BELOW , "term_one" , { levels : 1 } ) ;
163+ let Query = makeEntries ( SOURCE_CT ) . query ( ) . where ( TAX_FIELD , TaxonomyQueryOperation . BELOW , TAX_TERM , { levels : 1 } ) ;
158164 const data = await Query . find < TEntries > ( ) ;
159- // May return 0 entries if no entries are tagged with children of term_one
160165 if ( data . entries ) {
161166 expect ( data . entries . length ) . toBeGreaterThanOrEqual ( 0 ) ;
162- if ( data . entries . length === 0 ) {
163- console . log ( '⚠️ No entries found with taxonomy children of term_one - test data dependent' ) ;
164- }
165167 }
166168 } ) ;
167169
168170 it ( "CT Taxonomies Query: Get Entries With Taxonomy Terms and Also Matching Its Parent Term ($eq_above, level)" , async ( ) => {
169- let Query = makeEntries ( SOURCE_CT ) . query ( ) . where ( "taxonomies.one" , TaxonomyQueryOperation . EQ_ABOVE , "term_one" , { levels : 1 } ) ;
171+ let Query = makeEntries ( SOURCE_CT ) . query ( ) . where ( TAX_FIELD , TaxonomyQueryOperation . EQ_ABOVE , TAX_CHILD_TERM , { levels : 1 } ) ;
170172 const data = await Query . find < TEntries > ( ) ;
171173 if ( data . entries ) expect ( data . entries . length ) . toBeGreaterThan ( 0 ) ;
172174 } ) ;
@@ -186,20 +188,10 @@ describe("Entries API test cases", () => {
186188
187189 it ( "CT Taxonomies Query: Get Entries With Taxonomy Terms Parent and Excluding the term itself ($above, level)" , async ( ) => {
188190 // ABOVE operation finds entries tagged with PARENT terms of the given term
189- // Requires a child term (e.g., term_one_child) to find its parents
190- try {
191- let Query = makeEntries ( SOURCE_CT ) . query ( ) . where ( "taxonomies.one" , TaxonomyQueryOperation . ABOVE , "term_one_child" , { levels : 1 } ) ;
192- const data = await Query . find < TEntries > ( ) ;
193- if ( data . entries ) expect ( data . entries . length ) . toBeGreaterThanOrEqual ( 0 ) ;
194- } catch ( error : any ) {
195- // Handle gracefully if term_one_child doesn't exist or API doesn't support ABOVE
196- if ( error . status === 400 || error . status === 422 || error . status === 141 ) {
197- console . log ( `⚠️ TaxonomyQueryOperation.ABOVE returned ${ error . status } - term_one_child may not exist or ABOVE not supported` ) ;
198- expect ( [ 400 , 422 , 141 ] ) . toContain ( error . status ) ;
199- } else {
200- throw error ;
201- }
202- }
191+ // Using san_diago (child of california) to find its parent
192+ let Query = makeEntries ( SOURCE_CT ) . query ( ) . where ( TAX_FIELD , TaxonomyQueryOperation . ABOVE , TAX_CHILD_TERM , { levels : 1 } ) ;
193+ const data = await Query . find < TEntries > ( ) ;
194+ if ( data . entries ) expect ( data . entries . length ) . toBeGreaterThanOrEqual ( 0 ) ;
203195 } ) ;
204196} ) ;
205197function makeEntries ( contentTypeUid = "" ) : Entries {
0 commit comments