Skip to content

Commit

Permalink
chore: Add transmission content values test (#1200)
Browse files Browse the repository at this point in the history
<!--- Provide a general summary of your changes in the Title above -->

## Description

Adding test for required content on transmissions

## Related Issue(s)

- #1197 

## Verification

- [x] **Your** code builds clean without any errors or warnings
- [x] Manual testing done (required)
- [x] Relevant automated test added (if you find this hard, leave it and
we'll help out)

## Documentation

- [ ] Documentation is updated (either in `docs`-directory, Altinnpedia
or a separate linked PR in
[altinn-studio-docs.](https://github.com/Altinn/altinn-studio-docs), if
applicable)


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Added support for generating fake dialog transmissions with new
parameters in dialog generation methods.

- **Bug Fixes**
- Introduced validation tests to ensure that dialog transmissions cannot
be created without required content values.

- **Tests**
- Added new test cases to validate the creation of dialog transmissions
under specific conditions.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
oskogstad authored Sep 26, 2024
1 parent 8e570b4 commit d5729de
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 13 deletions.
16 changes: 10 additions & 6 deletions src/Digdir.Tool.Dialogporten.GenerateFakeData/DialogGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public static CreateDialogCommand GenerateFakeDialog(
List<CreateDialogDialogAttachmentDto>? attachments = null,
List<CreateDialogDialogGuiActionDto>? guiActions = null,
List<CreateDialogDialogApiActionDto>? apiActions = null,
List<CreateDialogDialogActivityDto>? activities = null)
List<CreateDialogDialogActivityDto>? activities = null,
List<CreateDialogDialogTransmissionDto>? transmissions = null)
{
return GenerateFakeDialogs(
seed,
Expand All @@ -60,12 +61,12 @@ public static CreateDialogCommand GenerateFakeDialog(
attachments,
guiActions,
apiActions,
activities
activities,
transmissions
)[0];
}

public static List<CreateDialogCommand> GenerateFakeDialogs(
int? seed = null,
public static List<CreateDialogCommand> GenerateFakeDialogs(int? seed = null,
int count = 1,
Guid? id = null,
string? serviceResource = null,
Expand All @@ -86,7 +87,8 @@ public static List<CreateDialogCommand> GenerateFakeDialogs(
List<CreateDialogDialogAttachmentDto>? attachments = null,
List<CreateDialogDialogGuiActionDto>? guiActions = null,
List<CreateDialogDialogApiActionDto>? apiActions = null,
List<CreateDialogDialogActivityDto>? activities = null)
List<CreateDialogDialogActivityDto>? activities = null,
List<CreateDialogDialogTransmissionDto>? transmissions = null)
{
Randomizer.Seed = seed.HasValue ? new Random(seed.Value) : new Random();
return new Faker<CreateDialogCommand>()
Expand All @@ -108,6 +110,7 @@ public static List<CreateDialogCommand> GenerateFakeDialogs(
.RuleFor(o => o.ApiActions, _ => apiActions ?? GenerateFakeDialogApiActions())
.RuleFor(o => o.Activities, _ => activities ?? GenerateFakeDialogActivities())
.RuleFor(o => o.Process, f => process ?? GenerateFakeProcessUri())
.RuleFor(o => o.Transmissions, f => transmissions ?? GenerateFakeDialogTransmissions())
.Generate(count);
}

Expand All @@ -121,7 +124,8 @@ public static CreateDialogCommand GenerateSimpleFakeDialog(Guid? id = null)
attachments: [],
guiActions: [],
apiActions: [],
searchTags: []);
searchTags: [],
transmissions: []);
}

public static string GenerateFakeResource(Func<string?>? generator = null)
Expand Down
8 changes: 2 additions & 6 deletions src/Digdir.Tool.Dialogporten.GenerateFakeData/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ private static async Task RunAsync(Options options)
Randomizer.Seed = new Random(options.Seed);
var dialogs = DialogGenerator.GenerateFakeDialogs(
seed: new Randomizer().Number(int.MaxValue),
serviceResourceGenerator: () => MaybeGetRandomResource(options),
partyGenerator: () => MaybeGetRandomParty(options),
count: options.Count);
count: options.Count, serviceResourceGenerator: () => MaybeGetRandomResource(options), partyGenerator: () => MaybeGetRandomParty(options));
var serialized = JsonSerializer.Serialize(dialogs, JsonSerializerOptions);
Console.WriteLine(serialized);
return;
Expand Down Expand Up @@ -118,9 +116,7 @@ private static void ProduceDialogs(Options options, BlockingCollection<(int, Cre
var dialogsToGenerate = Math.Min(DialogsPerBatch, totalDialogs - dialogCounter);
var dialogs = DialogGenerator.GenerateFakeDialogs(
seed: new Randomizer().Number(int.MaxValue),
serviceResourceGenerator: () => MaybeGetRandomResource(options),
partyGenerator: () => MaybeGetRandomParty(options),
count: dialogsToGenerate).Take(dialogsToGenerate);
count: dialogsToGenerate, serviceResourceGenerator: () => MaybeGetRandomResource(options), partyGenerator: () => MaybeGetRandomParty(options)).Take(dialogsToGenerate);
foreach (var dialog in dialogs)
{
dialogQueue.Add((dialogCounter + 1, dialog), cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Queries.Get;
using Castle.Core.Logging;
using Digdir.Domain.Dialogporten.Application.Features.V1.Common.Localizations;
using Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Queries.Get;
using Digdir.Domain.Dialogporten.Application.Integration.Tests.Common;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Transmissions;
using Digdir.Tool.Dialogporten.GenerateFakeData;
using FluentAssertions;
using static Digdir.Domain.Dialogporten.Application.Integration.Tests.UuiDv7Utils;
Expand Down Expand Up @@ -203,4 +206,70 @@ public async Task Can_Create_Dialog_With_UpdatedAt_And_CreatedAt_Being_Equal()
response.TryPickT0(out var success, out _).Should().BeTrue();
success.Should().NotBeNull();
}

[Fact]
public async Task Cannot_Create_Transmission_Without_Content()
{
// Arrange
var transmission = DialogGenerator.GenerateFakeDialogTransmissions(1)[0];
transmission.Content = null!;

var createDialogCommand = DialogGenerator.GenerateSimpleFakeDialog();
createDialogCommand.Transmissions = [transmission];

// Act
var response = await Application.Send(createDialogCommand);

// Assert
response.TryPickT2(out var validationError, out _).Should().BeTrue();
validationError.Should().NotBeNull();
validationError.Errors.Should().HaveCount(1);
validationError.Errors.First().ErrorMessage.Should().Contain("'Content' must not be empty");
}

[Fact]
public async Task Cannot_Create_Transmission_Without_Content_Value()
{
// Arrange
var transmission = DialogGenerator.GenerateFakeDialogTransmissions(1)[0];
transmission.Content.Summary.Value = [];
transmission.Content.Title.Value = [];

var createDialogCommand = DialogGenerator.GenerateSimpleFakeDialog();
createDialogCommand.Transmissions = [transmission];

// Act
var response = await Application.Send(createDialogCommand);

// Assert
response.TryPickT2(out var validationError, out _).Should().BeTrue();
validationError.Should().NotBeNull();
validationError.Errors
.Count(e => e.PropertyName.Contains(nameof(createDialogCommand.Content)))
.Should()
.Be(2);
}

[Fact]
public async Task Cannot_Create_Transmission_With_Empty_Content_Localization_Values()
{
// Arrange
var transmission = DialogGenerator.GenerateFakeDialogTransmissions(1)[0];
transmission.Content.Summary.Value = [new LocalizationDto { LanguageCode = "nb", Value = "" }];
transmission.Content.Title.Value = [new LocalizationDto { LanguageCode = "nb", Value = "" }];

var createDialogCommand = DialogGenerator.GenerateSimpleFakeDialog();
createDialogCommand.Transmissions = [transmission];

// Act
var response = await Application.Send(createDialogCommand);

// Assert
response.TryPickT2(out var validationError, out _).Should().BeTrue();
validationError.Should().NotBeNull();
validationError.Errors
.Count(e => e.PropertyName.Contains(nameof(createDialogCommand.Content)))
.Should()
.Be(2);
}
}

0 comments on commit d5729de

Please sign in to comment.