-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add notification condition tests (#1385)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced integration tests for notification conditions in the Dialogporten application, ensuring accurate notification sending based on various conditions. - **Bug Fixes** - Added a configuration setting to suppress specific IDE warnings, enhancing the development experience without impacting functionality. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
- Loading branch information
Showing
2 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[*] | ||
# CA1707: Identifiers should not contain underscores | ||
dotnet_diagnostic.CA1707.severity = none | ||
dotnet_diagnostic.CA1707.severity = none | ||
|
||
# IDE0010: Add missing cases to switch statements | ||
dotnet_diagnostic.IDE0010.severity = none |
97 changes: 97 additions & 0 deletions
97
...ration.Tests/Features/V1/ServiceOwner/NotificationCondition/NotificationConditionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
using Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.DialogActivities.Queries.NotificationCondition; | ||
using Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Commands.Create; | ||
using Digdir.Domain.Dialogporten.Application.Integration.Tests.Common; | ||
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Activities; | ||
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Transmissions; | ||
using Digdir.Tool.Dialogporten.GenerateFakeData; | ||
using FluentAssertions; | ||
|
||
namespace Digdir.Domain.Dialogporten.Application.Integration.Tests.Features.V1.ServiceOwner.NotificationCondition; | ||
|
||
[Collection(nameof(DialogCqrsCollectionFixture))] | ||
public class NotificationConditionTests(DialogApplication application) : ApplicationCollectionFixture(application) | ||
{ | ||
private static readonly bool[] ExpectedSendNotificationsValues = [true, false]; | ||
|
||
public static IEnumerable<object[]> NotificationConditionTestData() => | ||
from bool expectedSendNotificationValue in ExpectedSendNotificationsValues | ||
from DialogActivityType.Values activityType in Enum.GetValues(typeof(DialogActivityType.Values)) | ||
from NotificationConditionType conditionType in Enum.GetValues(typeof(NotificationConditionType)) | ||
select new object[] { activityType, conditionType, expectedSendNotificationValue }; | ||
|
||
|
||
[Theory, MemberData(nameof(NotificationConditionTestData))] | ||
public async Task SendNotification_Should_Be_True_When_Conditions_Are_Met( | ||
DialogActivityType.Values activityType, | ||
NotificationConditionType conditionType, | ||
bool expectedSendNotificationValue) | ||
{ | ||
// Arrange | ||
var createDialogCommand = DialogGenerator.GenerateSimpleFakeDialog(); | ||
switch (conditionType) | ||
{ | ||
case NotificationConditionType.Exists when expectedSendNotificationValue: | ||
case NotificationConditionType.NotExists when !expectedSendNotificationValue: | ||
AddActivityRequirements(createDialogCommand, activityType); | ||
break; | ||
} | ||
|
||
var response = await Application.Send(createDialogCommand); | ||
response.TryPickT0(out var dialogId, out _); | ||
|
||
var notificationConditionQuery = new NotificationConditionQuery | ||
{ | ||
DialogId = dialogId.Value, | ||
ActivityType = activityType, | ||
ConditionType = conditionType, | ||
}; | ||
|
||
if (activityType is DialogActivityType.Values.TransmissionOpened) | ||
{ | ||
var transmissionId = createDialogCommand.Transmissions.FirstOrDefault()?.Id ?? Guid.NewGuid(); | ||
notificationConditionQuery.TransmissionId = transmissionId; | ||
} | ||
|
||
// Act | ||
var queryResult = await Application.Send(notificationConditionQuery); | ||
|
||
// Assert | ||
queryResult.TryPickT0(out var notificationConditionResult, out _); | ||
queryResult.IsT0.Should().BeTrue(); | ||
notificationConditionResult.SendNotification.Should().Be(expectedSendNotificationValue); | ||
} | ||
|
||
private static void AddActivityRequirements( | ||
CreateDialogCommand createDialogCommand, | ||
DialogActivityType.Values activityType) | ||
{ | ||
var activity = DialogGenerator.GenerateFakeDialogActivity(type: activityType); | ||
createDialogCommand.Activities.Add(activity); | ||
|
||
if (activityType is not DialogActivityType.Values.TransmissionOpened) return; | ||
|
||
var transmission = DialogGenerator.GenerateFakeDialogTransmissions(type: DialogTransmissionType.Values.Information)[0]; | ||
createDialogCommand.Transmissions.Add(transmission); | ||
createDialogCommand.Activities[0].TransmissionId = createDialogCommand.Transmissions[0].Id; | ||
} | ||
|
||
[Fact] | ||
public async Task NotFound_Should_Be_Returned_When_Dialog_Does_Not_Exist() | ||
{ | ||
// Arrange | ||
var notificationConditionQuery = new NotificationConditionQuery | ||
{ | ||
DialogId = Guid.NewGuid(), | ||
ActivityType = DialogActivityType.Values.Information, | ||
ConditionType = NotificationConditionType.Exists, | ||
}; | ||
|
||
// Act | ||
var queryResult = await Application.Send(notificationConditionQuery); | ||
|
||
// Assert | ||
queryResult.TryPickT2(out var notFound, out _); | ||
queryResult.IsT2.Should().BeTrue(); | ||
notFound.Should().NotBeNull(); | ||
} | ||
} |