5858
5959class WorkspacesHandlerTest {
6060
61- public static final String FAILURE_NOTIFICATION_WEBHOOK = "http://airbyte.notifications/failure" ;
62- public static final String NEW_WORKSPACE = "new workspace" ;
63- public static final String TEST_NAME = "test-name" ;
61+ private static final String FAILURE_NOTIFICATION_WEBHOOK = "http://airbyte.notifications/failure" ;
62+ private static final String NEW_WORKSPACE = "new workspace" ;
63+ private static final String TEST_NAME = "test-name" ;
64+
65+ private static final String TEST_AUTH_TOKEN = "test-auth-token" ;
6466 private static final UUID WEBHOOK_CONFIG_ID = UUID .randomUUID ();
6567 private static final JsonNode PERSISTED_WEBHOOK_CONFIGS = Jsons .deserialize (
6668 String .format ("{\" webhookConfigs\" : [{\" id\" : \" %s\" , \" name\" : \" %s\" , \" authToken\" : {\" _secret\" : \" a-secret_v1\" }}]}" ,
6769 WEBHOOK_CONFIG_ID , TEST_NAME ));
70+ public static final String UPDATED = "updated" ;
6871 private ConfigRepository configRepository ;
6972 private SecretsRepositoryWriter secretsRepositoryWriter ;
7073 private ConnectionsHandler connectionsHandler ;
@@ -149,7 +152,7 @@ void testCreateWorkspace() throws JsonValidationException, IOException, ConfigNo
149152 .securityUpdates (false )
150153 .notifications (List .of (generateApiNotification ()))
151154 .defaultGeography (GEOGRAPHY_US )
152- .webhookConfigs (List .of (new WebhookConfigWrite ().name (TEST_NAME ).authToken ("test-auth-token" )));
155+ .webhookConfigs (List .of (new WebhookConfigWrite ().name (TEST_NAME ).authToken (TEST_AUTH_TOKEN )));
153156
154157 final WorkspaceRead actualRead = workspacesHandler .createWorkspace (workspaceCreate );
155158 final WorkspaceRead expectedRead = new WorkspaceRead ()
@@ -359,7 +362,7 @@ void testGetWorkspaceByConnectionId() {
359362 @ Test
360363 void testUpdateWorkspace () throws JsonValidationException , ConfigNotFoundException , IOException {
361364 final io .airbyte .api .model .generated .Notification apiNotification = generateApiNotification ();
362- apiNotification .getSlackConfiguration ().webhook ("updated" );
365+ apiNotification .getSlackConfiguration ().webhook (UPDATED );
363366 final WorkspaceUpdate workspaceUpdate = new WorkspaceUpdate ()
364367 .workspaceId (workspace .getWorkspaceId ())
365368 .anonymousDataCollection (true )
@@ -372,7 +375,7 @@ void testUpdateWorkspace() throws JsonValidationException, ConfigNotFoundExcepti
372375 .webhookConfigs (List .of (new WebhookConfigWrite ().name (TEST_NAME ).authToken ("test-auth-token" )));
373376
374377 final Notification expectedNotification = generateNotification ();
375- expectedNotification .getSlackConfiguration ().withWebhook ("updated" );
378+ expectedNotification .getSlackConfiguration ().withWebhook (UPDATED );
376379 final StandardWorkspace expectedWorkspace = new StandardWorkspace ()
377380 .withWorkspaceId (workspace .getWorkspaceId ())
378381 .withCustomerId (workspace .getCustomerId ())
@@ -398,7 +401,7 @@ void testUpdateWorkspace() throws JsonValidationException, ConfigNotFoundExcepti
398401 final WorkspaceRead actualWorkspaceRead = workspacesHandler .updateWorkspace (workspaceUpdate );
399402
400403 final io .airbyte .api .model .generated .Notification expectedNotificationRead = generateApiNotification ();
401- expectedNotificationRead .getSlackConfiguration ().webhook ("updated" );
404+ expectedNotificationRead .getSlackConfiguration ().webhook (UPDATED );
402405 final WorkspaceRead expectedWorkspaceRead = new WorkspaceRead ()
403406 .workspaceId (workspace .getWorkspaceId ())
404407 .customerId (workspace .getCustomerId ())
@@ -419,6 +422,43 @@ void testUpdateWorkspace() throws JsonValidationException, ConfigNotFoundExcepti
419422 assertEquals (expectedWorkspaceRead , actualWorkspaceRead );
420423 }
421424
425+ @ Test
426+ void testUpdateWorkspaceWithoutWebhookConfigs () throws JsonValidationException , ConfigNotFoundException , IOException {
427+ final io .airbyte .api .model .generated .Notification apiNotification = generateApiNotification ();
428+ apiNotification .getSlackConfiguration ().webhook (UPDATED );
429+ final WorkspaceUpdate workspaceUpdate = new WorkspaceUpdate ()
430+ .workspaceId (workspace .getWorkspaceId ())
431+ .anonymousDataCollection (false );
432+
433+ final Notification expectedNotification = generateNotification ();
434+ expectedNotification .getSlackConfiguration ().withWebhook (UPDATED );
435+ final StandardWorkspace expectedWorkspace = new StandardWorkspace ()
436+ .withWorkspaceId (workspace .getWorkspaceId ())
437+ .withCustomerId (workspace .getCustomerId ())
438+ .withEmail (TEST_EMAIL )
439+ .withName (TEST_WORKSPACE_NAME )
440+ .withSlug (TEST_WORKSPACE_SLUG )
441+ .withAnonymousDataCollection (true )
442+ .withSecurityUpdates (false )
443+ .withNews (false )
444+ .withInitialSetupComplete (true )
445+ .withDisplaySetupWizard (false )
446+ .withTombstone (false )
447+ .withNotifications (List .of (expectedNotification ))
448+ .withDefaultGeography (Geography .US )
449+ .withWebhookOperationConfigs (PERSISTED_WEBHOOK_CONFIGS );
450+
451+ when (uuidSupplier .get ()).thenReturn (WEBHOOK_CONFIG_ID );
452+
453+ when (configRepository .getStandardWorkspaceNoSecrets (workspace .getWorkspaceId (), false ))
454+ .thenReturn (expectedWorkspace )
455+ .thenReturn (expectedWorkspace .withAnonymousDataCollection (false ));
456+
457+ workspacesHandler .updateWorkspace (workspaceUpdate );
458+
459+ verify (configRepository ).writeStandardWorkspaceNoSecrets (expectedWorkspace );
460+ }
461+
422462 @ Test
423463 @ DisplayName ("Updating workspace name should update name and slug" )
424464 void testUpdateWorkspaceNoNameUpdate () throws JsonValidationException , ConfigNotFoundException , IOException {
0 commit comments