Skip to content

Commit

Permalink
Merge pull request #4315 from dfe-analytical-services/EES-4557
Browse files Browse the repository at this point in the history
EES-4557 Show all methodologies associated with release on Admin Cont…
  • Loading branch information
Mark Youngman authored Sep 28, 2023
2 parents 04a7b0a + c0dd492 commit bf96f10
Show file tree
Hide file tree
Showing 14 changed files with 516 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public async Task ListLatestMethodologyVersions_Returns_Ok()
var methodologyService = new Mock<IMethodologyService>(Strict);

methodologyService
.Setup(s => s.ListLatestMethodologyVersions(_id))
.Setup(s => s.ListLatestMethodologyVersions(_id, false))
.ReturnsAsync(ListOf(new MethodologyVersionSummaryViewModel()));

var controller = SetupMethodologyController(methodologyService.Object);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using GovUk.Education.ExploreEducationStatistics.Admin.ViewModels;
using GovUk.Education.ExploreEducationStatistics.Common.Model;
using GovUk.Education.ExploreEducationStatistics.Common.Services.Interfaces.Security;
using GovUk.Education.ExploreEducationStatistics.Common.Tests.Extensions;
using GovUk.Education.ExploreEducationStatistics.Common.Tests.Utils;
using GovUk.Education.ExploreEducationStatistics.Common.Utils;
using GovUk.Education.ExploreEducationStatistics.Content.Model;
Expand Down Expand Up @@ -148,19 +149,7 @@ public async Task GetManageContentPageViewModel()
{
Id = Guid.NewGuid(),
AlternativeTitle = "Methodology 2 title",
Status = MethodologyApprovalStatus.Approved,
},
new MethodologyVersion
{
Id = Guid.NewGuid(),
AlternativeTitle = "Methodology should not appear 1",
Status = MethodologyApprovalStatus.Draft,
},
new MethodologyVersion
{
Id = Guid.NewGuid(),
AlternativeTitle = "Methodology should not appear 2",
Status = MethodologyApprovalStatus.HigherLevelReview,
}
);

Expand Down Expand Up @@ -249,17 +238,17 @@ await contentDbContext.ReleaseContentSections.AddRangeAsync(

var result = await service.GetManageContentPageViewModel(release.Id);

Assert.True(result.IsRight);
var viewModel = result.AssertRight();

dataBlockService.Verify(mock =>
mock.GetUnattachedDataBlocks(release.Id), Times.Once);

releaseFileService.Verify(mock =>
mock.ListAll(release.Id, Ancillary, FileType.Data), Times.Once);

Assert.Equal(unattachedDataBlocks, result.Right.UnattachedDataBlocks);
Assert.Equal(unattachedDataBlocks, viewModel.UnattachedDataBlocks);

var contentRelease = result.Right.Release;
var contentRelease = viewModel.Release;

Assert.NotNull(contentRelease);
Assert.Equal(release.Id, contentRelease.Id);
Expand Down Expand Up @@ -367,6 +356,168 @@ await contentDbContext.ReleaseContentSections.AddRangeAsync(
MockUtils.VerifyAllMocks(dataBlockService, methodologyVersionRepository, releaseFileService);
}

[Fact]
public async Task GetManageContentPageViewModel_IsPrerelease()
{
var publication = new Publication
{
Contact = new Contact(),
Slug = "test-publication",
Title = "Publication",
Topic = new Topic
{
Theme = new Theme(),
}
};

var release = new Release
{
NextReleaseDate = new PartialDate {Day = "9", Month = "9", Year = "2040"},
PreReleaseAccessList = "Test access list",
Publication = publication,
PublishScheduled = DateTime.Parse("2020-09-08T23:00:00.00Z", styles: DateTimeStyles.AdjustToUniversal),
Published = null,
ReleaseName = "2020",
Slug = "2020-21",
TimePeriodCoverage = AcademicYear,
Type = ReleaseType.OfficialStatistics,
};

var previousMethodologyVersion = new MethodologyVersion
{
Id = Guid.NewGuid(),
AlternativeTitle = "Methodology 3 title",
// Previous versions should always be approved - so no status set
};

var methodologyVersions = AsList(
new MethodologyVersion
{
// in result because approved
Id = Guid.NewGuid(),
AlternativeTitle = "Methodology 1 title",
Status = MethodologyApprovalStatus.Approved,
},
new MethodologyVersion
{
// in result because approved
Id = Guid.NewGuid(),
AlternativeTitle = "Methodology 2 title",
Status = MethodologyApprovalStatus.Approved,
},
previousMethodologyVersion, // in result because amendment of this version is not Approved
new MethodologyVersion
{
Id = Guid.NewGuid(),
AlternativeTitle = "Methodology should be filtered 1",
Status = MethodologyApprovalStatus.Draft,
PreviousVersion = previousMethodologyVersion,
},
new MethodologyVersion
{
// not in result because not Approved and no previous version
Id = Guid.NewGuid(),
AlternativeTitle = "Methodology should be filtered 2",
Status = MethodologyApprovalStatus.HigherLevelReview,
PreviousVersion = null,
}
);

var contentDbContextId = Guid.NewGuid().ToString();
await using (var contentDbContext = InMemoryApplicationDbContext(contentDbContextId))
{
await contentDbContext.Publications.AddAsync(publication);
await contentDbContext.Releases.AddAsync(release);
await contentDbContext.MethodologyVersions.AddRangeAsync(methodologyVersions);
await contentDbContext.ReleaseContentSections.AddRangeAsync(
new()
{
Release = release,
ContentSection = new()
{
Type = ContentSectionType.Headlines
}
},
new()
{
Release = release,
ContentSection = new()
{
Type = ContentSectionType.KeyStatisticsSecondary
}
},
new()
{
Release = release,
ContentSection = new()
{
Type = ContentSectionType.ReleaseSummary
}
},
new()
{
Release = release,
ContentSection = new()
{
Type = ContentSectionType.RelatedDashboards
}
},
new()
{
Release = release,
ContentSection = new()
{
Type = ContentSectionType.Generic,
}
});
await contentDbContext.SaveChangesAsync();
}

var dataBlockService = new Mock<IDataBlockService>(MockBehavior.Strict);
var methodologyVersionRepository = new Mock<IMethodologyVersionRepository>(MockBehavior.Strict);
var releaseFileService = new Mock<IReleaseFileService>(MockBehavior.Strict);

dataBlockService.Setup(mock =>
mock.GetUnattachedDataBlocks(release.Id))
.ReturnsAsync(new List<DataBlockViewModel>());

methodologyVersionRepository.Setup(mock =>
mock.GetLatestVersionByPublication(publication.Id))
.ReturnsAsync(methodologyVersions);

releaseFileService.Setup(mock =>
mock.ListAll(release.Id, Ancillary, FileType.Data))
.ReturnsAsync(new List<FileInfo>());

await using (var contentDbContext = InMemoryApplicationDbContext(contentDbContextId))
{
var service = SetupManageContentPageService(contentDbContext: contentDbContext,
dataBlockService: dataBlockService.Object,
methodologyVersionRepository: methodologyVersionRepository.Object,
releaseFileService: releaseFileService.Object);

var result = await service.GetManageContentPageViewModel(
release.Id, isPrerelease: true);

var viewModel = result.AssertRight();

var contentRelease = viewModel.Release;

var contentPublication = contentRelease.Publication;
Assert.NotNull(contentPublication);

Assert.Equal(3, contentPublication.Methodologies.Count);
Assert.Equal(methodologyVersions[0].Id, contentPublication.Methodologies[0].Id);
Assert.Equal("Methodology 1 title", contentPublication.Methodologies[0].Title);
Assert.Equal(methodologyVersions[1].Id, contentPublication.Methodologies[1].Id);
Assert.Equal("Methodology 2 title", contentPublication.Methodologies[1].Title);
Assert.Equal(methodologyVersions[2].Id, contentPublication.Methodologies[2].Id);
Assert.Equal("Methodology 3 title", contentPublication.Methodologies[2].Title);
}

MockUtils.VerifyAllMocks(dataBlockService, methodologyVersionRepository, releaseFileService);
}

[Fact]
public async Task GetManageContentPageViewModel_MapsBlocksCorrectly()
{
Expand Down Expand Up @@ -507,17 +658,17 @@ await contentDbContext.ReleaseContentSections.AddRangeAsync(

var result = await service.GetManageContentPageViewModel(release.Id);

Assert.True(result.IsRight);
var viewModel = result.AssertRight();

dataBlockService.Verify(mock =>
mock.GetUnattachedDataBlocks(release.Id), Times.Once);

releaseFileService.Verify(mock =>
mock.ListAll(release.Id, Ancillary, FileType.Data), Times.Once);

Assert.Equal(unattachedDataBlocks, result.Right.UnattachedDataBlocks);
Assert.Equal(unattachedDataBlocks, viewModel.UnattachedDataBlocks);

var contentRelease = result.Right.Release;
var contentRelease = viewModel.Release;

var contentReleaseSummary = contentRelease.SummarySection;

Expand Down Expand Up @@ -581,6 +732,7 @@ private static ManageContentPageService SetupManageContentPageService(
IUserService? userService = null)
{
return new(
contentDbContext,
contentPersistenceHelper ?? new PersistenceHelper<ContentDbContext>(contentDbContext),
mapper ?? MapperUtils.AdminMapper(),
dataBlockService ?? new Mock<IDataBlockService>().Object,
Expand Down
Loading

0 comments on commit bf96f10

Please sign in to comment.