|
| 1 | +using Digdir.Domain.Dialogporten.Application.Common; |
| 2 | +using Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Queries.Search; |
| 3 | +using Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.DialogSeenLogs.Queries.Get; |
| 4 | +using Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.DialogSeenLogs.Queries.Search; |
| 5 | +using Digdir.Domain.Dialogporten.Application.Integration.Tests.Common; |
| 6 | +using Digdir.Tool.Dialogporten.GenerateFakeData; |
| 7 | +using FluentAssertions; |
| 8 | +using Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.Dialogs.Queries.Get; |
| 9 | +using GetDialogQueryEndUser = Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.Dialogs.Queries.Get.GetDialogQuery; |
| 10 | +using GetDialogQueryServiceOwner = Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Queries.Get.GetDialogQuery; |
| 11 | + |
| 12 | +namespace Digdir.Domain.Dialogporten.Application.Integration.Tests.Features.V1.ServiceOwner.Dialogs.Queries; |
| 13 | + |
| 14 | +[Collection(nameof(DialogCqrsCollectionFixture))] |
| 15 | +public class SeenLogTests(DialogApplication application) : ApplicationCollectionFixture(application) |
| 16 | +{ |
| 17 | + [Fact] |
| 18 | + public async Task Get_Dialog_Should_Not_Return_User_Ids_Unhashed() |
| 19 | + { |
| 20 | + // Arrange |
| 21 | + var createDialogCommand = DialogGenerator.GenerateSimpleFakeDialog(); |
| 22 | + var createCommandResponse = await Application.Send(createDialogCommand); |
| 23 | + |
| 24 | + // Call EndUser API to trigger SeenLog |
| 25 | + await Application.Send(new GetDialogQueryEndUser { DialogId = createCommandResponse.AsT0.Value }); |
| 26 | + |
| 27 | + // Act |
| 28 | + var response = await Application.Send(new GetDialogQueryServiceOwner { DialogId = createCommandResponse.AsT0.Value }); |
| 29 | + |
| 30 | + // Assert |
| 31 | + response.TryPickT0(out var result, out _).Should().BeTrue(); |
| 32 | + result.Should().NotBeNull(); |
| 33 | + |
| 34 | + result.SeenSinceLastUpdate |
| 35 | + .Single() |
| 36 | + .EndUserIdHash |
| 37 | + .Should() |
| 38 | + .HaveLength(PersistentRandomSaltStringHasher.StringLength); |
| 39 | + } |
| 40 | + |
| 41 | + [Fact] |
| 42 | + public async Task Search_Dialog_Should_Not_Return_User_Ids_Unhashed() |
| 43 | + { |
| 44 | + // Arrange |
| 45 | + var createDialogCommand = DialogGenerator.GenerateSimpleFakeDialog(); |
| 46 | + var createCommandResponse = await Application.Send(createDialogCommand); |
| 47 | + |
| 48 | + // Trigger SeenLog |
| 49 | + await Application.Send(new GetDialogQueryEndUser { DialogId = createCommandResponse.AsT0.Value }); |
| 50 | + |
| 51 | + // Act |
| 52 | + var response = await Application.Send(new SearchDialogQuery |
| 53 | + { |
| 54 | + ServiceResource = [createDialogCommand.ServiceResource] |
| 55 | + }); |
| 56 | + |
| 57 | + // Assert |
| 58 | + response.TryPickT0(out var result, out _).Should().BeTrue(); |
| 59 | + result.Should().NotBeNull(); |
| 60 | + |
| 61 | + result.Items |
| 62 | + .Single() |
| 63 | + .SeenSinceLastUpdate |
| 64 | + .Single() |
| 65 | + .EndUserIdHash |
| 66 | + .Should() |
| 67 | + .HaveLength(PersistentRandomSaltStringHasher.StringLength); |
| 68 | + } |
| 69 | + |
| 70 | + [Fact] |
| 71 | + public async Task Get_SeenLog_Should_Not_Return_User_Ids_Unhashed() |
| 72 | + { |
| 73 | + // Arrange |
| 74 | + var createDialogCommand = DialogGenerator.GenerateSimpleFakeDialog(); |
| 75 | + var createCommandResponse = await Application.Send(createDialogCommand); |
| 76 | + |
| 77 | + var triggerSeenLogResponse = await Application.Send(new GetDialogQueryEndUser { DialogId = createCommandResponse.AsT0.Value }); |
| 78 | + var seenLogId = triggerSeenLogResponse.AsT0.SeenSinceLastUpdate.Single().Id; |
| 79 | + |
| 80 | + // Act |
| 81 | + var response = await Application.Send(new GetDialogSeenLogQuery |
| 82 | + { |
| 83 | + DialogId = createCommandResponse.AsT0.Value, |
| 84 | + SeenLogId = seenLogId |
| 85 | + }); |
| 86 | + |
| 87 | + // Assert |
| 88 | + response.TryPickT0(out var result, out _).Should().BeTrue(); |
| 89 | + result.Should().NotBeNull(); |
| 90 | + |
| 91 | + result.EndUserIdHash |
| 92 | + .Should() |
| 93 | + .HaveLength(PersistentRandomSaltStringHasher.StringLength); |
| 94 | + } |
| 95 | + |
| 96 | + [Fact] |
| 97 | + public async Task Search_SeenLog_Should_Not_Return_User_Ids_Unhashed() |
| 98 | + { |
| 99 | + // Arrange |
| 100 | + var createDialogCommand = DialogGenerator.GenerateSimpleFakeDialog(); |
| 101 | + var createCommandResponse = await Application.Send(createDialogCommand); |
| 102 | + |
| 103 | + // Trigger SeenLog |
| 104 | + await Application.Send(new GetDialogQueryEndUser { DialogId = createCommandResponse.AsT0.Value }); |
| 105 | + |
| 106 | + // Act |
| 107 | + var response = await Application.Send(new SearchDialogSeenLogQuery |
| 108 | + { |
| 109 | + DialogId = createCommandResponse.AsT0.Value, |
| 110 | + }); |
| 111 | + |
| 112 | + // Assert |
| 113 | + response.TryPickT0(out var result, out _).Should().BeTrue(); |
| 114 | + result.Should().NotBeNull(); |
| 115 | + |
| 116 | + result.Single() |
| 117 | + .EndUserIdHash |
| 118 | + .Should() |
| 119 | + .HaveLength(PersistentRandomSaltStringHasher.StringLength); |
| 120 | + } |
| 121 | +} |
0 commit comments