-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EES-5753 Add and use new email template to highlight breaking changes…
… 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.
- Loading branch information
Showing
8 changed files
with
89 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
using GovUk.Education.ExploreEducationStatistics.Common.Tests.Utils; | ||
using GovUk.Education.ExploreEducationStatistics.Notifier.Functions; | ||
using GovUk.Education.ExploreEducationStatistics.Notifier.Model; | ||
using GovUk.Education.ExploreEducationStatistics.Notifier.Options; | ||
using GovUk.Education.ExploreEducationStatistics.Notifier.Requests; | ||
using GovUk.Education.ExploreEducationStatistics.Notifier.Services.Interfaces; | ||
using GovUk.Education.ExploreEducationStatistics.Notifier.Validators; | ||
|
@@ -28,7 +29,7 @@ public abstract class ApiSubscriptionFunctionsTests(NotifierFunctionsIntegration | |
private const string DataSetTitle = "data set title"; | ||
private const string Version = "1.0"; | ||
private const string Email = "[email protected]"; | ||
|
||
public class RequestPendingSubscriptionTests(NotifierFunctionsIntegrationTestFixture fixture) | ||
: ApiSubscriptionFunctionsTests(fixture) | ||
{ | ||
|
@@ -555,12 +556,12 @@ public async Task Success() | |
}; | ||
|
||
await CreateApiSubscription(subscription); | ||
|
||
string? unsubscribeUrl = null; | ||
fixture.NotificationClient | ||
.Setup(mock => mock.SendEmail( | ||
Email, | ||
GetGovUkNotifyOptions().EmailTemplates.ApiSubscriptionNotificationId, | ||
GetGovUkNotifyOptions().EmailTemplates.ApiSubscriptionMinorDataSetVersionId, | ||
It.Is<Dictionary<string, dynamic>>(personalisation => | ||
AssertEmailTemplateValues( | ||
personalisation, | ||
|
@@ -746,6 +747,43 @@ await functions.RemoveExpiredSubscriptions( | |
} | ||
} | ||
|
||
public class ApiSubscriptionEmailsHelperTests | ||
{ | ||
[Theory] | ||
[InlineData("2.0.0", "major-template-id")] | ||
[InlineData("2.0", "major-template-id")] | ||
[InlineData("3.0.0", "major-template-id")] | ||
[InlineData("3.0", "major-template-id")] | ||
[InlineData("1.1.0", "minor-template-id")] | ||
[InlineData("1.1", "minor-template-id")] | ||
[InlineData("1.0.1", "minor-template-id")] | ||
[InlineData("2.1.0", "minor-template-id")] | ||
[InlineData("2.1", "minor-template-id")] | ||
[InlineData("2.0.1", "minor-template-id")] | ||
[InlineData("1.0.0", "minor-template-id")] | ||
[InlineData("1.0", "minor-template-id")] | ||
[InlineData("0.0.1", "minor-template-id")] | ||
public void SelectApiSubscriptionNotifEmailTemplateID_ReturnsCorrectTemplateId(string version, string expectedTemplateId) | ||
{ | ||
var newApiSubscriptionNotifEmailTemplateIdSelector = new ApiSubscriptionEmailsHelper("major-template-id", "minor-template-id"); | ||
var templateId = newApiSubscriptionNotifEmailTemplateIdSelector.SelectApiSubscriptionNotifEmailTemplateID(version); | ||
Assert.Equal(expectedTemplateId, templateId); | ||
} | ||
|
||
|
||
[Theory] | ||
[InlineData("2.*.0")] | ||
[InlineData("Not a version")] | ||
[InlineData("1.1.1.1")] | ||
[InlineData("")] | ||
public void SelectApiSubscriptionNotifEmailTemplateID_ThrowsArgumentException(string version) | ||
{ | ||
var newApiSubscriptionNotifEmailTemplateIdSelector = new ApiSubscriptionEmailsHelper("major-template-id", "minor-template-id"); | ||
var exception = Assert.Throws<ArgumentException>(() => newApiSubscriptionNotifEmailTemplateIdSelector.SelectApiSubscriptionNotifEmailTemplateID(version)); | ||
Assert.Equal(ValidationMessages.InvalidDataSetVersion.Message, exception.Message); | ||
} | ||
} | ||
|
||
private string? ExtractEmailFromSubscriptionLinkToken(string? subscriptionLink) | ||
{ | ||
if (subscriptionLink == null) | ||
|
28 changes: 28 additions & 0 deletions
28
...on.ExploreEducationStatistics.Notifier/Options/EmailTemplateForNotificationSubscribers.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using GovUk.Education.ExploreEducationStatistics.Notifier.Validators; | ||
using System.Runtime.CompilerServices; | ||
[assembly: InternalsVisibleTo("GovUk.Education.ExploreEducationStatistics.Notifier.Tests")] | ||
|
||
namespace GovUk.Education.ExploreEducationStatistics.Notifier.Options; | ||
internal class ApiSubscriptionEmailsHelper(string apiSubscriptionMajorDataSetVersionId, string apiSubscriptionMinorDataSetVersionId) | ||
{ | ||
private readonly string _apiSubscriptionMajorDataSetVersionId = apiSubscriptionMajorDataSetVersionId; | ||
private readonly string _apiSubscriptionMinorDataSetVersionId = apiSubscriptionMinorDataSetVersionId; | ||
/// <summary> | ||
/// Select the correct email template ID based on publication data set version | ||
/// i.e., major/minor version sends a different message via corresponding e-mail template ID | ||
/// </summary> | ||
/// <param name="version"></param> | ||
/// <returns></returns> | ||
/// <exception cref="System.ArgumentException"></exception> | ||
public string SelectApiSubscriptionNotifEmailTemplateID(string version) | ||
{ | ||
if (!Common.Utils.DataSetVersionNumber.TryParse(version, out var dataSetVersionNumber)) | ||
{ | ||
throw new System.ArgumentException(ValidationMessages.InvalidDataSetVersion.Message); | ||
} | ||
var isNewMajorVersion = dataSetVersionNumber!.Major >= 2 | ||
&& dataSetVersionNumber.Patch == 0 | ||
&& dataSetVersionNumber.Minor == 0; | ||
return isNewMajorVersion ? _apiSubscriptionMajorDataSetVersionId : _apiSubscriptionMinorDataSetVersionId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters