Skip to content

Commit

Permalink
Add missing where clause (#6403)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmoriceau committed May 8, 2023
1 parent ca40c14 commit 70df394
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ private void updateNotificationConfigurationIfNeeded(final List<NotificationConf
ctx.update(NOTIFICATION_CONFIGURATION)
.set(NOTIFICATION_CONFIGURATION.ENABLED, getNotificationEnabled(standardSync, notificationType))
.set(NOTIFICATION_CONFIGURATION.UPDATED_AT, timestamp)
.where(NOTIFICATION_CONFIGURATION.CONNECTION_ID.eq(standardSync.getConnectionId()))
.and(NOTIFICATION_CONFIGURATION.NOTIFICATION_TYPE.eq(notificationType))
.execute();
}
} else if (getNotificationEnabled(standardSync, notificationType)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,29 @@ void testWriteNotificationConfigurationIfNeeded() throws JsonValidationException
assertEquals(2, notificationConfigurations.size());
}

@Test
void testDontUpdateIfNotNeeded() throws JsonValidationException, IOException, SQLException {
createBaseObjects();

final StandardSync syncGa = createStandardSync(source1, destination1);
syncGa.setNotifySchemaChangesByEmail(true);
standardSyncPersistence.writeStandardSync(syncGa);
final StandardSync syncGa2 = createStandardSync(source2, destination2);
syncGa2.setNotifySchemaChangesByEmail(true);
standardSyncPersistence.writeStandardSync(syncGa2);

syncGa.setNotifySchemaChangesByEmail(false);
standardSyncPersistence.writeStandardSync(syncGa);
final List<NotificationConfigurationRecord> notificationConfigurations = getNotificationConfigurations();

assertEquals(2, notificationConfigurations.size());
assertEquals(NotificationType.email,
notificationConfigurations.stream().filter(notificationConfigurationRecord -> notificationConfigurationRecord.getConnectionId()
.equals(syncGa.getConnectionId())).map(record -> record.getNotificationType()).findFirst().get());
assertFalse(notificationConfigurations.stream().filter(notificationConfigurationRecord -> notificationConfigurationRecord.getConnectionId()
.equals(syncGa.getConnectionId())).map(record -> record.getEnabled()).findFirst().get());
}

private List<NotificationConfigurationRecord> getNotificationConfigurations() throws SQLException {
return database.query(ctx -> ctx.selectFrom(NOTIFICATION_CONFIGURATION).fetch());
}
Expand Down

0 comments on commit 70df394

Please sign in to comment.