Skip to content

Commit

Permalink
Fix tests, fix broken mappings, add missing properties to SO get/sear…
Browse files Browse the repository at this point in the history
…ch DTOs
  • Loading branch information
elsand committed Jul 21, 2024
1 parent af35e95 commit 0fdb308
Show file tree
Hide file tree
Showing 15 changed files with 582 additions and 118 deletions.
359 changes: 304 additions & 55 deletions docs/schema/V1/swagger.verified.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public async Task<GetDialogSeenLogResult> Handle(GetDialogSeenLogQuery request,
var dialog = await _dbContext.Dialogs
.AsNoTracking()
.Include(x => x.SeenLog.Where(x => x.Id == request.SeenLogId))
.ThenInclude(x => x.SeenBy)
.ThenInclude(x => x.SeenBy)
.IgnoreQueryFilters()
.FirstOrDefaultAsync(x => x.Id == request.DialogId,
cancellationToken: cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public MappingProfile()
CreateMap<DialogSeenLog, SearchDialogDialogSeenLogDto>()
.ForMember(dest => dest.SeenAt, opt => opt.MapFrom(src => src.CreatedAt));

CreateMap<DialogActor, SearchDialogDialogSeenLogActorDto>();
CreateMap<DialogActor, SearchDialogDialogSeenLogActorDto>()
.ForMember(dest => dest.ActorId, opt => opt.MapFrom(src => IdentifierMasker.GetMaybeMaskedIdentifier(src.ActorId)));

CreateMap<DialogActivity, SearchDialogDialogActivityDto>()
.ForMember(dest => dest.Type, opt => opt.MapFrom(src => src.TypeId));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using AutoMapper;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Actors;

namespace Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.DialogSeenLogs.Queries.Search;

Expand All @@ -9,5 +10,7 @@ public MappingProfile()
{
CreateMap<DialogSeenLog, SearchDialogSeenLogDto>()
.ForMember(dest => dest.SeenAt, opt => opt.MapFrom(src => src.CreatedAt));

CreateMap<DialogActor, SearchDialogSeenLogActorDto>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ public sealed class SearchDialogSeenLogDto
public Guid Id { get; set; }
public DateTimeOffset SeenAt { get; set; }

public SearchDialogSeenLogSeenByDto SeenBy { get; set; } = null!;
public SearchDialogSeenLogActorDto SeenBy { get; set; } = null!;

public bool? IsViaServiceOwner { get; set; }
}

public sealed class SearchDialogSeenLogSeenByDto
public sealed class SearchDialogSeenLogActorDto
{
public string ActorName { get; set; } = null!;
public string ActorId { get; set; } = null!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public async Task<SearchDialogSeenLogResult> Handle(SearchDialogSeenLogQuery req
var dialog = await _db.Dialogs
.AsNoTracking()
.Include(x => x.SeenLog)
.ThenInclude(x => x.SeenBy)
.IgnoreQueryFilters()
.Where(x => resourceIds.Contains(x.ServiceResource))
.FirstOrDefaultAsync(x => x.Id == request.DialogId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public MappingProfile()
.ForMember(dest => dest.SeenSinceLastUpdate, opt => opt.Ignore());

CreateMap<DialogSeenLog, GetDialogDialogSeenLogDto>();
CreateMap<DialogActor, GetDialogDialogSeenLogActorDto>();

CreateMap<DialogActivity, GetDialogDialogActivityDto>()
.ForMember(dest => dest.Type, opt => opt.MapFrom(src => src.TypeId));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using AutoMapper;
using Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Queries.Get;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Activities;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Actors;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Attachments;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Content;

namespace Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Queries.Search;
Expand All @@ -11,20 +12,35 @@ internal sealed class MappingProfile : Profile
public MappingProfile()
{
CreateMap<DialogEntity, SearchDialogDto>()
.ForMember(dest => dest.LatestActivity, opt => opt.MapFrom(src => src.Activities
.Where(activity => activity.TypeId != DialogActivityType.Values.Forwarded)
.OrderByDescending(activity => activity.CreatedAt).ThenByDescending(activity => activity.Id)
.FirstOrDefault()
))
.ForMember(dest => dest.SeenSinceLastUpdate, opt => opt.MapFrom(src => src.SeenLog
.Where(x => x.CreatedAt >= x.Dialog.UpdatedAt)
.OrderByDescending(x => x.CreatedAt)
))
.ForMember(dest => dest.GuiAttachmentCount, opt => opt.MapFrom(src => src.Attachments
.Count(x => x.Urls
.Any(url => url.ConsumerTypeId == DialogAttachmentUrlConsumerType.Values.Gui))))
.ForMember(dest => dest.Content, opt => opt.MapFrom(src => src.Content.Where(x => x.Type.OutputInList)))
.ForMember(dest => dest.Status, opt => opt.MapFrom(src => src.StatusId));

CreateMap<DialogSeenLog, SearchDialogDialogSeenLogDto>();
CreateMap<DialogContent, SearchDialogContentDto>()
.ForMember(dest => dest.Type, opt => opt.MapFrom(src => src.TypeId));

CreateMap<DialogActor, GetDialogDialogSeenLogActorDto>();
CreateMap<DialogSeenLog, SearchDialogDialogSeenLogDto>()
.ForMember(dest => dest.SeenAt, opt => opt.MapFrom(src => src.CreatedAt));

CreateMap<DialogSearchTag, SearchDialogSearchTagDto>();
CreateMap<DialogActor, SearchDialogDialogSeenLogActorDto>()
.ForMember(dest => dest.ActorId, opt => opt.MapFrom(src => src.ActorId));

CreateMap<DialogContent, SearchDialogContentDto>()
CreateMap<DialogActivity, SearchDialogDialogActivityDto>()
.ForMember(dest => dest.Type, opt => opt.MapFrom(src => src.TypeId));

CreateMap<DialogActor, SearchDialogDialogActivityActorDto>()
.ForMember(dest => dest.ActorType, opt => opt.MapFrom(src => src.ActorTypeId))
.ForMember(dest => dest.ActorId, opt => opt.MapFrom(src => src.ActorId));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Digdir.Domain.Dialogporten.Application.Features.V1.Common.Localizations;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Activities;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Actors;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Content;

namespace Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Queries.Search;
Expand All @@ -13,6 +15,7 @@ public sealed class SearchDialogDto
public string Party { get; set; } = null!;
public string? EndUserId { get; set; }
public int? Progress { get; set; }
public int? GuiAttachmentCount { get; set; }
public string? ExtendedStatus { get; set; }
public DateTimeOffset CreatedAt { get; set; }
public DateTimeOffset UpdatedAt { get; set; }
Expand All @@ -21,6 +24,8 @@ public sealed class SearchDialogDto

public DialogStatus.Values Status { get; set; }

public SearchDialogDialogActivityDto? LatestActivity { get; set; }

public List<SearchDialogContentDto> Content { get; set; } = [];
public List<SearchDialogDialogSeenLogDto> SeenSinceLastUpdate { get; set; } = [];
}
Expand Down Expand Up @@ -52,3 +57,24 @@ public sealed class SearchDialogContentDto
public DialogContentType.Values Type { get; set; }
public List<LocalizationDto> Value { get; set; } = [];
}

public sealed class SearchDialogDialogActivityDto
{
public Guid Id { get; set; }
public DateTimeOffset? CreatedAt { get; set; }
public Uri? ExtendedType { get; set; }

public DialogActivityType.Values Type { get; set; }

public Guid? RelatedActivityId { get; set; }

public SearchDialogDialogActivityActorDto PerformedBy { get; set; } = new();
public List<LocalizationDto> Description { get; set; } = [];
}

public sealed class SearchDialogDialogActivityActorDto
{
public DialogActorType.Values ActorType { get; set; }
public string? ActorName { get; set; }
public string? ActorId { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,12 @@ public async Task<SearchDialogResult> Handle(SearchDialogQuery request, Cancella
.ProjectTo<SearchDialogDto>(_mapper.ConfigurationProvider)
.ToPaginatedListAsync(request, cancellationToken: cancellationToken);

foreach (var seenRecord in paginatedList.Items.SelectMany(x => x.SeenSinceLastUpdate))
if (request.EndUserId is not null)
{
if (request.EndUserId is not null)
foreach (var seenRecord in paginatedList.Items.SelectMany(x => x.SeenSinceLastUpdate))
{
seenRecord.IsCurrentEndUser = seenRecord.SeenBy.ActorId == request.EndUserId;

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ public static string GenerateFakeResource()
return ResourcePrefix + result.ToString("D4", CultureInfo.InvariantCulture);
}

public static string GenerateRandomParty()
public static string GenerateRandomParty(bool forcePerson = false)
{
var r = new Randomizer();
return r.Bool() ? $"urn:altinn:organization:identifier-no:{GenerateFakeOrgNo()}" : $"urn:altinn:person:identifier-no:{GenerateFakePid()}";
return r.Bool() && !forcePerson ? $"urn:altinn:organization:identifier-no:{GenerateFakeOrgNo()}" : $"urn:altinn:person:identifier-no:{GenerateFakePid()}";
}

private static readonly int[] SocialSecurityNumberWeights1 = [3, 7, 6, 1, 8, 9, 4, 5, 2];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.Dialogs.Queries.Get;
using Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.Dialogs.Queries.Search;
using Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.DialogActivities.Queries.Get;
using Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Commands.Create;
using Digdir.Domain.Dialogporten.Application.Integration.Tests.Common;
using Digdir.Domain.Dialogporten.Domain.Parties;
using Digdir.Tool.Dialogporten.GenerateFakeData;
using FluentAssertions;

namespace Digdir.Domain.Dialogporten.Application.Integration.Tests.Features.V1.EndUser.Dialogs.Queries;

[Collection(nameof(DialogCqrsCollectionFixture))]
public class ActivityLogTests(DialogApplication application) : ApplicationCollectionFixture(application)
{
[Fact]
public async Task Get_Dialog_ActivityLog_Should_Not_Return_User_Ids_Unhashed()
{
var (_, createCommandResponse) = await GenerateDialogWithActivity();

// Act
var response = await Application.Send(new GetDialogQuery { DialogId = createCommandResponse.AsT0.Value });

// Assert
response.TryPickT0(out var result, out _).Should().BeTrue();
result.Should().NotBeNull();

result.Activities
.Single()
.PerformedBy.ActorId
.Should()
.StartWith(NorwegianPersonIdentifier.HashPrefixWithSeparator);

}

[Fact]
public async Task Search_Dialog_LatestActivity_Should_Not_Return_User_Ids_Unhashed()
{
// Arrange
var (createDialogCommand, _) = await GenerateDialogWithActivity();

// Act
var response = await Application.Send(new SearchDialogQuery
{
ServiceResource = [createDialogCommand.ServiceResource]
});

// Assert
response.TryPickT0(out var result, out _).Should().BeTrue();
result.Should().NotBeNull();

result.Items
.Single()
.LatestActivity!
.PerformedBy.ActorId
.Should()
.StartWith(NorwegianPersonIdentifier.HashPrefixWithSeparator);
}

[Fact]
public async Task Get_ActivityLog_Should_Not_Return_User_Ids_Unhashed()
{
// Arrange
var (_, createCommandResponse) = await GenerateDialogWithActivity();

var getDialogResult = await Application.Send(new GetDialogQuery { DialogId = createCommandResponse.AsT0.Value });
var activityId = getDialogResult.AsT0.Activities.First().Id;

// Act
var response = await Application.Send(new GetDialogActivityQuery()
{
DialogId = createCommandResponse.AsT0.Value,
ActivityId = activityId
});

// Assert
response.TryPickT0(out var result, out _).Should().BeTrue();
result.Should().NotBeNull();

result.PerformedBy.ActorId
.Should()
.StartWith(NorwegianPersonIdentifier.HashPrefixWithSeparator);
}

private async Task<(CreateDialogCommand, CreateDialogResult)> GenerateDialogWithActivity()
{
var createDialogCommand = DialogGenerator.GenerateSimpleFakeDialog();
var activity = DialogGenerator.GenerateFakeDialogActivity();
activity.PerformedBy.ActorId = DialogGenerator.GenerateRandomParty(forcePerson: true);
activity.PerformedBy.ActorName = null;
createDialogCommand.Activities.Add(activity);
var createCommandResponse = await Application.Send(createDialogCommand);
return (createDialogCommand, createCommandResponse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.DialogSeenLogs.Queries.Get;
using Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.DialogSeenLogs.Queries.Search;
using Digdir.Domain.Dialogporten.Application.Integration.Tests.Common;
using Digdir.Domain.Dialogporten.Domain.Parties;
using Digdir.Tool.Dialogporten.GenerateFakeData;
using FluentAssertions;

Expand All @@ -13,9 +14,9 @@ namespace Digdir.Domain.Dialogporten.Application.Integration.Tests.Features.V1.E
public class SeenLogTests(DialogApplication application) : ApplicationCollectionFixture(application)
{
[Fact]
public Task Get_Dialog_Should_Not_Return_User_Ids_Unhashed()
public async Task Get_Dialog_SeenLog_Should_Not_Return_User_Ids_Unhashed()
{
/*

var createDialogCommand = DialogGenerator.GenerateSimpleFakeDialog();
var createCommandResponse = await Application.Send(createDialogCommand);

Expand All @@ -28,17 +29,15 @@ public Task Get_Dialog_Should_Not_Return_User_Ids_Unhashed()

result.SeenSinceLastUpdate
.Single()
.EndUserIdHash
.SeenBy.ActorId
.Should()
.HaveLength(PersistentRandomSaltStringHasher.StringLength);
*/
throw new NotImplementedException();
.StartWith(NorwegianPersonIdentifier.HashPrefixWithSeparator);

}

[Fact]
public Task Search_Dialog_Should_Not_Return_User_Ids_Unhashed()
public async Task Search_Dialog_SeenLog_Should_Not_Return_User_Ids_Unhashed()
{
/*
// Arrange
var createDialogCommand = DialogGenerator.GenerateSimpleFakeDialog();
var createCommandResponse = await Application.Send(createDialogCommand);
Expand All @@ -60,17 +59,14 @@ public Task Search_Dialog_Should_Not_Return_User_Ids_Unhashed()
.Single()
.SeenSinceLastUpdate
.Single()
.EndUserIdHash
.SeenBy.ActorId
.Should()
.HaveLength(PersistentRandomSaltStringHasher.StringLength);
*/
throw new NotImplementedException();
.StartWith(NorwegianPersonIdentifier.HashPrefixWithSeparator);
}

[Fact]
public Task Get_SeenLog_Should_Not_Return_User_Ids_Unhashed()
public async Task Get_SeenLog_Should_Not_Return_User_Ids_Unhashed()
{
/*
// Arrange
var createDialogCommand = DialogGenerator.GenerateSimpleFakeDialog();
var createCommandResponse = await Application.Send(createDialogCommand);
Expand All @@ -89,17 +85,14 @@ public Task Get_SeenLog_Should_Not_Return_User_Ids_Unhashed()
response.TryPickT0(out var result, out _).Should().BeTrue();
result.Should().NotBeNull();

result.EndUserIdHash
result.SeenBy.ActorId
.Should()
.HaveLength(PersistentRandomSaltStringHasher.StringLength);
*/
throw new NotImplementedException();
.StartWith(NorwegianPersonIdentifier.HashPrefixWithSeparator);
}

[Fact]
public Task Search_SeenLog_Should_Not_Return_User_Ids_Unhashed()
public async Task Search_SeenLog_Should_Not_Return_User_Ids_Unhashed()
{
/*
// Arrange
var createDialogCommand = DialogGenerator.GenerateSimpleFakeDialog();
var createCommandResponse = await Application.Send(createDialogCommand);
Expand All @@ -118,11 +111,8 @@ public Task Search_SeenLog_Should_Not_Return_User_Ids_Unhashed()
result.Should().NotBeNull();

result.Single()
.EndUserIdHash
.SeenBy.ActorId
.Should()
.HaveLength(PersistentRandomSaltStringHasher.StringLength);
*/
throw new NotImplementedException();
.StartWith(NorwegianPersonIdentifier.HashPrefixWithSeparator);
}
}
Loading

0 comments on commit 0fdb308

Please sign in to comment.