@@ -33,7 +33,10 @@ async function waitForConfig(client, configId) {
3333
3434 while ( retries < maxRetries ) {
3535 try {
36- const name = client . organizationNotificationConfigPath ( organizationId , configId ) ;
36+ const name = client . organizationNotificationConfigPath (
37+ organizationId ,
38+ configId
39+ ) ;
3740 const [ config ] = await client . getNotificationConfig ( { name} ) ;
3841 if ( config ) return ;
3942 } catch ( err ) {
@@ -72,9 +75,15 @@ describe('Client with Notifications', async () => {
7275 if ( err . code === 400 ) {
7376 console . error ( `Invalid input for config ${ configId } :` , err . message ) ;
7477 } else if ( err . code === 503 ) {
75- console . error ( `Service unavailable when creating config ${ configId } :` , err . message ) ;
78+ console . error (
79+ `Service unavailable when creating config ${ configId } :` ,
80+ err . message
81+ ) ;
7682 } else {
77- console . error ( `Unexpected error creating config ${ configId } :` , err . message ) ;
83+ console . error (
84+ `Unexpected error creating config ${ configId } :` ,
85+ err . message
86+ ) ;
7887 }
7988 }
8089 }
@@ -91,31 +100,40 @@ describe('Client with Notifications', async () => {
91100
92101 after ( async ( ) => {
93102 const client = new SecurityCenterClient ( ) ;
94- async function deleteNotificationConfig ( configId ) {
103+ async function deleteNotificationConfigIfExists ( configId ) {
104+ const name = client . organizationNotificationConfigPath (
105+ organizationId ,
106+ configId
107+ ) ;
95108 try {
96- const name = client . organizationNotificationConfigPath (
97- organizationId ,
98- configId
99- ) ;
100- await client . deleteNotificationConfig ( { name : name } ) ;
109+ // Check if the config exists
110+ const [ config ] = await client . getNotificationConfig ( { name} ) ;
111+ if ( config ) {
112+ // Proceed with deletion if the config exists
113+ await client . deleteNotificationConfig ( { name : name } ) ;
114+ console . log ( `Config ${ configId } deleted successfully.` ) ;
115+ }
101116 } catch ( err ) {
102117 if ( err . code === 404 ) {
103- console . warn ( `Config ${ configId } not found during deletion:` , err . message ) ;
118+ console . warn ( `Config ${ configId } not found during deletion.` ) ;
104119 } else if ( err . code === 503 ) {
105- console . error ( `Service unavailable when deleting config ${ configId } :` , err . message ) ;
120+ console . error (
121+ `Service unavailable when deleting config ${ configId } :` ,
122+ err . message
123+ ) ;
106124 } else {
107- console . error ( `Unexpected error deleting config ${ configId } :` , err . message ) ;
125+ console . error (
126+ `Unexpected error deleting config ${ configId } :` ,
127+ err . message
128+ ) ;
108129 }
109130 }
110131 }
111132
112- await deleteNotificationConfig ( createConfig ) ;
113- await waitForConfig ( client , createConfig ) ;
114- await deleteNotificationConfig ( getConfig ) ;
115- await waitForConfig ( client , getConfig ) ;
116- await deleteNotificationConfig ( listConfig ) ;
117- await waitForConfig ( client , listConfig ) ;
118- await deleteNotificationConfig ( updateConfig ) ;
133+ await deleteNotificationConfigIfExists ( createConfig ) ;
134+ await deleteNotificationConfigIfExists ( getConfig ) ;
135+ await deleteNotificationConfigIfExists ( listConfig ) ;
136+ await deleteNotificationConfigIfExists ( updateConfig ) ;
119137 } ) ;
120138
121139 it ( 'client can create config' , ( ) => {
0 commit comments