@@ -211,23 +211,43 @@ describe('Workflow API Tests', () => {
211211 let ruleEnvironment = null
212212
213213 before ( async function ( ) {
214- this . timeout ( 30000 )
214+ this . timeout ( 60000 )
215215
216216 // Get environment name from testData or query
217217 if ( testData . environments && testData . environments . development ) {
218218 ruleEnvironment = testData . environments . development . name
219+ console . log ( `Publish Rules using environment from testData: ${ ruleEnvironment } ` )
219220 } else {
220221 try {
221222 const envResponse = await stack . environment ( ) . query ( ) . find ( )
222223 const environments = envResponse . items || envResponse . environments || [ ]
223224 if ( environments . length > 0 ) {
224225 ruleEnvironment = environments [ 0 ] . name
226+ console . log ( `Publish Rules using existing environment: ${ ruleEnvironment } ` )
225227 }
226228 } catch ( e ) {
227229 console . log ( 'Could not fetch environments:' , e . message )
228230 }
229231 }
230232
233+ // If no environment exists, create a temporary one for publish rules
234+ if ( ! ruleEnvironment ) {
235+ try {
236+ const tempEnvName = `wf_${ Math . random ( ) . toString ( 36 ) . substring ( 2 , 7 ) } `
237+ const envResponse = await stack . environment ( ) . create ( {
238+ environment : {
239+ name : tempEnvName ,
240+ urls : [ { locale : 'en-us' , url : 'https://workflow-test.example.com' } ]
241+ }
242+ } )
243+ ruleEnvironment = envResponse . name || tempEnvName
244+ console . log ( `Publish Rules created temporary environment: ${ ruleEnvironment } ` )
245+ await wait ( 2000 )
246+ } catch ( e ) {
247+ console . log ( 'Could not create environment for publish rules:' , e . message )
248+ }
249+ }
250+
231251 // Try to use existing workflow from testData instead of creating new one
232252 // This avoids "Workflow already exists for all content types" error
233253 if ( testData . workflows && testData . workflows . simple && testData . workflows . simple . uid ) {
@@ -294,6 +314,12 @@ describe('Workflow API Tests', () => {
294314 return
295315 }
296316
317+ if ( ! workflowForRulesUid ) {
318+ console . log ( 'Skipping - no workflow available for publish rule' )
319+ this . skip ( )
320+ return
321+ }
322+
297323 try {
298324 const ruleData = {
299325 publishing_rule : {
@@ -306,12 +332,16 @@ describe('Workflow API Tests', () => {
306332 }
307333 }
308334
309- const response = await stack . workflow ( workflowForRulesUid ) . publishRule ( ) . create ( ruleData )
335+ // Note: publishRule() is on workflow() collection, not on workflow(uid)
336+ const response = await stack . workflow ( ) . publishRule ( ) . create ( ruleData )
310337
311338 expect ( response ) . to . be . an ( 'object' )
312339 if ( response . publishing_rule ) {
313340 publishRuleUid = response . publishing_rule . uid
314341 testData . workflows . publishRule = response . publishing_rule
342+ } else if ( response . uid ) {
343+ publishRuleUid = response . uid
344+ testData . workflows . publishRule = response
315345 }
316346 } catch ( error ) {
317347 // Publish rules might require specific environment
@@ -322,7 +352,8 @@ describe('Workflow API Tests', () => {
322352
323353 it ( 'should fetch all publish rules' , async ( ) => {
324354 try {
325- const response = await stack . workflow ( workflowForRulesUid ) . publishRule ( ) . fetchAll ( )
355+ // Note: publishRule() is on workflow() collection, not on workflow(uid)
356+ const response = await stack . workflow ( ) . publishRule ( ) . fetchAll ( )
326357
327358 expect ( response ) . to . be . an ( 'object' )
328359 } catch ( error ) {
0 commit comments