Skip to content

EES-5955 - On publication latest published release version changed function #5766

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using GovUk.Education.ExploreEducationStatistics.Content.Search.FunctionApp.Functions.OnPublicationChanged.Dtos;
using GovUk.Education.ExploreEducationStatistics.Content.Search.FunctionApp.Functions.OnPublicationLatestPublishedReleaseVersionChanged;
using GovUk.Education.ExploreEducationStatistics.Content.Search.FunctionApp.Functions.OnPublicationLatestPublishedReleaseVersionChanged.Dtos;
using GovUk.Education.ExploreEducationStatistics.Content.Search.FunctionApp.Services;
using GovUk.Education.ExploreEducationStatistics.Content.Search.FunctionApp.Tests.Builders;
using Microsoft.Extensions.Logging.Abstractions;

namespace GovUk.Education.ExploreEducationStatistics.Content.Search.FunctionApp.Tests.Functions.OnPublicationLatestPublishedReleaseVersionChanged;

public class OnPublicationLatestPublishedReleaseVersionChangedFunctionTests
{
private OnPublicationLatestPublishedReleaseVersionChangedFunction GetSut() => new(new EventGridEventHandler(new NullLogger<EventGridEventHandler>()));

[Fact]
public void Can_instantiate_Sut() => Assert.NotNull(GetSut());

[Fact]
public async Task GivenEvent_WhenPayloadContainsSlug_ThenRefreshSearchableDocumentMessageDtoReturned()
{
// ARRANGE
var payload = new PublicationLatestPublishedReleaseVersionChangedEventDto
{
Slug = "this-is-a-publication-slug",
};

var eventGridEvent = new EventGridEventBuilder()
.WithPayload(payload)
.Build();

var sut = GetSut();

// ACT
var response = await sut.OnPublicationLatestPublishedReleaseVersionChanged(
eventGridEvent,
new FunctionContextMockBuilder().Build());

// ASSERT
var actual = Assert.Single(response);
Assert.NotNull(actual);
Assert.Equal(payload.Slug, actual.PublicationSlug);
}

[Theory]
[InlineData((string?)null)]
[InlineData("")]
public async Task GivenEvent_WhenPayloadDoesNotContainSlug_ThenNothingIsReturned(string? blankSlug)
{
// ARRANGE
var payload = new PublicationLatestPublishedReleaseVersionChangedEventDto
{
Slug = blankSlug,
};

var eventGridEvent = new EventGridEventBuilder()
.WithPayload(payload)
.Build();

var sut = GetSut();

// ACT
var response = await sut.OnPublicationLatestPublishedReleaseVersionChanged(
eventGridEvent,
new FunctionContextMockBuilder().Build());

// ASSERT
Assert.Empty(response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace GovUk.Education.ExploreEducationStatistics.Content.Search.FunctionApp.Functions.OnPublicationLatestPublishedReleaseVersionChanged.Dtos;

public class PublicationLatestPublishedReleaseVersionChangedEventDto
{
public string? Title { get; init; }
public string? Slug { get; init; }
public Guid? LatestPublishedReleaseVersionId { get; init; }
public Guid? PreviousReleaseVersionId { get; init; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Azure.Messaging.EventGrid;
using GovUk.Education.ExploreEducationStatistics.Content.Search.FunctionApp.Functions.OnPublicationLatestPublishedReleaseVersionChanged.Dtos;
using GovUk.Education.ExploreEducationStatistics.Content.Search.FunctionApp.Functions.RefreshSearchableDocument.Dto;
using GovUk.Education.ExploreEducationStatistics.Content.Search.FunctionApp.Services;
using Microsoft.Azure.Functions.Worker;

namespace GovUk.Education.ExploreEducationStatistics.Content.Search.FunctionApp.Functions.OnPublicationLatestPublishedReleaseVersionChanged;

public class OnPublicationLatestPublishedReleaseVersionChangedFunction(IEventGridEventHandler eventGridEventHandler)
{
[Function(nameof(OnPublicationLatestPublishedReleaseVersionChanged))]
[QueueOutput("%RefreshSearchableDocumentQueueName%")]
public async Task<RefreshSearchableDocumentMessageDto[]> OnPublicationLatestPublishedReleaseVersionChanged(
[QueueTrigger("%PublicationLatestPublishedReleaseVersionChangedQueueName%")]
EventGridEvent eventDto,
FunctionContext context) =>
await eventGridEventHandler.Handle<PublicationLatestPublishedReleaseVersionChangedEventDto, RefreshSearchableDocumentMessageDto[]>(
context,
eventDto,
(payload, ct) =>
Task.FromResult<RefreshSearchableDocumentMessageDto[]>(
string.IsNullOrEmpty(payload.Slug)
? []
: [ new RefreshSearchableDocumentMessageDto { PublicationSlug = payload.Slug } ]));
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"AzureWebJobsStorage": "UseDevelopmentStorage=true;DevelopmentStorageProxyUri=http://data-storage",
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
"PublicationChangedQueueName": "publication-changed-queue",
"PublicationLatestPublishedReleaseVersionChangedQueueName" : "publication-latest-published-release-version-changed-queue",
"RefreshSearchableDocumentQueueName": "refresh-searchable-document-queue",
"ReleaseSlugChangedQueueName": "release-slug-changed-queue",
"ReleaseVersionPublishedQueueName": "release-version-published-queue",
Expand Down