Skip to content

Commit

Permalink
SLVS-1474 Fix notifications are always disabled when creating DTO for…
Browse files Browse the repository at this point in the history
… connection needed for SlCore
  • Loading branch information
gabriela-trutan-sonarsource committed Oct 1, 2024
1 parent 5bfcc5d commit b568d66
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
37 changes: 35 additions & 2 deletions src/SLCore.UnitTests/State/ServerConnectionsProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,24 @@ public void GetServerConnections_CorrectlyReturnsSonarQubeConnection()
serverConnections.Should().HaveCount(1);
serverConnections[connection.Id].Should().BeOfType<SonarQubeConnectionConfigurationDto>().Which.serverUrl.Should().Be(servierUriString);
}


[TestMethod]
[DataRow(true)]
[DataRow(false)]
public void GetServerConnections_CorrectlyReturnsSonarQubeNotifications(bool isSmartNotificationsEnabled)
{
const string servierUriString = "http://localhost/";
var serverUri = new Uri(servierUriString);
var connection = new ServerConnection.SonarQube(serverUri, settings: new ServerConnectionSettings(isSmartNotificationsEnabled));
var serverConnectionsRepository = SetServerConnectionsRepository(succeeded: true, connection);
var testSubject = CreateTestSubject(serverConnectionsRepository);

var serverConnections = testSubject.GetServerConnections();

serverConnections.Should().HaveCount(1);
serverConnections[connection.Id].Should().BeOfType<SonarQubeConnectionConfigurationDto>().Which.disableNotification.Should().Be(!isSmartNotificationsEnabled);
}

[TestMethod]
public void GetServerConnections_CorrectlyReturnsSonarCloudConnection()
{
Expand All @@ -68,7 +85,23 @@ public void GetServerConnections_CorrectlyReturnsSonarCloudConnection()
serverConnections.Should().HaveCount(1);
serverConnections[connection.Id].Should().BeOfType<SonarCloudConnectionConfigurationDto>().Which.organization.Should().Be(organizationKey);
}


[TestMethod]
[DataRow(true)]
[DataRow(false)]
public void GetServerConnections_CorrectlyReturnsSonarCloudNotifications(bool isSmartNotificationsEnabled)
{
const string organizationKey = "org";
var connection = new ServerConnection.SonarCloud(organizationKey, settings: new ServerConnectionSettings(isSmartNotificationsEnabled));
var serverConnectionsRepository = SetServerConnectionsRepository(succeeded: true, connection);
var testSubject = CreateTestSubject(serverConnectionsRepository);

var serverConnections = testSubject.GetServerConnections();

serverConnections.Should().HaveCount(1);
serverConnections[connection.Id].Should().BeOfType<SonarCloudConnectionConfigurationDto>().Which.disableNotification.Should().Be(!isSmartNotificationsEnabled);
}

[TestMethod]
public void GetServerConnections_CorrectlyHandlesMultipleConnections()
{
Expand Down
4 changes: 2 additions & 2 deletions src/SLCore/State/ServerConnectionsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ private static List<ServerConnectionConfiguration> GetServerConnectionConfigurat
switch (serverConnection)
{
case ServerConnection.SonarQube sonarQubeConnection:
serverConnectionConfigurations.Add(new SonarQubeConnectionConfigurationDto(sonarQubeConnection.Id, sonarQubeConnection.Settings.IsSmartNotificationsEnabled, sonarQubeConnection.ServerUri.ToString()));
serverConnectionConfigurations.Add(new SonarQubeConnectionConfigurationDto(sonarQubeConnection.Id, !sonarQubeConnection.Settings.IsSmartNotificationsEnabled, sonarQubeConnection.ServerUri.ToString()));
break;
case ServerConnection.SonarCloud sonarCloudConnection:
serverConnectionConfigurations.Add(new SonarCloudConnectionConfigurationDto(sonarCloudConnection.Id, sonarCloudConnection.Settings.IsSmartNotificationsEnabled, sonarCloudConnection.OrganizationKey));
serverConnectionConfigurations.Add(new SonarCloudConnectionConfigurationDto(sonarCloudConnection.Id, !sonarCloudConnection.Settings.IsSmartNotificationsEnabled, sonarCloudConnection.OrganizationKey));
break;
default:
throw new InvalidOperationException(SLCoreStrings.UnexpectedServerConnectionType);
Expand Down

0 comments on commit b568d66

Please sign in to comment.