Skip to content

Commit

Permalink
EES-5632 Distinguishing release redirects across different publicatio…
Browse files Browse the repository at this point in the history
…ns (#5446)

* EES-5632 [WIP] Refactoring BE to return release redirects grouped by publication

* EES-5632 [WIP] Integration tests

* EES-5632 Enabling a different Azurite TestContainer instance to be used across each test so that the stored data doesn't interfere with other tests

* EES-5632 FE - Changing the view-model field names to match the new BE field names

* EES-5632 Some requested changes as per PR review

* EES-5632 removing some duplicated tests

* EES-5632 Reformatting tests

* EES-5632 remove unused import
  • Loading branch information
jack-hive authored Dec 12, 2024
1 parent d357fe5 commit 7e51403
Show file tree
Hide file tree
Showing 22 changed files with 680 additions and 480 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -681,9 +681,9 @@ public async Task UpdateApprovalStatus_ApprovingUsingImmediateStrategy()

redirectsCacheService.Setup(mock => mock.UpdateRedirects())
.ReturnsAsync(new RedirectsViewModel(
Publications: [],
Methodologies: [],
Releases: []));
PublicationRedirects: [],
MethodologyRedirects: [],
ReleaseRedirectsByPublicationSlug: []));

await using (var context = InMemoryApplicationDbContext(contentDbContextId))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3600,9 +3600,9 @@ public async Task PublicationTitleOrSlugChanged()
var redirectsCacheService = new Mock<IRedirectsCacheService>(MockBehavior.Strict);
redirectsCacheService.Setup(mock => mock.UpdateRedirects())
.ReturnsAsync(new RedirectsViewModel(
Publications: [],
Methodologies: [],
Releases: []));
PublicationRedirects: [],
MethodologyRedirects: [],
ReleaseRedirectsByPublicationSlug: []));

var service = SetupMethodologyService(contentDbContext,
redirectsCacheService: redirectsCacheService.Object);
Expand Down Expand Up @@ -3662,9 +3662,9 @@ public async Task PublicationTitleOrSlugChanged_NoMethodologyRedirectAsMethodolo
var redirectsCacheService = new Mock<IRedirectsCacheService>(MockBehavior.Strict);
redirectsCacheService.Setup(mock => mock.UpdateRedirects())
.ReturnsAsync(new RedirectsViewModel(
Publications: [],
Methodologies: [],
Releases: []));
PublicationRedirects: [],
MethodologyRedirects: [],
ReleaseRedirectsByPublicationSlug: []));

var service = SetupMethodologyService(contentDbContext,
redirectsCacheService: redirectsCacheService.Object);
Expand Down Expand Up @@ -3745,9 +3745,9 @@ await contentDbContext.PublicationMethodologies.AddRangeAsync(
var redirectsCacheService = new Mock<IRedirectsCacheService>(MockBehavior.Strict);
redirectsCacheService.Setup(mock => mock.UpdateRedirects())
.ReturnsAsync(new RedirectsViewModel(
Publications: [],
Methodologies: [],
Releases: []));
PublicationRedirects: [],
MethodologyRedirects: [],
ReleaseRedirectsByPublicationSlug: []));

var service = SetupMethodologyService(contentDbContext,
redirectsCacheService: redirectsCacheService.Object);
Expand Down Expand Up @@ -3847,9 +3847,9 @@ public async Task PublicationTitleOrSlugChanged_MethodologySlugIsAlternativeSlug
var redirectsCacheService = new Mock<IRedirectsCacheService>(MockBehavior.Strict);
redirectsCacheService.Setup(mock => mock.UpdateRedirects())
.ReturnsAsync(new RedirectsViewModel(
Publications: [],
Methodologies: [],
Releases: []));
PublicationRedirects: [],
MethodologyRedirects: [],
ReleaseRedirectsByPublicationSlug: []));

var service = SetupMethodologyService(contentDbContext,
redirectsCacheService: redirectsCacheService.Object);
Expand Down Expand Up @@ -3917,9 +3917,9 @@ public async Task PublicationTitleOrSlugChanged_MethodologyIsLive()
var redirectsCacheService = new Mock<IRedirectsCacheService>(MockBehavior.Strict);
redirectsCacheService.Setup(mock => mock.UpdateRedirects())
.ReturnsAsync(new RedirectsViewModel(
Publications: [],
Methodologies: [],
Releases: []));
PublicationRedirects: [],
MethodologyRedirects: [],
ReleaseRedirectsByPublicationSlug: []));

var service = SetupMethodologyService(contentDbContext,
redirectsCacheService: redirectsCacheService.Object);
Expand Down Expand Up @@ -4004,9 +4004,9 @@ public async Task
var redirectsCacheService = new Mock<IRedirectsCacheService>(MockBehavior.Strict);
redirectsCacheService.Setup(mock => mock.UpdateRedirects())
.ReturnsAsync(new RedirectsViewModel(
Publications: [],
Methodologies: [],
Releases: []));
PublicationRedirects: [],
MethodologyRedirects: [],
ReleaseRedirectsByPublicationSlug: []));

var service = SetupMethodologyService(contentDbContext,
redirectsCacheService: redirectsCacheService.Object);
Expand Down Expand Up @@ -4110,9 +4110,9 @@ public async Task
var redirectsCacheService = new Mock<IRedirectsCacheService>(MockBehavior.Strict);
redirectsCacheService.Setup(mock => mock.UpdateRedirects())
.ReturnsAsync(new RedirectsViewModel(
Publications: [],
Methodologies: [],
Releases: []));
PublicationRedirects: [],
MethodologyRedirects: [],
ReleaseRedirectsByPublicationSlug: []));

var service = SetupMethodologyService(contentDbContext,
redirectsCacheService: redirectsCacheService.Object);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1127,9 +1127,9 @@ public async Task UpdatePublication_AlreadyPublished()

redirectsCacheService.Setup(mock => mock.UpdateRedirects())
.ReturnsAsync(new RedirectsViewModel(
Publications: [],
Methodologies: [],
Releases: []));
PublicationRedirects: [],
MethodologyRedirects: [],
ReleaseRedirectsByPublicationSlug: []));

var publicationService = BuildPublicationService(context,
methodologyService: methodologyService.Object,
Expand Down Expand Up @@ -1272,9 +1272,9 @@ public async Task UpdatePublication_TitleChangesPublicationAndMethodologySlug()

redirectsCacheService.Setup(mock => mock.UpdateRedirects())
.ReturnsAsync(new RedirectsViewModel(
Publications: [],
Methodologies: [],
Releases: []));
PublicationRedirects: [],
MethodologyRedirects: [],
ReleaseRedirectsByPublicationSlug: []));

var publicationService = BuildPublicationService(context,
methodologyService: methodologyService.Object,
Expand Down Expand Up @@ -1579,9 +1579,9 @@ public async Task UpdatePublication_CreateRedirectIfLiveSlugChanged()
var redirectsCacheService = new Mock<IRedirectsCacheService>(Strict);
redirectsCacheService.Setup(mock => mock.UpdateRedirects())
.ReturnsAsync(new RedirectsViewModel(
Publications: [],
Methodologies: [],
Releases: []));
PublicationRedirects: [],
MethodologyRedirects: [],
ReleaseRedirectsByPublicationSlug: []));

var publicationService = BuildPublicationService(context,
methodologyService: methodologyService.Object,
Expand Down Expand Up @@ -1678,9 +1678,9 @@ public async Task UpdatePublication_ChangeBackToPreviousLiveSlug()
var redirectsCacheService = new Mock<IRedirectsCacheService>(Strict);
redirectsCacheService.Setup(mock => mock.UpdateRedirects())
.ReturnsAsync(new RedirectsViewModel(
Publications: [],
Methodologies: [],
Releases: []));
PublicationRedirects: [],
MethodologyRedirects: [],
ReleaseRedirectsByPublicationSlug: []));

var publicationService = BuildPublicationService(context,
methodologyService: methodologyService.Object,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1759,7 +1759,7 @@ private static Mock<ContentDbContext> ContentDbContextMock(

public class DownloadDataSetFileTests(TestApplicationFactory testApp) : DataSetFilesControllerTests(testApp)
{
public override async Task InitializeAsync() => await TestApp.StartAzurite();
public override async Task InitializeAsync() => await StartAzurite();

[Fact]
public async Task DownloadDataSetFile()
Expand Down Expand Up @@ -1844,7 +1844,7 @@ public async Task DownloadDataSetFile_NotPublished()
.WithReleaseVersion(publication.ReleaseVersions[0])
.WithFile(_fixture.DefaultFile(FileType.Data));

await TestApp.StartAzurite();
await StartAzurite();

var testApp = BuildApp(enableAzurite: true);
var publicBlobStorageService = testApp.Services.GetRequiredService<IPublicBlobStorageService>();
Expand All @@ -1871,7 +1871,7 @@ await TestApp.AddTestData<ContentDbContext>(context =>

public class ListSitemapItemsTests(TestApplicationFactory testApp) : DataSetFilesControllerTests(testApp)
{
public override async Task InitializeAsync() => await TestApp.StartAzurite();
public override async Task InitializeAsync() => await StartAzurite();

private async Task<HttpResponseMessage> InvokeListSitemapItems(
WebApplicationFactory<Startup>? app = null)
Expand Down Expand Up @@ -1904,7 +1904,7 @@ public async Task ListSitemapItems()
))
);

await TestApp.StartAzurite();
await StartAzurite();

var testApp = BuildApp(enableAzurite: true);
var publicBlobStorageService = testApp.Services.GetRequiredService<IPublicBlobStorageService>();
Expand Down Expand Up @@ -1944,7 +1944,7 @@ public class GetDataSetFileTests(TestApplicationFactory testApp) : DataSetFilesC
{
public override async Task InitializeAsync()
{
await TestApp.StartAzurite();
await StartAzurite();
}

[Fact]
Expand Down Expand Up @@ -1975,7 +1975,7 @@ await TestApp.AddTestData<ContentDbContext>(context =>
context.ReleaseFiles.Add(releaseFile);
});

await TestApp.StartAzurite();
await StartAzurite();

var testApp = BuildApp(enableAzurite: true);

Expand Down Expand Up @@ -2098,7 +2098,7 @@ await TestApp.AddTestData<ContentDbContext>(context =>
context.ReleaseFiles.Add(releaseFile);
});

await TestApp.StartAzurite();
await StartAzurite();

var testApp = BuildApp(enableAzurite: true);

Expand Down Expand Up @@ -2163,7 +2163,7 @@ await TestApp.AddTestData<ContentDbContext>(context =>
context.ReleaseFiles.Add(releaseFile);
});

await TestApp.StartAzurite();
await StartAzurite();

var testApp = BuildApp(enableAzurite: true);

Expand Down Expand Up @@ -2224,7 +2224,7 @@ await TestApp.AddTestData<ContentDbContext>(context =>
context.ReleaseFiles.Add(releaseFile);
});

await TestApp.StartAzurite();
await StartAzurite();

var testApp = BuildApp(enableAzurite: true);

Expand Down Expand Up @@ -2281,7 +2281,7 @@ await TestApp.AddTestData<ContentDbContext>(context =>
context.ReleaseFiles.Add(releaseFile);
});

await TestApp.StartAzurite();
await StartAzurite();

var testApp = BuildApp(enableAzurite: true);

Expand Down Expand Up @@ -2362,7 +2362,7 @@ await TestApp.AddTestData<StatisticsDbContext>(context =>
context.ReleaseFootnote.AddRange(releaseFootnote1, releaseFootnote2);
});

await TestApp.StartAzurite();
await StartAzurite();

var testApp = BuildApp(enableAzurite: true);

Expand Down Expand Up @@ -2466,7 +2466,7 @@ await TestApp.AddTestData<ContentDbContext>(context =>
context.ReleaseFiles.AddRange(releaseFile0, releaseFile1, releaseFile2);
});

await TestApp.StartAzurite();
await StartAzurite();

var testApp = BuildApp(enableAzurite: true);

Expand Down Expand Up @@ -2532,8 +2532,7 @@ private WebApplicationFactory<Startup> BuildApp(
StatisticsDbContext? statisticsDbContext = null,
bool enableAzurite = false)
{
return TestApp
.WithAzurite(enabled: enableAzurite)
return WithAzurite(enabled: enableAzurite)
.ConfigureServices(services =>
{
services.ReplaceService(MemoryCacheService);
Expand Down
Loading

0 comments on commit 7e51403

Please sign in to comment.