Skip to content

Commit

Permalink
Add missing predicates, clean up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
elsand committed Nov 25, 2024
1 parent 298b682 commit a2face6
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using AutoMapper;
using Digdir.Domain.Dialogporten.Application.Common;
using Digdir.Domain.Dialogporten.Application.Common.Extensions;
using Digdir.Domain.Dialogporten.Application.Common.ReturnTypes;
using Digdir.Domain.Dialogporten.Application.Externals;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities;
Expand Down Expand Up @@ -44,7 +45,7 @@ public async Task<GetSeenLogResult> Handle(GetSeenLogQuery request,
.Include(x => x.SeenLog.Where(x => x.Id == request.SeenLogId))
.ThenInclude(x => x.SeenBy)
.IgnoreQueryFilters()
.Where(x => resourceIds.Contains(x.ServiceResource))
.WhereIf(!_userResourceRegistry.IsCurrentUserServiceOwnerAdmin(), x => resourceIds.Contains(x.ServiceResource))
.FirstOrDefaultAsync(x => x.Id == request.DialogId,
cancellationToken: cancellationToken);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using AutoMapper;
using Digdir.Domain.Dialogporten.Application.Common;
using Digdir.Domain.Dialogporten.Application.Common.Extensions;
using Digdir.Domain.Dialogporten.Application.Common.ReturnTypes;
using Digdir.Domain.Dialogporten.Application.Externals;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities;
Expand Down Expand Up @@ -42,7 +43,7 @@ public async Task<SearchSeenLogResult> Handle(SearchSeenLogQuery request, Cancel
.Include(x => x.SeenLog)
.ThenInclude(x => x.SeenBy)
.IgnoreQueryFilters()
.Where(x => resourceIds.Contains(x.ServiceResource))
.WhereIf(!_userResourceRegistry.IsCurrentUserServiceOwnerAdmin(), x => resourceIds.Contains(x.ServiceResource))
.FirstOrDefaultAsync(x => x.Id == request.DialogId,
cancellationToken: cancellationToken);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Diagnostics;
using Digdir.Domain.Dialogporten.Application.Common;
using Digdir.Domain.Dialogporten.Application.Common.Extensions;
using Digdir.Domain.Dialogporten.Application.Common.ReturnTypes;
using Digdir.Domain.Dialogporten.Application.Externals;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities;
Expand Down Expand Up @@ -42,7 +43,7 @@ public async Task<DeleteDialogResult> Handle(DeleteDialogCommand request, Cancel

var dialog = await _db.Dialogs
.Include(x => x.Activities)
.Where(x => resourceIds.Contains(x.ServiceResource))
.WhereIf(!_userResourceRegistry.IsCurrentUserServiceOwnerAdmin(), x => resourceIds.Contains(x.ServiceResource))
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken);

if (dialog is null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Diagnostics;
using Digdir.Domain.Dialogporten.Application.Common;
using Digdir.Domain.Dialogporten.Application.Common.Extensions;
using Digdir.Domain.Dialogporten.Application.Common.ReturnTypes;
using Digdir.Domain.Dialogporten.Application.Externals;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities;
Expand Down Expand Up @@ -42,7 +43,7 @@ public async Task<PurgeDialogResult> Handle(PurgeDialogCommand request, Cancella
var dialog = await _db.Dialogs
.Include(x => x.Attachments)
.Include(x => x.Activities)
.Where(x => resourceIds.Contains(x.ServiceResource))
.WhereIf(!_userResourceRegistry.IsCurrentUserServiceOwnerAdmin(), x => resourceIds.Contains(x.ServiceResource))
.IgnoreQueryFilters()
.FirstOrDefaultAsync(x => x.Id == request.DialogId, cancellationToken);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public async Task CreateDialogCommand_Should_Return_Forbidden_When_Scope_Is_Miss

var unitOfWorkSub = Substitute.For<IUnitOfWork>();
var domainContextSub = Substitute.For<IDomainContext>();
var userResourceRegistrySub = Substitute.For<IUserResourceRegistry>();
var resourceRegistrySub = Substitute.For<IResourceRegistry>();
var serviceAuthorizationSub = Substitute.For<IServiceResourceAuthorizer>();
var userSub = Substitute.For<IUser>();
Expand All @@ -37,10 +36,6 @@ public async Task CreateDialogCommand_Should_Return_Forbidden_When_Scope_Is_Miss
.AuthorizeServiceResources(Arg.Any<DialogEntity>(), Arg.Any<CancellationToken>())
.Returns(new Forbidden());

userResourceRegistrySub
.CurrentUserIsOwner(createCommand.ServiceResource, Arg.Any<CancellationToken>())
.Returns(true);

resourceRegistrySub
.GetResourceInformation(createCommand.ServiceResource, Arg.Any<CancellationToken>())
.Returns(new ServiceResourceInformation(createCommand.ServiceResource, "foo", "912345678", "ttd"));
Expand Down Expand Up @@ -69,7 +64,6 @@ public async Task CreateDialogCommand_Should_Return_Forbidden_When_User_Is_Not_O

var unitOfWorkSub = Substitute.For<IUnitOfWork>();
var domainContextSub = Substitute.For<IDomainContext>();
var userResourceRegistrySub = Substitute.For<IUserResourceRegistry>();
var resourceRegistrySub = Substitute.For<IResourceRegistry>();
var serviceAuthorizationSub = Substitute.For<IServiceResourceAuthorizer>();
var userSub = Substitute.For<IUser>();
Expand All @@ -79,10 +73,6 @@ public async Task CreateDialogCommand_Should_Return_Forbidden_When_User_Is_Not_O
.AuthorizeServiceResources(Arg.Any<DialogEntity>(), Arg.Any<CancellationToken>())
.Returns(new Forbidden());

userResourceRegistrySub
.CurrentUserIsOwner(createCommand.ServiceResource, Arg.Any<CancellationToken>())
.Returns(false);

resourceRegistrySub
.GetResourceInformation(createCommand.ServiceResource, Arg.Any<CancellationToken>())
.Returns(new ServiceResourceInformation(createCommand.ServiceResource, "foo", "912345678", "ttd"));
Expand Down

0 comments on commit a2face6

Please sign in to comment.