Skip to content
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

EES-5753 API notification subscribers receive email to highlight new major version has breaking changes #5606

Merged

Conversation

mmoalin
Copy link
Collaborator

@mmoalin mmoalin commented Feb 14, 2025

This PR adds a new email template to be used by API data set notification subscribers. It also uses an existing email template but renames it to be more accurate for its purpose.

When a major data set version is published, this e-mail template will be sent:
image

When a minor data set version is published, the subscribers will receive a message that uses this template:
image

If a new published data set's version contains breaking changes (i.e., has a major version increment), then an email which highlights this is sent. Otherwise, if the new published data set contains only minor changes, a different e-mail template will be sent.

This uses a small utility method in the related classes that can be unit tested to decide whether to send the major data set email or the minor data set email by checking the version number received by the function send_email is a new major version (and is not the very first major version published).

This also adds the associated template IDs as secrets in the infrastructure templates json. Please note this requires manual configurations in the infrastructure to add the new template id (major data set updates) and rename the existing other template id (minor data set updates).

@mmoalin mmoalin force-pushed the EES-5753-Highlight-breaking-changes-in-API-email-updates branch from dbd33bd to 1ac37c8 Compare February 14, 2025 15:33
@mmoalin mmoalin changed the title EES-5753 Add and use new email template to highlight breaking changes… EES-5753 API notification subscribers receive email to highlight new major version has breaking changes Feb 14, 2025
@mmoalin mmoalin marked this pull request as ready for review February 14, 2025 16:24
@@ -746,6 +747,43 @@ await functions.RemoveExpiredSubscriptions(
}
}

public class ApiSubscriptionEmailsHelperTests
{
[Theory]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would make more sense I think if the test setup had what the current version is, what the new version is, and then the expected template. Because in the data here, if I go from v.1.9 to v2.1, you're expecting that to be a minor version?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, I don't think it is possible to go from v.1.9 to v2.1 so I believe the test cases are fit for purpose as is unless I've misinterpreted your comment.
I'll try to confirm this from the team but from my testing I have found no way of doing this within the EES system.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's worth checking. It does seem overly restrictive. For example, you have a test below that says that version 0.0.1 is a minor release, even though that is likely to be the first release.

Copy link
Collaborator Author

@mmoalin mmoalin Feb 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Lee!

For example, you have a test below that says that version 0.0.1 is a minor release, even though that is likely to be the first release.

This is the logic as is (and as expected by the ticket): the first release (regardless of if the data set version is a minor or a major release) sends the 'API data set version published' email template ID and because I started to include the word 'minor version' into it i.e., ApiSubscriptionMinorDataSetVersionNotificationId; maybe this is the source of the confusion and is worth a second look from my POV.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the wording of the shared template ID to make it more accurate to the meaning of the function. Also this is what Cam (the PO) named these templates in the first place so I probably should've just stuck to the script.
I think we should use: ApiSubscriptionDataSetVersionPublishedId & ApiSubscriptionMajorDataSetVersionPublishedId to support this after thinking about your initial impression and feedback Lee. Looking forward to discussing this some more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added coverage of this new logic for the integration test thanks to Lee's help.

@mmoalin mmoalin force-pushed the EES-5753-Highlight-breaking-changes-in-API-email-updates branch from f0efa02 to 64485e2 Compare February 14, 2025 17:40
@@ -746,6 +747,43 @@ await functions.RemoveExpiredSubscriptions(
}
}

public class ApiSubscriptionEmailsHelperTests
{
[Theory]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's worth checking. It does seem overly restrictive. For example, you have a test below that says that version 0.0.1 is a minor release, even though that is likely to be the first release.

@@ -560,7 +561,7 @@ public async Task Success()
fixture.NotificationClient
.Setup(mock => mock.SendEmail(
Email,
GetGovUkNotifyOptions().EmailTemplates.ApiSubscriptionNotificationId,
GetGovUkNotifyOptions().EmailTemplates.ApiSubscriptionMinorDataSetVersionNotificationId,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This setup only allows the minor template version to be used. If your intention is that this test doesn't care, then instead consider using A._
Having said that, do you have a test that ensures SendEmail is being called with the expected template anywhere?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some background: this change is because I renamed the variable storing a template ID shared by this test and other bits of the codebase. This is a pre-existing test that isn't intended to change unless I have to and so this was one of those cases (as renaming the variable affected this test).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this test was from before, when the only expectation was that it would send an email with the single template id. There are now two different scenarios, based on the version number. Therefore, this test needs to be expanded on - with two different initial conditions (version major and version minor) and two different expectations (id major and id minor).
To put it another way, you can change the ApiSubscriptionService code to this:

emailService.SendEmail(
            email: subscription.RowKey,
            templateId: govUkNotifyOptions.Value.EmailTemplates.ApiSubscriptionMinorDataSetVersionNotificationId,
            values: personalisation);

and all of the tests pass.

Copy link
Collaborator Author

@mmoalin mmoalin Feb 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test case NotifySubscribersTests.Success uses mocks in order to instantiate INotificationClient (which implements SendEmail). The new logic sits outside of what is being mocked which is why I was inclined to use a separate unit test to ensure it's coverage.

There are many instances in the codebase that uses the SendEmail method in tests and I'm put off from making any changes to any tests that are unrelated to this ticket unless I have to which was the case in this instance.
For an expansion of my thoughts please see comments under ApiSubscriptionFunctionsTests.cs

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very grateful for your explanation on this Lee. I've updated the integration tests to test the correct template ID is called based on if the new version contains breaking changes or not.

@mmoalin mmoalin force-pushed the EES-5753-Highlight-breaking-changes-in-API-email-updates branch 6 times, most recently from faa8f54 to 841b038 Compare February 17, 2025 16:58
await CreateApiSubscription(subscription);

var templates = GetGovUkNotifyOptions().EmailTemplates;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this call needed anymore?

.gitignore Outdated
@@ -99,3 +99,4 @@ src/GovUk.Education.ExploreEducationStatistics.Admin/appsettings.IdpBootstrapUse

## IDE Files (e.g. local Visual Studio configuration)
*.csproj.user
/src/GovUk.Education.ExploreEducationStatistics.slnLaunch.user
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well ignore all *.user files.

… in new publications of api data sets. Uses a small utility class to determine which template id to use. Adds template ID references to infrastructure (template.json). Note this requires a manual faffy deploy ticket to add the required secrets in each environment.
@mmoalin mmoalin force-pushed the EES-5753-Highlight-breaking-changes-in-API-email-updates branch from b5c09c3 to 95409c5 Compare February 17, 2025 17:10
@N-moh N-moh added do not merge Don't merge just yet and removed do not merge Don't merge just yet labels Feb 17, 2025
@mmoalin mmoalin merged commit 50118de into dev Feb 18, 2025
10 checks passed
@mmoalin mmoalin deleted the EES-5753-Highlight-breaking-changes-in-API-email-updates branch February 18, 2025 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants