diff --git a/src/GovUk.Education.ExploreEducationStatistics.Admin.Tests/Services/PublicationServicePermissionTests.cs b/src/GovUk.Education.ExploreEducationStatistics.Admin.Tests/Services/PublicationServicePermissionTests.cs index 215d0cc265c..75477c2195e 100644 --- a/src/GovUk.Education.ExploreEducationStatistics.Admin.Tests/Services/PublicationServicePermissionTests.cs +++ b/src/GovUk.Education.ExploreEducationStatistics.Admin.Tests/Services/PublicationServicePermissionTests.cs @@ -591,7 +591,12 @@ await PermissionTestUtils.PolicyCheckBuilder() var service = BuildPublicationService( context: contentDbContext, userService: userService.Object); - return await service.AddReleaseSeriesLegacyLink(publication.Id, new ReleaseSeriesLegacyLinkAddRequest()); + return await service.AddReleaseSeriesLegacyLink(publication.Id, + new ReleaseSeriesLegacyLinkAddRequest + { + Description = "Test description", + Url = "https://test.url" + }); }); } diff --git a/src/GovUk.Education.ExploreEducationStatistics.Admin.Tests/Services/PublicationServiceTests.cs b/src/GovUk.Education.ExploreEducationStatistics.Admin.Tests/Services/PublicationServiceTests.cs index 9c493f09b50..4841cb8ce96 100644 --- a/src/GovUk.Education.ExploreEducationStatistics.Admin.Tests/Services/PublicationServiceTests.cs +++ b/src/GovUk.Education.ExploreEducationStatistics.Admin.Tests/Services/PublicationServiceTests.cs @@ -1326,7 +1326,7 @@ public async Task UpdatePublication_TitleChangesPublicationAndMethodologySlug() } [Fact] - public async void UpdatePublication_NoTitleOrSupersededByChange() + public async Task UpdatePublication_NoTitleOrSupersededByChange() { var theme = new Theme { @@ -2648,28 +2648,25 @@ public async Task ListLatestReleaseVersionsPaginated() [Fact] public async Task GetReleaseSeries() { - var legacyLinks = new List - { - new() - { - Id = Guid.NewGuid(), - LegacyLinkDescription = "legacy link 1", - LegacyLinkUrl = "https://test.com/1", - }, - }; + ReleaseSeriesItem legacyLink = _dataFixture.DefaultLegacyReleaseSeriesItem(); Publication publication = _dataFixture .DefaultPublication() - .WithReleases(ListOf( + .WithReleases([ _dataFixture .DefaultRelease(publishedVersions: 1, year: 2020), _dataFixture .DefaultRelease(publishedVersions: 0, draftVersion: true, year: 2021), _dataFixture - .DefaultRelease(publishedVersions: 2, draftVersion: true, year: 2022))) - .WithLegacyLinks(legacyLinks) + .DefaultRelease(publishedVersions: 2, draftVersion: true, year: 2022) + ]) + .WithLegacyLinks([legacyLink]) .WithTheme(_dataFixture.DefaultTheme()); + var release2020 = publication.Releases.Single(r => r.Year == 2020); + var release2021 = publication.Releases.Single(r => r.Year == 2021); + var release2022 = publication.Releases.Single(r => r.Year == 2022); + var contentDbContextId = Guid.NewGuid().ToString(); await using (var contentDbContext = InMemoryApplicationDbContext(contentDbContextId)) { @@ -2686,127 +2683,45 @@ public async Task GetReleaseSeries() Assert.Equal(4, viewModels.Count); - var expectedReleaseVersion1 = publication.ReleaseVersions.Single(rv => rv is { Year: 2022, Version: 1 }); - Assert.Equal(publication.ReleaseSeries[0].Id, viewModels[0].Id); Assert.False(viewModels[0].IsLegacyLink); - Assert.Equal(expectedReleaseVersion1.Title, viewModels[0].Description); - Assert.Equal(expectedReleaseVersion1.ReleaseId, viewModels[0].ReleaseId); - Assert.Equal(expectedReleaseVersion1.Slug, viewModels[0].ReleaseSlug); + Assert.Equal(release2022.Title, viewModels[0].Description); + Assert.Equal(release2022.Id, viewModels[0].ReleaseId); + Assert.Equal(release2022.Slug, viewModels[0].ReleaseSlug); Assert.True(viewModels[0].IsLatest); Assert.True(viewModels[0].IsPublished); Assert.Null(viewModels[0].LegacyLinkUrl); - var expectedReleaseVersion2 = publication.ReleaseVersions.Single(rv => rv is { Year: 2021, Version: 0 }); - Assert.Equal(publication.ReleaseSeries[1].Id, viewModels[1].Id); Assert.False(viewModels[1].IsLegacyLink); - Assert.Equal(expectedReleaseVersion2.Title, viewModels[1].Description); - Assert.Equal(expectedReleaseVersion2.ReleaseId, viewModels[1].ReleaseId); - Assert.Equal(expectedReleaseVersion2.Slug, viewModels[1].ReleaseSlug); + Assert.Equal(release2021.Title, viewModels[1].Description); + Assert.Equal(release2021.Id, viewModels[1].ReleaseId); + Assert.Equal(release2021.Slug, viewModels[1].ReleaseSlug); Assert.False(viewModels[1].IsLatest); Assert.False(viewModels[1].IsPublished); Assert.Null(viewModels[1].LegacyLinkUrl); - var expectedReleaseVersion3 = publication.ReleaseVersions.Single(rv => rv is { Year: 2020, Version: 0 }); - Assert.Equal(publication.ReleaseSeries[2].Id, viewModels[2].Id); Assert.False(viewModels[2].IsLegacyLink); - Assert.Equal(expectedReleaseVersion3.Title, viewModels[2].Description); - Assert.Equal(expectedReleaseVersion3.ReleaseId, viewModels[2].ReleaseId); - Assert.Equal(expectedReleaseVersion3.Slug, viewModels[2].ReleaseSlug); + Assert.Equal(release2020.Title, viewModels[2].Description); + Assert.Equal(release2020.Id, viewModels[2].ReleaseId); + Assert.Equal(release2020.Slug, viewModels[2].ReleaseSlug); Assert.False(viewModels[2].IsLatest); Assert.True(viewModels[2].IsPublished); Assert.Null(viewModels[2].LegacyLinkUrl); - Assert.Equal(publication.ReleaseSeries[3].Id, viewModels[3].Id); Assert.True(viewModels[3].IsLegacyLink); - Assert.Equal(legacyLinks[0].LegacyLinkDescription, viewModels[3].Description); + Assert.Equal(legacyLink.LegacyLinkDescription, viewModels[3].Description); Assert.Null(viewModels[3].ReleaseId); Assert.Null(viewModels[3].ReleaseSlug); Assert.Null(viewModels[3].IsLatest); Assert.Null(viewModels[3].IsPublished); - Assert.Equal(legacyLinks[0].LegacyLinkUrl, viewModels[3].LegacyLinkUrl); - } - } - - [Fact] - public async Task GetReleaseSeries_NoLegacyLinks() - { - Publication publication = _dataFixture - .DefaultPublication() - .WithReleases(ListOf( - _dataFixture - .DefaultRelease(publishedVersions: 1, year: 2020), - _dataFixture - .DefaultRelease(publishedVersions: 0, draftVersion: true, year: 2021), - _dataFixture - .DefaultRelease(publishedVersions: 2, draftVersion: true, year: 2022))) - .WithTheme(_dataFixture.DefaultTheme()); - - var contentDbContextId = Guid.NewGuid().ToString(); - await using (var contentDbContext = InMemoryApplicationDbContext(contentDbContextId)) - { - contentDbContext.Publications.Add(publication); - await contentDbContext.SaveChangesAsync(); - } - - await using (var contentDbContext = InMemoryApplicationDbContext(contentDbContextId)) - { - var publicationService = BuildPublicationService(contentDbContext); - - var result = await publicationService.GetReleaseSeries(publication.Id); - var viewModels = result.AssertRight(); - - Assert.Equal(3, viewModels.Count); - - var expectedReleaseVersion1 = publication.ReleaseVersions.Single(rv => rv is { Year: 2022, Version: 1 }); - Assert.Equal(publication.ReleaseSeries[0].Id, viewModels[0].Id); - Assert.False(viewModels[0].IsLegacyLink); - Assert.Equal(expectedReleaseVersion1.Title, viewModels[0].Description); - Assert.Equal(expectedReleaseVersion1.ReleaseId, viewModels[0].ReleaseId); - Assert.Equal(expectedReleaseVersion1.Slug, viewModels[0].ReleaseSlug); - Assert.True(viewModels[0].IsLatest); - Assert.True(viewModels[0].IsPublished); - Assert.Null(viewModels[0].LegacyLinkUrl); - - var expectedReleaseVersion2 = publication.ReleaseVersions.Single(rv => rv is { Year: 2021, Version: 0 }); - Assert.Equal(publication.ReleaseSeries[1].Id, viewModels[1].Id); - Assert.False(viewModels[1].IsLegacyLink); - Assert.Equal(expectedReleaseVersion2.Title, viewModels[1].Description); - Assert.Equal(expectedReleaseVersion2.ReleaseId, viewModels[1].ReleaseId); - Assert.Equal(expectedReleaseVersion2.Slug, viewModels[1].ReleaseSlug); - Assert.False(viewModels[1].IsLatest); - Assert.False(viewModels[1].IsPublished); - Assert.Null(viewModels[1].LegacyLinkUrl); - - var expectedReleaseVersion3 = publication.ReleaseVersions.Single(rv => rv is { Year: 2020, Version: 0 }); - Assert.Equal(publication.ReleaseSeries[2].Id, viewModels[2].Id); - Assert.False(viewModels[2].IsLegacyLink); - Assert.Equal(expectedReleaseVersion3.Title, viewModels[2].Description); - Assert.Equal(expectedReleaseVersion3.ReleaseId, viewModels[2].ReleaseId); - Assert.Equal(expectedReleaseVersion3.Slug, viewModels[2].ReleaseSlug); - Assert.False(viewModels[2].IsLatest); - Assert.True(viewModels[2].IsPublished); - Assert.Null(viewModels[2].LegacyLinkUrl); + Assert.Equal(legacyLink.LegacyLinkUrl, viewModels[3].LegacyLinkUrl); } } [Fact] public async Task GetReleaseSeries_NoReleases() { - var legacyLinks = new List - { - new() - { - Id = Guid.NewGuid(), - LegacyLinkDescription = "legacy link 1", - LegacyLinkUrl = "https://test.com/1", - }, - new() - { - Id = Guid.NewGuid(), - LegacyLinkDescription = "legacy link 2", - LegacyLinkUrl = "https://test.com/2", - }, - }; + var legacyLinks = _dataFixture.DefaultLegacyReleaseSeriesItem() + .GenerateList(2); Publication publication = _dataFixture .DefaultPublication() @@ -2829,7 +2744,6 @@ public async Task GetReleaseSeries_NoReleases() Assert.Equal(2, viewModels.Count); - Assert.Equal(publication.ReleaseSeries[0].Id, viewModels[0].Id); Assert.True(viewModels[0].IsLegacyLink); Assert.Equal(legacyLinks[0].LegacyLinkDescription, viewModels[0].Description); Assert.Null(viewModels[0].ReleaseId); @@ -2838,7 +2752,6 @@ public async Task GetReleaseSeries_NoReleases() Assert.Null(viewModels[0].IsPublished); Assert.Equal(legacyLinks[0].LegacyLinkUrl, viewModels[0].LegacyLinkUrl); - Assert.Equal(publication.ReleaseSeries[1].Id, viewModels[1].Id); Assert.True(viewModels[1].IsLegacyLink); Assert.Equal(legacyLinks[1].LegacyLinkDescription, viewModels[1].Description); Assert.Null(viewModels[1].ReleaseId); @@ -2877,24 +2790,16 @@ public async Task GetReleaseSeries_Empty() [Fact] public async Task AddReleaseSeriesLegacyLink() { - var legacyLinks = new List - { - new() - { - Id = Guid.NewGuid(), - LegacyLinkDescription = "legacy link 1", - LegacyLinkUrl = "https://test.com/1", - }, - }; + ReleaseSeriesItem legacyLink = _dataFixture.DefaultLegacyReleaseSeriesItem(); Publication publication = _dataFixture .DefaultPublication() - .WithReleases(ListOf( - _dataFixture - .DefaultRelease(publishedVersions: 1, year: 2020))) - .WithLegacyLinks(legacyLinks) + .WithReleases([_dataFixture.DefaultRelease(publishedVersions: 1)]) + .WithLegacyLinks([legacyLink]) .WithTheme(_dataFixture.DefaultTheme()); + var release = publication.Releases.Single(); + var contentDbContextId = Guid.NewGuid().ToString(); await using (var contentDbContext = InMemoryApplicationDbContext(contentDbContextId)) { @@ -2920,28 +2825,27 @@ public async Task AddReleaseSeriesLegacyLink() Description = "New legacy link", Url = "https://test.com/new" }); + var viewModels = result.AssertRight(); + VerifyAllMocks(publicationCacheService); Assert.Equal(3, viewModels.Count); - var expectedReleaseVersion1 = publication.ReleaseVersions.Single(rv => rv is { Year: 2020, Version: 0 }); - Assert.Equal(publication.ReleaseSeries[0].Id, viewModels[0].Id); Assert.False(viewModels[0].IsLegacyLink); - Assert.Equal(expectedReleaseVersion1.Title, viewModels[0].Description); - Assert.Equal(expectedReleaseVersion1.ReleaseId, viewModels[0].ReleaseId); - Assert.Equal(expectedReleaseVersion1.Slug, viewModels[0].ReleaseSlug); + Assert.Equal(release.Title, viewModels[0].Description); + Assert.Equal(release.Id, viewModels[0].ReleaseId); + Assert.Equal(release.Slug, viewModels[0].ReleaseSlug); Assert.True(viewModels[0].IsLatest); Assert.True(viewModels[0].IsPublished); Assert.Null(viewModels[0].LegacyLinkUrl); - Assert.Equal(publication.ReleaseSeries[1].Id, viewModels[1].Id); Assert.True(viewModels[1].IsLegacyLink); - Assert.Equal(legacyLinks[0].LegacyLinkDescription, viewModels[1].Description); + Assert.Equal(legacyLink.LegacyLinkDescription, viewModels[1].Description); Assert.Null(viewModels[1].ReleaseId); Assert.Null(viewModels[1].ReleaseSlug); Assert.Null(viewModels[1].IsLatest); Assert.Null(viewModels[1].IsPublished); - Assert.Equal(legacyLinks[0].LegacyLinkUrl, viewModels[1].LegacyLinkUrl); + Assert.Equal(legacyLink.LegacyLinkUrl, viewModels[1].LegacyLinkUrl); Assert.True(viewModels[2].IsLegacyLink); Assert.Equal("New legacy link", viewModels[2].Description); @@ -2950,16 +2854,23 @@ public async Task AddReleaseSeriesLegacyLink() Assert.Null(viewModels[2].IsLatest); Assert.Null(viewModels[2].IsPublished); Assert.Equal("https://test.com/new", viewModels[2].LegacyLinkUrl); + } - var dbReleaseSeries = contentDbContext.Publications - .Where(p => p.Id == publication.Id) - .Select(p => p.ReleaseSeries) - .Single(); + await using (var contentDbContext = InMemoryApplicationDbContext(contentDbContextId)) + { + var actualPublication = await contentDbContext.Publications + .SingleAsync(p => p.Id == publication.Id); + + var actualReleaseSeries = actualPublication.ReleaseSeries; + Assert.Equal(3, actualReleaseSeries.Count); + + Assert.Equal(release.Id, actualReleaseSeries[0].ReleaseId); + + Assert.Equal(legacyLink.LegacyLinkDescription, actualReleaseSeries[1].LegacyLinkDescription); + Assert.Equal(legacyLink.LegacyLinkUrl, actualReleaseSeries[1].LegacyLinkUrl); - Assert.Equal(3, dbReleaseSeries.Count); - Assert.Equal(viewModels[0].Id, dbReleaseSeries[0].Id); - Assert.Equal(viewModels[1].Id, dbReleaseSeries[1].Id); - Assert.Equal(viewModels[2].Id, dbReleaseSeries[2].Id); + Assert.Equal("New legacy link", actualReleaseSeries[2].LegacyLinkDescription); + Assert.Equal("https://test.com/new", actualReleaseSeries[2].LegacyLinkUrl); } } @@ -2995,6 +2906,9 @@ public async Task AddReleaseSeriesLegacyLink_AddToEmptySeries() Description = "New legacy link", Url = "https://test.com/new" }); + + VerifyAllMocks(publicationCacheService); + var viewModels = result.AssertRight(); var newSeriesItem = Assert.Single(viewModels); @@ -3005,42 +2919,40 @@ public async Task AddReleaseSeriesLegacyLink_AddToEmptySeries() Assert.Null(newSeriesItem.IsLatest); Assert.Null(newSeriesItem.IsPublished); Assert.Equal("https://test.com/new", newSeriesItem.LegacyLinkUrl); + } - var dbReleaseSeries = contentDbContext.Publications - .Where(p => p.Id == publication.Id) - .Select(p => p.ReleaseSeries) - .Single(); + await using (var contentDbContext = InMemoryApplicationDbContext(contentDbContextId)) + { + var actualPublication = await contentDbContext.Publications + .SingleAsync(p => p.Id == publication.Id); + + var actualReleaseSeriesItem = Assert.Single(actualPublication.ReleaseSeries); - var dbSeriesItem = Assert.Single(dbReleaseSeries); - Assert.Equal(viewModels[0].Id, dbSeriesItem.Id); + Assert.Equal("New legacy link", actualReleaseSeriesItem.LegacyLinkDescription); + Assert.Equal("https://test.com/new", actualReleaseSeriesItem.LegacyLinkUrl); } } [Fact] public async Task UpdateReleaseSeries() { - var legacyLinks = new List - { - new() - { - Id = Guid.NewGuid(), - LegacyLinkDescription = "legacy link 1", - LegacyLinkUrl = "https://test.com/1", - }, - }; - Publication publication = _dataFixture .DefaultPublication() - .WithReleases(ListOf( + .WithReleases([ _dataFixture .DefaultRelease(publishedVersions: 1, year: 2020), _dataFixture .DefaultRelease(publishedVersions: 0, draftVersion: true, year: 2021), _dataFixture - .DefaultRelease(publishedVersions: 2, draftVersion: true, year: 2022))) - .WithLegacyLinks(legacyLinks) + .DefaultRelease(publishedVersions: 2, draftVersion: true, year: 2022) + ]) + .WithLegacyLinks([_dataFixture.DefaultLegacyReleaseSeriesItem()]) .WithTheme(_dataFixture.DefaultTheme()); + var release2020 = publication.Releases.Single(r => r.Year == 2020); + var release2021 = publication.Releases.Single(r => r.Year == 2021); + var release2022 = publication.Releases.Single(r => r.Year == 2022); + var contentDbContextId = Guid.NewGuid().ToString(); await using (var contentDbContext = InMemoryApplicationDbContext(contentDbContextId)) { @@ -3059,36 +2971,31 @@ public async Task UpdateReleaseSeries() contentDbContext, publicationCacheService: publicationCacheService.Object); - var expectedReleaseVersion2022 = publication.ReleaseVersions.Single(rv => rv is { Year: 2022, Version: 1 }); - var expectedReleaseVersion2021 = publication.ReleaseVersions.Single(rv => rv is { Year: 2021, Version: 0 }); - var expectedReleaseVersion2020 = publication.ReleaseVersions.Single(rv => rv is { Year: 2020, Version: 0 }); - var result = await publicationService.UpdateReleaseSeries( publication.Id, - new List - { - new() + updatedReleaseSeriesItems: + [ + new ReleaseSeriesItemUpdateRequest { - Id = Guid.NewGuid(), LegacyLinkDescription = "Legacy link new", LegacyLinkUrl = "https://test.com/new", }, - new() + new ReleaseSeriesItemUpdateRequest { - Id = Guid.NewGuid(), - ReleaseId = expectedReleaseVersion2021.ReleaseId, + ReleaseId = release2021.Id }, - new() + new ReleaseSeriesItemUpdateRequest { - Id = Guid.NewGuid(), - ReleaseId = expectedReleaseVersion2020.ReleaseId, + ReleaseId = release2020.Id }, - new() + new ReleaseSeriesItemUpdateRequest { - Id = Guid.NewGuid(), - ReleaseId = expectedReleaseVersion2022.ReleaseId, - }, - }); + ReleaseId = release2022.Id + } + ]); + + VerifyAllMocks(publicationCacheService); + var viewModels = result.AssertRight(); Assert.Equal(4, viewModels.Count); @@ -3102,47 +3009,53 @@ public async Task UpdateReleaseSeries() Assert.Equal("https://test.com/new", viewModels[0].LegacyLinkUrl); Assert.False(viewModels[1].IsLegacyLink); - Assert.Equal(expectedReleaseVersion2021.Title, viewModels[1].Description); - Assert.Equal(expectedReleaseVersion2021.ReleaseId, viewModels[1].ReleaseId); - Assert.Equal(expectedReleaseVersion2021.Slug, viewModels[1].ReleaseSlug); + Assert.Equal(release2021.Title, viewModels[1].Description); + Assert.Equal(release2021.Id, viewModels[1].ReleaseId); + Assert.Equal(release2021.Slug, viewModels[1].ReleaseSlug); Assert.False(viewModels[1].IsLatest); Assert.False(viewModels[1].IsPublished); Assert.Null(viewModels[1].LegacyLinkUrl); Assert.False(viewModels[2].IsLegacyLink); - Assert.Equal(expectedReleaseVersion2020.Title, viewModels[2].Description); - Assert.Equal(expectedReleaseVersion2020.ReleaseId, viewModels[2].ReleaseId); - Assert.Equal(expectedReleaseVersion2020.Slug, viewModels[2].ReleaseSlug); + Assert.Equal(release2020.Title, viewModels[2].Description); + Assert.Equal(release2020.Id, viewModels[2].ReleaseId); + Assert.Equal(release2020.Slug, viewModels[2].ReleaseSlug); Assert.False(viewModels[2].IsLatest); Assert.True(viewModels[2].IsPublished); Assert.Null(viewModels[2].LegacyLinkUrl); Assert.False(viewModels[3].IsLegacyLink); - Assert.Equal(expectedReleaseVersion2022.Title, viewModels[3].Description); - Assert.Equal(expectedReleaseVersion2022.ReleaseId, viewModels[3].ReleaseId); - Assert.Equal(expectedReleaseVersion2022.Slug, viewModels[3].ReleaseSlug); + Assert.Equal(release2022.Title, viewModels[3].Description); + Assert.Equal(release2022.Id, viewModels[3].ReleaseId); + Assert.Equal(release2022.Slug, viewModels[3].ReleaseSlug); Assert.True(viewModels[3].IsLatest); Assert.True(viewModels[3].IsPublished); Assert.Null(viewModels[3].LegacyLinkUrl); } + + await using (var contentDbContext = InMemoryApplicationDbContext(contentDbContextId)) + { + var actualPublication = await contentDbContext.Publications + .SingleAsync(p => p.Id == publication.Id); + + var actualReleaseSeries = actualPublication.ReleaseSeries; + Assert.Equal(4, actualReleaseSeries.Count); + + Assert.Equal("Legacy link new", actualReleaseSeries[0].LegacyLinkDescription); + Assert.Equal("https://test.com/new", actualReleaseSeries[0].LegacyLinkUrl); + + Assert.Equal(release2021.Id, actualReleaseSeries[1].ReleaseId); + Assert.Equal(release2020.Id, actualReleaseSeries[2].ReleaseId); + Assert.Equal(release2022.Id, actualReleaseSeries[3].ReleaseId); + } } [Fact] public async Task UpdateReleaseSeries_SetEmpty() { - var legacyLinks = new List - { - new() - { - Id = Guid.NewGuid(), - LegacyLinkDescription = "legacy link 1", - LegacyLinkUrl = "https://test.com/1", - }, - }; - Publication publication = _dataFixture .DefaultPublication() - .WithLegacyLinks(legacyLinks) + .WithLegacyLinks([_dataFixture.DefaultLegacyReleaseSeriesItem()]) .WithTheme(_dataFixture.DefaultTheme()); var contentDbContextId = Guid.NewGuid().ToString(); @@ -3165,11 +3078,22 @@ public async Task UpdateReleaseSeries_SetEmpty() var result = await publicationService.UpdateReleaseSeries( publication.Id, - new List()); + updatedReleaseSeriesItems: []); + + VerifyAllMocks(publicationCacheService); + var viewModels = result.AssertRight(); Assert.Empty(viewModels); } + + await using (var contentDbContext = InMemoryApplicationDbContext(contentDbContextId)) + { + var actualPublication = await contentDbContext.Publications + .SingleAsync(p => p.Id == publication.Id); + + Assert.Empty(actualPublication.ReleaseSeries); + } } [Fact] @@ -3177,11 +3101,11 @@ public async Task UpdateReleaseSeries_UnsetRelease() { Publication publication = _dataFixture .DefaultPublication() - .WithReleases(ListOf( - _dataFixture - .DefaultRelease(publishedVersions: 1, year: 2020))) + .WithReleases([_dataFixture.DefaultRelease(publishedVersions: 1)]) .WithTheme(_dataFixture.DefaultTheme()); + var release = publication.Releases.Single(); + var contentDbContextId = Guid.NewGuid().ToString(); await using (var contentDbContext = InMemoryApplicationDbContext(contentDbContextId)) { @@ -3191,19 +3115,15 @@ public async Task UpdateReleaseSeries_UnsetRelease() await using (var contentDbContext = InMemoryApplicationDbContext(contentDbContextId)) { - var publicationCacheService = new Mock(Strict); - publicationCacheService.Setup(mock => - mock.UpdatePublication(publication.Slug)) - .ReturnsAsync(new PublicationCacheViewModel()); + var publicationService = BuildPublicationService(contentDbContext); - var publicationService = BuildPublicationService( - contentDbContext, - publicationCacheService: publicationCacheService.Object); + var exception = await Assert.ThrowsAsync(() => + publicationService.UpdateReleaseSeries( + publication.Id, + updatedReleaseSeriesItems: [])); - var exception = await Assert.ThrowsAsync(() => publicationService.UpdateReleaseSeries( - publication.Id, - new List())); - Assert.Equal("Missing or duplicate release in new release series. Expected ReleaseIds: " + publication.ReleaseVersions[0].ReleaseId, exception.Message); + Assert.Equal($"Missing or duplicate release in new release series. Expected ReleaseIds: {release.Id}", + exception.Message); } } @@ -3212,11 +3132,11 @@ public async Task UpdateReleaseSeries_SetDuplicateRelease() { Publication publication = _dataFixture .DefaultPublication() - .WithReleases(ListOf( - _dataFixture - .DefaultRelease(publishedVersions: 1, year: 2020))) + .WithReleases([_dataFixture.DefaultRelease(publishedVersions: 1)]) .WithTheme(_dataFixture.DefaultTheme()); + var release = publication.Releases.Single(); + var contentDbContextId = Guid.NewGuid().ToString(); await using (var contentDbContext = InMemoryApplicationDbContext(contentDbContextId)) { @@ -3226,31 +3146,25 @@ public async Task UpdateReleaseSeries_SetDuplicateRelease() await using (var contentDbContext = InMemoryApplicationDbContext(contentDbContextId)) { - var publicationCacheService = new Mock(Strict); - publicationCacheService.Setup(mock => - mock.UpdatePublication(publication.Slug)) - .ReturnsAsync(new PublicationCacheViewModel()); - - var publicationService = BuildPublicationService( - contentDbContext, - publicationCacheService: publicationCacheService.Object); + var publicationService = BuildPublicationService(contentDbContext); - var exception = await Assert.ThrowsAsync(() => publicationService.UpdateReleaseSeries( - publication.Id, - new List - { - new() - { - Id = Guid.NewGuid(), - ReleaseId = publication.ReleaseVersions[0].ReleaseId, - }, - new() - { - Id = Guid.NewGuid(), - ReleaseId = publication.ReleaseVersions[0].ReleaseId, - }, - })); - Assert.Equal("Missing or duplicate release in new release series. Expected ReleaseIds: " + publication.ReleaseVersions[0].ReleaseId, exception.Message); + var exception = await Assert.ThrowsAsync(() => + publicationService.UpdateReleaseSeries( + publication.Id, + updatedReleaseSeriesItems: + [ + new ReleaseSeriesItemUpdateRequest + { + ReleaseId = release.Id + }, + new ReleaseSeriesItemUpdateRequest + { + ReleaseId = release.Id + } + ])); + + Assert.Equal($"Missing or duplicate release in new release series. Expected ReleaseIds: {release.Id}", + exception.Message); } } @@ -3259,11 +3173,11 @@ public async Task UpdateReleaseSeries_InvalidSeriesItem1() { Publication publication = _dataFixture .DefaultPublication() - .WithReleases(ListOf( - _dataFixture - .DefaultRelease(publishedVersions: 1, year: 2020))) + .WithReleases([_dataFixture.DefaultRelease(publishedVersions: 1)]) .WithTheme(_dataFixture.DefaultTheme()); + var release = publication.Releases.Single(); + var contentDbContextId = Guid.NewGuid().ToString(); await using (var contentDbContext = InMemoryApplicationDbContext(contentDbContextId)) { @@ -3273,29 +3187,21 @@ public async Task UpdateReleaseSeries_InvalidSeriesItem1() await using (var contentDbContext = InMemoryApplicationDbContext(contentDbContextId)) { - var publicationCacheService = new Mock(Strict); - publicationCacheService.Setup(mock => - mock.UpdatePublication(publication.Slug)) - .ReturnsAsync(new PublicationCacheViewModel()); + var publicationService = BuildPublicationService(contentDbContext); - var publicationService = BuildPublicationService( - contentDbContext, - publicationCacheService: publicationCacheService.Object); + var exception = await Assert.ThrowsAsync(() => + publicationService.UpdateReleaseSeries( + publication.Id, + [ + new ReleaseSeriesItemUpdateRequest + { + ReleaseId = release.Id, + LegacyLinkDescription = "this should be null", + LegacyLinkUrl = "https://should.be/null", + } + ])); - var seriesItemId = Guid.NewGuid(); - var exception = await Assert.ThrowsAsync(() => publicationService.UpdateReleaseSeries( - publication.Id, - new List - { - new() - { - Id = seriesItemId, - ReleaseId = publication.ReleaseVersions[0].ReleaseId, - LegacyLinkDescription = "this should be null", - LegacyLinkUrl = "https://should.be/null", - }, - })); - Assert.Equal($"LegacyLink details shouldn't be set if ReleaseId is set. ReleaseSeriesItem: {seriesItemId}", exception.Message); + Assert.Equal("LegacyLink details shouldn't be set if ReleaseId is set.", exception.Message); } } @@ -3315,29 +3221,21 @@ public async Task UpdateReleaseSeries_InvalidSeriesItem2() await using (var contentDbContext = InMemoryApplicationDbContext(contentDbContextId)) { - var publicationCacheService = new Mock(Strict); - publicationCacheService.Setup(mock => - mock.UpdatePublication(publication.Slug)) - .ReturnsAsync(new PublicationCacheViewModel()); - - var publicationService = BuildPublicationService( - contentDbContext, - publicationCacheService: publicationCacheService.Object); + var publicationService = BuildPublicationService(contentDbContext); - var seriesItemId = Guid.NewGuid(); - var exception = await Assert.ThrowsAsync(() => publicationService.UpdateReleaseSeries( - publication.Id, - new List - { - new() - { - Id = seriesItemId, - ReleaseId = null, - LegacyLinkDescription = null, - LegacyLinkUrl = null, - }, - })); - Assert.Equal($"LegacyLink details should be set if ReleaseId is null. ReleaseSeriesItem: {seriesItemId}", exception.Message); + var exception = await Assert.ThrowsAsync(() => + publicationService.UpdateReleaseSeries( + publication.Id, + [ + new ReleaseSeriesItemUpdateRequest + { + ReleaseId = null, + LegacyLinkDescription = null, + LegacyLinkUrl = null, + } + ])); + + Assert.Equal("LegacyLink details should be set if ReleaseId is null.", exception.Message); } } diff --git a/src/GovUk.Education.ExploreEducationStatistics.Admin/Requests/ReleaseSeriesItemRequests.cs b/src/GovUk.Education.ExploreEducationStatistics.Admin/Requests/ReleaseSeriesItemRequests.cs index ffb39b58cbe..33ca1bdb6e2 100644 --- a/src/GovUk.Education.ExploreEducationStatistics.Admin/Requests/ReleaseSeriesItemRequests.cs +++ b/src/GovUk.Education.ExploreEducationStatistics.Admin/Requests/ReleaseSeriesItemRequests.cs @@ -1,21 +1,19 @@ #nullable enable - using System; namespace GovUk.Education.ExploreEducationStatistics.Admin.Requests; -public class ReleaseSeriesLegacyLinkAddRequest +public record ReleaseSeriesLegacyLinkAddRequest { - public string Description { get; set; } = string.Empty; - public string Url { get; set; } = string.Empty; + public required string Description { get; init; } + + public required string Url { get; init; } } -public class ReleaseSeriesItemUpdateRequest +public record ReleaseSeriesItemUpdateRequest { - public Guid Id { get; set; } - public Guid? ReleaseId { get; set; } + public Guid? ReleaseId { get; init; } - public string? LegacyLinkDescription { get; set; } - public string? LegacyLinkUrl { get; set; } + public string? LegacyLinkDescription { get; init; } + public string? LegacyLinkUrl { get; init; } } - diff --git a/src/GovUk.Education.ExploreEducationStatistics.Admin/Services/ManageContent/ManageContentPageService.cs b/src/GovUk.Education.ExploreEducationStatistics.Admin/Services/ManageContent/ManageContentPageService.cs index 56a0515af77..f6c6c038a9c 100644 --- a/src/GovUk.Education.ExploreEducationStatistics.Admin/Services/ManageContent/ManageContentPageService.cs +++ b/src/GovUk.Education.ExploreEducationStatistics.Admin/Services/ManageContent/ManageContentPageService.cs @@ -118,8 +118,6 @@ await _releaseVersionRepository { return new ReleaseSeriesItemViewModel { - Id = rsi.Id, - IsLegacyLink = rsi.IsLegacyLink, Description = rsi.LegacyLinkDescription!, LegacyLinkUrl = rsi.LegacyLinkUrl, }; @@ -130,10 +128,7 @@ await _releaseVersionRepository return new ReleaseSeriesItemViewModel { - Id = rsi.Id, - IsLegacyLink = rsi.IsLegacyLink, Description = latestReleaseVersion.Title, - ReleaseId = latestReleaseVersion.ReleaseId, ReleaseSlug = latestReleaseVersion.Slug, }; diff --git a/src/GovUk.Education.ExploreEducationStatistics.Admin/Services/PublicationService.cs b/src/GovUk.Education.ExploreEducationStatistics.Admin/Services/PublicationService.cs index 6215b3edc51..1341e018e56 100644 --- a/src/GovUk.Education.ExploreEducationStatistics.Admin/Services/PublicationService.cs +++ b/src/GovUk.Education.ExploreEducationStatistics.Admin/Services/PublicationService.cs @@ -19,14 +19,12 @@ using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; -using System.IO; using System.Linq; using System.Threading.Tasks; +using GovUk.Education.ExploreEducationStatistics.Admin.Services.Interfaces; using static GovUk.Education.ExploreEducationStatistics.Admin.Validators.ValidationErrorMessages; using static GovUk.Education.ExploreEducationStatistics.Admin.Validators.ValidationUtils; using ExternalMethodologyViewModel = GovUk.Education.ExploreEducationStatistics.Admin.ViewModels.ExternalMethodologyViewModel; -using IPublicationRepository = GovUk.Education.ExploreEducationStatistics.Admin.Services.Interfaces.IPublicationRepository; -using IPublicationService = GovUk.Education.ExploreEducationStatistics.Admin.Services.Interfaces.IPublicationService; using IReleaseVersionRepository = GovUk.Education.ExploreEducationStatistics.Content.Model.Repository.Interfaces.IReleaseVersionRepository; using PublicationViewModel = GovUk.Education.ExploreEducationStatistics.Admin.ViewModels.PublicationViewModel; using ReleaseSummaryViewModel = GovUk.Education.ExploreEducationStatistics.Admin.ViewModels.ReleaseSummaryViewModel; @@ -435,11 +433,12 @@ public async Task>> ListLates }); } - public async Task>> GetReleaseSeries(Guid publicationId) + public async Task>> GetReleaseSeries( + Guid publicationId) { - return await _persistenceHelper - .CheckEntityExists(publicationId) - .OnSuccess(publication => _userService.CheckCanViewPublication(publication)) + return await _context.Publications + .FirstOrNotFoundAsync(p => p.Id == publicationId) + .OnSuccess(_userService.CheckCanViewPublication) .OnSuccess(async publication => { var result = new List(); @@ -450,43 +449,28 @@ public async Task>> result.Add(new ReleaseSeriesTableEntryViewModel { Id = seriesItem.Id, - IsLegacyLink = true, Description = seriesItem.LegacyLinkDescription!, LegacyLinkUrl = seriesItem.LegacyLinkUrl, }); } else { - // prefer getting the latest published version over an unpublished amendment - var latestVersion = await _context.ReleaseVersions - .LatestReleaseVersion(seriesItem.ReleaseId!.Value, publishedOnly: true) - .SingleOrDefaultAsync(); + var release = await _context.Releases + .SingleAsync(r => r.Id == seriesItem.ReleaseId); - if (latestVersion == null) - { - // if the release has no published version, then use its original unpublished version - latestVersion = await _context.ReleaseVersions - .LatestReleaseVersion(seriesItem.ReleaseId!.Value) - .SingleOrDefaultAsync(); - - if (latestVersion == null) - { - throw new InvalidDataException( - "ReleaseSeriesItem with ReleaseId set should have an associated " + - $"ReleaseVersion. Release: {seriesItem.ReleaseId} " + - $"ReleaseSeriesItem: {seriesItem.Id}"); - } - } + var latestPublishedReleaseVersion = await _context.ReleaseVersions + .LatestReleaseVersion(releaseId: seriesItem.ReleaseId!.Value, publishedOnly: true) + .SingleOrDefaultAsync(); result.Add(new ReleaseSeriesTableEntryViewModel { Id = seriesItem.Id, - IsLegacyLink = false, - Description = latestVersion.Title, - ReleaseId = latestVersion.ReleaseId, - ReleaseSlug = latestVersion.Slug, - IsLatest = latestVersion.Id == publication.LatestPublishedReleaseVersionId, - IsPublished = latestVersion.Live, + ReleaseId = release.Id, + Description = release.Title, + ReleaseSlug = release.Slug, + IsLatest = publication.LatestPublishedReleaseVersionId != null && + latestPublishedReleaseVersion?.Id == publication.LatestPublishedReleaseVersionId, + IsPublished = latestPublishedReleaseVersion != null }); } } @@ -507,7 +491,6 @@ public async Task>> publication.ReleaseSeries.Add(new ReleaseSeriesItem { Id = Guid.NewGuid(), - ReleaseId = null, LegacyLinkDescription = newLegacyLink.Description, LegacyLinkUrl = newLegacyLink.Url, }); @@ -517,8 +500,7 @@ public async Task>> await _publicationCacheService.UpdatePublication(publication.Slug); - return await GetReleaseSeries(publication.Id) - .OnSuccess(releaseSeries => releaseSeries); + return await GetReleaseSeries(publication.Id); }); } @@ -527,7 +509,6 @@ public async Task>> List updatedReleaseSeriesItems) { return await _context.Publications - .Include(p => p.ReleaseVersions) .FirstOrNotFoundAsync(p => p.Id == publicationId) .OnSuccess(_userService.CheckCanManageReleaseSeries) .OnSuccess(async publication => @@ -538,26 +519,24 @@ public async Task>> if (seriesItem.ReleaseId != null && ( seriesItem.LegacyLinkDescription != null || seriesItem.LegacyLinkUrl != null)) { - throw new ArgumentException( - $"LegacyLink details shouldn't be set if ReleaseId is set. ReleaseSeriesItem: {seriesItem.Id}"); + throw new ArgumentException("LegacyLink details shouldn't be set if ReleaseId is set."); } if (seriesItem.ReleaseId == null && ( seriesItem.LegacyLinkDescription == null || seriesItem.LegacyLinkUrl == null)) { - throw new ArgumentException( - $"LegacyLink details should be set if ReleaseId is null. ReleaseSeriesItem: {seriesItem.Id}"); + throw new ArgumentException("LegacyLink details should be set if ReleaseId is null."); } } // Check all publication releases are included in updatedReleaseSeriesItems - var publicationReleaseIds = publication.ReleaseVersions - .Select(rv => rv.ReleaseId) - .Distinct() - .ToList(); + var publicationReleaseIds = await _context.Releases + .Where(r => r.PublicationId == publicationId) + .Select(r => r.Id) + .ToListAsync(); var updatedSeriesReleaseIds = updatedReleaseSeriesItems - .Where(rsi => rsi.ReleaseId != null) + .Where(rsi => rsi.ReleaseId.HasValue) .Select(rsi => rsi.ReleaseId!.Value) .ToList(); @@ -565,29 +544,23 @@ public async Task>> { throw new ArgumentException( "Missing or duplicate release in new release series. Expected ReleaseIds: " + - publicationReleaseIds.Select(id => id.ToString()).JoinToString(",")); + publicationReleaseIds.JoinToString(",")); } - // NOTE: A malicious user could change the release series items' Ids, but we don't care - - var newReleaseSeries = updatedReleaseSeriesItems + publication.ReleaseSeries = updatedReleaseSeriesItems .Select(request => new ReleaseSeriesItem { - Id = request.Id, + Id = Guid.NewGuid(), ReleaseId = request.ReleaseId, LegacyLinkDescription = request.LegacyLinkDescription, LegacyLinkUrl = request.LegacyLinkUrl, }).ToList(); - publication.ReleaseSeries = newReleaseSeries; - _context.Publications.Update(publication); - await _context.SaveChangesAsync(); await _publicationCacheService.UpdatePublication(publication.Slug); - return await GetReleaseSeries(publication.Id) - .OnSuccess(releaseSeries => releaseSeries); + return await GetReleaseSeries(publication.Id); }); } diff --git a/src/GovUk.Education.ExploreEducationStatistics.Admin/Services/ReleaseService.cs b/src/GovUk.Education.ExploreEducationStatistics.Admin/Services/ReleaseService.cs index abad7c72c1b..d969dbfac2c 100644 --- a/src/GovUk.Education.ExploreEducationStatistics.Admin/Services/ReleaseService.cs +++ b/src/GovUk.Education.ExploreEducationStatistics.Admin/Services/ReleaseService.cs @@ -197,7 +197,7 @@ await CreateGenericContentFromTemplate(releaseCreate.TemplateReleaseId.Value, publication.ReleaseSeries.Insert(0, new ReleaseSeriesItem { Id = Guid.NewGuid(), - ReleaseId = newReleaseVersion.ReleaseId, + ReleaseId = release.Id }); _context.Publications.Update(publication); diff --git a/src/GovUk.Education.ExploreEducationStatistics.Admin/ViewModels/ReleaseSeriesTableEntryViewModel.cs b/src/GovUk.Education.ExploreEducationStatistics.Admin/ViewModels/ReleaseSeriesTableEntryViewModel.cs index 83eb3c842b2..7140ad73187 100644 --- a/src/GovUk.Education.ExploreEducationStatistics.Admin/ViewModels/ReleaseSeriesTableEntryViewModel.cs +++ b/src/GovUk.Education.ExploreEducationStatistics.Admin/ViewModels/ReleaseSeriesTableEntryViewModel.cs @@ -5,17 +5,17 @@ namespace GovUk.Education.ExploreEducationStatistics.Admin.ViewModels; public record ReleaseSeriesTableEntryViewModel { - public Guid Id { get; set; } - public bool IsLegacyLink { get; set; } - public string Description { get; set; } = string.Empty; + public required Guid Id { get; init; } + public required string Description { get; init; } // used by EES release series item - public Guid? ReleaseId { get; set; } - public string? ReleaseSlug { get; set; } - public bool? IsLatest { get; set; } - public bool? IsPublished { get; set; } + public Guid? ReleaseId { get; init; } + public string? ReleaseSlug { get; init; } + public bool? IsLatest { get; init; } + public bool? IsPublished { get; init; } // used by legacy link series item - public string? LegacyLinkUrl { get; set; } -} + public string? LegacyLinkUrl { get; init; } + public bool IsLegacyLink => ReleaseId == null; +} diff --git a/src/GovUk.Education.ExploreEducationStatistics.Common/ViewModels/ReleaseSeriesItemViewModel.cs b/src/GovUk.Education.ExploreEducationStatistics.Common/ViewModels/ReleaseSeriesItemViewModel.cs index 2da3516d111..1d32d83477c 100644 --- a/src/GovUk.Education.ExploreEducationStatistics.Common/ViewModels/ReleaseSeriesItemViewModel.cs +++ b/src/GovUk.Education.ExploreEducationStatistics.Common/ViewModels/ReleaseSeriesItemViewModel.cs @@ -5,14 +5,14 @@ namespace GovUk.Education.ExploreEducationStatistics.Common.ViewModels; public record ReleaseSeriesItemViewModel { - public Guid Id { get; set; } - public bool IsLegacyLink { get; set; } - public string Description { get; set; } = string.Empty; + public required string Description { get; init; } // used by EES release series item - public Guid? ReleaseId { get; set; } - public string? ReleaseSlug { get; set; } + public Guid? ReleaseId { get; init; } + public string? ReleaseSlug { get; init; } // used by legacy link series item - public string? LegacyLinkUrl { get; set; } + public string? LegacyLinkUrl { get; init; } + + public bool IsLegacyLink => ReleaseId == null; } diff --git a/src/GovUk.Education.ExploreEducationStatistics.Content.Model/ReleaseSeriesItem.cs b/src/GovUk.Education.ExploreEducationStatistics.Content.Model/ReleaseSeriesItem.cs index e31cfc68dcf..75ca3662e94 100644 --- a/src/GovUk.Education.ExploreEducationStatistics.Content.Model/ReleaseSeriesItem.cs +++ b/src/GovUk.Education.ExploreEducationStatistics.Content.Model/ReleaseSeriesItem.cs @@ -6,6 +6,9 @@ namespace GovUk.Education.ExploreEducationStatistics.Content.Model; public record ReleaseSeriesItem { + /// + /// Unique identifier for the ReleaseSeriesItem which exists to allow safely managing legacy links in the UI. + /// public Guid Id { get; set; } public Guid? ReleaseId { get; set; } diff --git a/src/GovUk.Education.ExploreEducationStatistics.Content.Services.Tests/Cache/PublicationCacheServiceTests.cs b/src/GovUk.Education.ExploreEducationStatistics.Content.Services.Tests/Cache/PublicationCacheServiceTests.cs index 3cc4a6ee302..55bd9df9411 100644 --- a/src/GovUk.Education.ExploreEducationStatistics.Content.Services.Tests/Cache/PublicationCacheServiceTests.cs +++ b/src/GovUk.Education.ExploreEducationStatistics.Content.Services.Tests/Cache/PublicationCacheServiceTests.cs @@ -52,16 +52,14 @@ public class PublicationCacheServiceTests : CacheServiceTestFixture Title = "" } }, - ReleaseSeries = new() - { - new() + ReleaseSeries = + [ + new ReleaseSeriesItemViewModel { - Id = Guid.NewGuid(), - IsLegacyLink = true, Description = "legacy link description", LegacyLinkUrl = "http://test.com/", } - }, + ], Theme = new ThemeViewModel( Guid.NewGuid(), Slug: "", diff --git a/src/GovUk.Education.ExploreEducationStatistics.Content.Services.Tests/PublicationServiceTests.cs b/src/GovUk.Education.ExploreEducationStatistics.Content.Services.Tests/PublicationServiceTests.cs index bc28e6d61ed..6821c31bde4 100644 --- a/src/GovUk.Education.ExploreEducationStatistics.Content.Services.Tests/PublicationServiceTests.cs +++ b/src/GovUk.Education.ExploreEducationStatistics.Content.Services.Tests/PublicationServiceTests.cs @@ -205,7 +205,6 @@ public async Task Success() Assert.Null(releaseSeriesItem2.LegacyLinkUrl); var releaseSeriesItem3 = publicationViewModel.ReleaseSeries[2]; - Assert.Equal(_legacyLinks[0].Id, releaseSeriesItem3.Id); Assert.True(releaseSeriesItem3.IsLegacyLink); Assert.Null(releaseSeriesItem3.ReleaseId); Assert.Equal(_legacyLinks[0].LegacyLinkDescription, releaseSeriesItem3.Description); diff --git a/src/GovUk.Education.ExploreEducationStatistics.Content.Services/PublicationService.cs b/src/GovUk.Education.ExploreEducationStatistics.Content.Services/PublicationService.cs index 5e298c79739..7792a5f2b93 100644 --- a/src/GovUk.Education.ExploreEducationStatistics.Content.Services/PublicationService.cs +++ b/src/GovUk.Education.ExploreEducationStatistics.Content.Services/PublicationService.cs @@ -100,8 +100,6 @@ public async Task> Get(string pu { return new ReleaseSeriesItemViewModel { - Id = rsi.Id, - IsLegacyLink = rsi.IsLegacyLink, Description = rsi.LegacyLinkDescription!, LegacyLinkUrl = rsi.LegacyLinkUrl, }; @@ -112,10 +110,7 @@ public async Task> Get(string pu return new ReleaseSeriesItemViewModel { - Id = rsi.Id, - IsLegacyLink = rsi.IsLegacyLink, Description = latestReleaseVersion.Title, - ReleaseId = latestReleaseVersion.ReleaseId, ReleaseSlug = latestReleaseVersion.Slug, }; diff --git a/src/explore-education-statistics-admin/src/pages/publication/PublicationEditReleaseSeriesLegacyLinkPage.tsx b/src/explore-education-statistics-admin/src/pages/publication/PublicationEditReleaseSeriesLegacyLinkPage.tsx index 1c9e437e492..31d990847c0 100644 --- a/src/explore-education-statistics-admin/src/pages/publication/PublicationEditReleaseSeriesLegacyLinkPage.tsx +++ b/src/explore-education-statistics-admin/src/pages/publication/PublicationEditReleaseSeriesLegacyLinkPage.tsx @@ -19,7 +19,6 @@ export const mapToReleaseSeriesItemUpdateRequest = ( releaseSeries: ReleaseSeriesTableEntry[], ): ReleaseSeriesItemUpdateRequest[] => { return releaseSeries.map(seriesItem => ({ - id: seriesItem.id, releaseId: seriesItem.releaseId, legacyLinkDescription: seriesItem.isLegacyLink ? seriesItem.description diff --git a/src/explore-education-statistics-admin/src/pages/publication/__tests__/PublicationEditReleaseSeriesLegacyLinkPage.test.tsx b/src/explore-education-statistics-admin/src/pages/publication/__tests__/PublicationEditReleaseSeriesLegacyLinkPage.test.tsx index 9267147916c..5be827048c1 100644 --- a/src/explore-education-statistics-admin/src/pages/publication/__tests__/PublicationEditReleaseSeriesLegacyLinkPage.test.tsx +++ b/src/explore-education-statistics-admin/src/pages/publication/__tests__/PublicationEditReleaseSeriesLegacyLinkPage.test.tsx @@ -25,24 +25,24 @@ const publicationService = _publicationService as jest.Mocked< describe('PublicationEditReleaseSeriesLegacyLinkPage', () => { const releaseSeries: ReleaseSeriesTableEntry[] = [ { - id: 'legacy-release-1', + id: 'release-series-item-1', isLegacyLink: true, description: 'Legacy link 1', legacyLinkUrl: 'https://gov.uk/1', }, { - id: 'release-1', + id: 'release-series-item-2', isLegacyLink: false, description: 'Academic Year 2000/01', - releaseId: 'release-parent-1', + releaseId: 'release-1', releaseSlug: 'release-slug', isLatest: true, isPublished: true, }, { - id: 'legacy-release-2', + id: 'release-series-item-3', isLegacyLink: true, description: 'Legacy link 2', @@ -55,7 +55,7 @@ describe('PublicationEditReleaseSeriesLegacyLinkPage', () => { }); test('renders the edit legacy release page', async () => { - renderPage(testPublication, 'legacy-release-1'); + renderPage(testPublication, 'release-series-item-1'); await waitFor(() => { expect(screen.getByText('Edit legacy release')).toBeInTheDocument(); @@ -72,7 +72,7 @@ describe('PublicationEditReleaseSeriesLegacyLinkPage', () => { }); test('handles successfully submitting the form', async () => { - renderPage(testPublication, 'legacy-release-1'); + renderPage(testPublication, 'release-series-item-1'); await waitFor(() => { expect(screen.getByText('Edit legacy release')).toBeInTheDocument(); }); @@ -90,19 +90,13 @@ describe('PublicationEditReleaseSeriesLegacyLinkPage', () => { 'publication-1', [ { - id: 'legacy-release-1', - legacyLinkDescription: 'Legacy link 1 edited', legacyLinkUrl: 'https://gov.uk/1/edit', }, { - id: 'release-1', - - releaseId: 'release-parent-1', + releaseId: 'release-1', }, { - id: 'legacy-release-2', - legacyLinkDescription: 'Legacy link 2', legacyLinkUrl: 'https://gov.uk/2', }, diff --git a/src/explore-education-statistics-admin/src/pages/release/content/components/ReleaseContent.tsx b/src/explore-education-statistics-admin/src/pages/release/content/components/ReleaseContent.tsx index 7d766922ba8..945c68dfc14 100644 --- a/src/explore-education-statistics-admin/src/pages/release/content/components/ReleaseContent.tsx +++ b/src/explore-education-statistics-admin/src/pages/release/content/components/ReleaseContent.tsx @@ -346,14 +346,19 @@ const ReleaseContent = ({
    {[ ...releaseSeries.map( - ({ - id, - isLegacyLink, - description, - legacyLinkUrl, - releaseSlug, - }) => ( -
  • + ( + { + isLegacyLink, + description, + legacyLinkUrl, + releaseSlug, + }, + index, + ) => ( +
  • {isLegacyLink ? ( {description} ) : ( diff --git a/src/explore-education-statistics-admin/src/prototypes/page-view/PrototypeReleaseContent.tsx b/src/explore-education-statistics-admin/src/prototypes/page-view/PrototypeReleaseContent.tsx index 13cd6458699..aea585bcebb 100644 --- a/src/explore-education-statistics-admin/src/prototypes/page-view/PrototypeReleaseContent.tsx +++ b/src/explore-education-statistics-admin/src/prototypes/page-view/PrototypeReleaseContent.tsx @@ -308,14 +308,19 @@ const PrototypeReleaseContent = ({
      {[ ...releaseSeries.map( - ({ - id, - isLegacyLink, - description, - legacyLinkUrl, - releaseSlug, - }) => ( -
    • + ( + { + isLegacyLink, + description, + legacyLinkUrl, + releaseSlug, + }, + index, + ) => ( +
    • {isLegacyLink ? ( {description} ) : ( diff --git a/src/explore-education-statistics-admin/src/services/publicationService.ts b/src/explore-education-statistics-admin/src/services/publicationService.ts index f20174ef199..71465d3190c 100644 --- a/src/explore-education-statistics-admin/src/services/publicationService.ts +++ b/src/explore-education-statistics-admin/src/services/publicationService.ts @@ -83,7 +83,6 @@ export interface ReleaseSeriesLegacyLinkAddRequest { } export interface ReleaseSeriesItemUpdateRequest { - id: string; releaseId?: string; legacyLinkDescription?: string; legacyLinkUrl?: string; @@ -97,6 +96,7 @@ export interface ListReleasesParams { } export interface ReleaseSeriesTableEntry extends ReleaseSeriesItem { + id: string; isLatest?: boolean; isPublished?: boolean; } diff --git a/src/explore-education-statistics-admin/test/generators/releaseContentGenerators.ts b/src/explore-education-statistics-admin/test/generators/releaseContentGenerators.ts index a8dc2067805..ab2c4eb9faa 100644 --- a/src/explore-education-statistics-admin/test/generators/releaseContentGenerators.ts +++ b/src/explore-education-statistics-admin/test/generators/releaseContentGenerators.ts @@ -95,7 +95,6 @@ const defaultPublication: Publication = { releases: [], releaseSeries: [ { - id: 'legacylink-id', isLegacyLink: true, description: 'legacy link 1', legacyLinkUrl: 'https://test.com/1', diff --git a/src/explore-education-statistics-common/src/services/publicationService.ts b/src/explore-education-statistics-common/src/services/publicationService.ts index a512cb26639..d32c4c8898d 100644 --- a/src/explore-education-statistics-common/src/services/publicationService.ts +++ b/src/explore-education-statistics-common/src/services/publicationService.ts @@ -39,7 +39,6 @@ export interface Publication { } export interface ReleaseSeriesItem { - id: string; isLegacyLink: boolean; description: string; releaseId?: string; diff --git a/src/explore-education-statistics-frontend/src/modules/find-statistics/PublicationReleasePage.tsx b/src/explore-education-statistics-frontend/src/modules/find-statistics/PublicationReleasePage.tsx index 5f6784870ff..ac3a4d19f6b 100644 --- a/src/explore-education-statistics-frontend/src/modules/find-statistics/PublicationReleasePage.tsx +++ b/src/explore-education-statistics-frontend/src/modules/find-statistics/PublicationReleasePage.tsx @@ -341,14 +341,19 @@ const PublicationReleasePage: NextPage = ({ release }) => {
        {[ ...releaseSeries.map( - ({ - id, - isLegacyLink, - description, - legacyLinkUrl, - releaseSlug, - }) => ( -
      • + ( + { + isLegacyLink, + description, + legacyLinkUrl, + releaseSlug, + }, + index, + ) => ( +
      • {isLegacyLink ? ( {description} ) : ( diff --git a/src/explore-education-statistics-frontend/src/modules/find-statistics/__tests__/__data__/testReleaseData.ts b/src/explore-education-statistics-frontend/src/modules/find-statistics/__tests__/__data__/testReleaseData.ts index b750540f349..c7c697c1db3 100644 --- a/src/explore-education-statistics-frontend/src/modules/find-statistics/__tests__/__data__/testReleaseData.ts +++ b/src/explore-education-statistics-frontend/src/modules/find-statistics/__tests__/__data__/testReleaseData.ts @@ -18,33 +18,28 @@ export const testPublication: Publication = { ], releaseSeries: [ { - id: 'release-2', isLegacyLink: false, description: 'Academic year 2018/19', releaseSlug: '2018-19', }, { - id: 'legacy-release-3', isLegacyLink: true, description: 'Academic year 2014/15', legacyLinkUrl: 'https://www.gov.uk/government/statistics/pupil-absence-in-schools-in-england-2014-to-2015', }, { - id: 'release-1', isLegacyLink: false, description: 'Academic year 2017/18', releaseSlug: '2017-18', }, { - id: 'legacy-release-2', isLegacyLink: true, description: 'Academic year 2013/14', legacyLinkUrl: 'https://www.gov.uk/government/statistics/pupil-absence-in-schools-in-england-2013-to-2014', }, { - id: 'legacy-release-1', isLegacyLink: true, description: 'Academic year 2012/13', legacyLinkUrl: