Skip to content

Commit

Permalink
Merge pull request #5417 from dfe-analytical-services/EES-5694-approv…
Browse files Browse the repository at this point in the history
…al-permissions-error-due-to-unused-images

EES-5694 - allowing unused images to be removed on ReleaseVersion approval
  • Loading branch information
duncan-at-hiveit authored Nov 29, 2024
2 parents 80bd0c2 + d90d6f3 commit cebd825
Show file tree
Hide file tree
Showing 6 changed files with 2,308 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,12 @@ public async Task UpdateApprovalStatus_ApprovingMethodologyWithUnusedImages()
mock.GetContentBlocks<HtmlBlock>(methodologyVersion.Id))
.ReturnsAsync(new List<HtmlBlock>());

imageService.Setup(mock =>
mock.Delete(methodologyVersion.Id, new List<Guid>
imageService.Setup(mock => mock.Delete(
methodologyVersion.Id, new List<Guid>
{
imageFile1.File.Id,
imageFile2.File.Id
}, false))
}, true))
.ReturnsAsync(Unit.Instance);

methodologyVersionRepository.Setup(mock =>
Expand All @@ -232,7 +232,7 @@ public async Task UpdateApprovalStatus_ApprovingMethodologyWithUnusedImages()
{
imageFile1.File.Id,
imageFile2.File.Id
}, false), Times.Once);
}, true), Times.Once);

VerifyAllMocks(contentService, imageService, methodologyVersionRepository);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,24 +224,30 @@ public async Task CreateReleaseStatus_Approved_FailsOnChecklistErrors()
await context.SaveChangesAsync();
}

var contentService = new Mock<IContentService>(MockBehavior.Strict);
var releaseChecklistService = new Mock<IReleaseChecklistService>(MockBehavior.Strict);

contentService.Setup(mock =>
mock.GetContentBlocks<HtmlBlock>(releaseVersion.Id))
.ReturnsAsync(new List<HtmlBlock>());

releaseChecklistService
.Setup(s =>
s.GetErrors(It.Is<ReleaseVersion>(rv => rv.Id == releaseVersion.Id)))
.ReturnsAsync(
new List<ReleaseChecklistIssue>
{
new(DataFileImportsMustBeCompleted),
new(DataFileReplacementsMustBeCompleted)
}
);

await using (var context = InMemoryApplicationDbContext(contextId))
{
releaseChecklistService
.Setup(s =>
s.GetErrors(It.Is<ReleaseVersion>(rv => rv.Id == releaseVersion.Id)))
.ReturnsAsync(
new List<ReleaseChecklistIssue>
{
new(DataFileImportsMustBeCompleted),
new(DataFileReplacementsMustBeCompleted)
}
);

var releaseService = BuildService(
context,
releaseChecklistService: releaseChecklistService.Object);
releaseChecklistService: releaseChecklistService.Object,
contentService: contentService.Object);

var result = await releaseService
.CreateReleaseStatus(
Expand All @@ -260,7 +266,7 @@ public async Task CreateReleaseStatus_Approved_FailsOnChecklistErrors()
}
);

VerifyAllMocks(releaseChecklistService);
VerifyAllMocks(releaseChecklistService, contentService);

result.AssertBadRequest(
DataFileImportsMustBeCompleted,
Expand Down Expand Up @@ -764,10 +770,18 @@ public async Task CreateReleaseStatus_Approved_Scheduled_FailsChangingToDraft()
context.ReleaseVersions.Add(releaseVersion);
await context.SaveChangesAsync();
}

var contentService = new Mock<IContentService>(MockBehavior.Strict);

contentService.Setup(mock =>
mock.GetContentBlocks<HtmlBlock>(releaseVersion.Id))
.ReturnsAsync(new List<HtmlBlock>());

await using (var context = InMemoryApplicationDbContext(contextId))
{
var releaseService = BuildService(context);
var releaseService = BuildService(
contentDbContext: context,
contentService: contentService.Object);

var result = await releaseService
.CreateReleaseStatus(
Expand All @@ -777,6 +791,8 @@ public async Task CreateReleaseStatus_Approved_Scheduled_FailsChangingToDraft()
ApprovalStatus = ReleaseApprovalStatus.Draft,
}
);

VerifyAllMocks(contentService);

result.AssertBadRequest(PublishedReleaseCannotBeUnapproved);
}
Expand Down Expand Up @@ -1382,7 +1398,7 @@ public async Task CreateReleaseStatus_ReleaseHasUnusedImages()
imageFile1.File.Id,
imageFile2.File.Id
},
false))
true))
.ReturnsAsync(Unit.Instance);

userReleaseRoleService.Setup(mock =>
Expand Down Expand Up @@ -1422,7 +1438,7 @@ public async Task CreateReleaseStatus_ReleaseHasUnusedImages()
imageFile1.File.Id,
imageFile2.File.Id
},
false),
true),
Times.Once);

VerifyAllMocks(contentService, releaseFileService, userReleaseRoleService);
Expand Down
Loading

0 comments on commit cebd825

Please sign in to comment.