Skip to content

Commit

Permalink
refactor: get rid of specific push notification interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
tnotheis committed Nov 14, 2024
1 parent ba1d0c9 commit 7452e39
Show file tree
Hide file tree
Showing 27 changed files with 51 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ namespace Backbone.BuildingBlocks.Application.PushNotifications;

public interface IPushNotificationSender
{
Task SendNotification(IPushNotificationWithConstantText notification, SendPushNotificationFilter filter, CancellationToken cancellationToken);
Task SendNotification(IPushNotification notification, SendPushNotificationFilter filter, CancellationToken cancellationToken);

Task SendNotification(IPushNotificationWithDynamicText notification, SendPushNotificationFilter filter, Dictionary<string, NotificationText> notificationTexts,
Task SendNotification(IPushNotification notification, SendPushNotificationFilter filter, Dictionary<string, NotificationText> notificationTexts,
CancellationToken cancellationToken);
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public async Task<ApproveDeletionProcessResponse> Handle(ApproveDeletionProcessC
var daysUntilDeletion = deletionProcess.GracePeriodEndsAt.Value.DaysUntilDate();

await _notificationSender.SendNotification(
new DeletionProcessApprovedNotification(daysUntilDeletion),
new DeletionProcessApprovedPushNotification(daysUntilDeletion),
new SendPushNotificationFilter { IncludedIdentities = [identity.Address] },
cancellationToken
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async Task<CancelDeletionProcessAsOwnerResponse> Handle(CancelDeletionPro
await _identitiesRepository.Update(identity, cancellationToken);

await _notificationSender.SendNotification(
new DeletionProcessCancelledByOwnerNotification(),
new DeletionProcessCancelledByOwnerPushNotification(),
new SendPushNotificationFilter { IncludedIdentities = [identity.Address] },
cancellationToken
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public async Task<CancelDeletionAsSupportResponse> Handle(CancelDeletionAsSuppor
await _identitiesRepository.Update(identity, cancellationToken);

await _notificationSender.SendNotification(
new DeletionProcessCancelledBySupportNotification(),
new DeletionProcessCancelledBySupportPushNotification(),
new SendPushNotificationFilter { IncludedIdentities = [identity.Address] },
cancellationToken
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

namespace Backbone.Modules.Devices.Application.Infrastructure.PushNotifications.Datawallet;

public record DatawalletModificationsCreatedPushNotification(string CreatedByDevice) : IPushNotificationWithConstantText;
public record DatawalletModificationsCreatedPushNotification(string CreatedByDevice) : IPushNotification;
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

namespace Backbone.Modules.Devices.Application.Infrastructure.PushNotifications.DeletionProcess;

public record DeletionProcessApprovedNotification(int DaysUntilDeletion) : IPushNotificationWithConstantText;
public record DeletionProcessApprovedPushNotification(int DaysUntilDeletion) : IPushNotification;
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

namespace Backbone.Modules.Devices.Application.Infrastructure.PushNotifications.DeletionProcess;

public record DeletionProcessCancelledByOwnerNotification : IPushNotificationWithConstantText;
public record DeletionProcessCancelledByOwnerPushNotification : IPushNotification;
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

namespace Backbone.Modules.Devices.Application.Infrastructure.PushNotifications.DeletionProcess;

public record DeletionProcessCancelledBySupportNotification : IPushNotificationWithConstantText;
public record DeletionProcessCancelledBySupportPushNotification : IPushNotification;
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

namespace Backbone.Modules.Devices.Application.Infrastructure.PushNotifications.DeletionProcess;

public record DeletionProcessGracePeriodReminderPushNotification(int DaysUntilDeletion) : IPushNotificationWithConstantText;
public record DeletionProcessGracePeriodReminderPushNotification(int DaysUntilDeletion) : IPushNotification;
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

namespace Backbone.Modules.Devices.Application.Infrastructure.PushNotifications.DeletionProcess;

public record DeletionProcessStartedPushNotification : IPushNotificationWithConstantText;
public record DeletionProcessStartedPushNotification : IPushNotification;
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

namespace Backbone.Modules.Devices.Application.Infrastructure.PushNotifications.DeletionProcess;

public record DeletionProcessWaitingForApprovalReminderPushNotification(int DaysUntilApprovalPeriodEnds) : IPushNotificationWithConstantText;
public record DeletionProcessWaitingForApprovalReminderPushNotification(int DaysUntilApprovalPeriodEnds) : IPushNotification;
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

namespace Backbone.Modules.Devices.Application.Infrastructure.PushNotifications.DeletionProcess;

public record DeletionStartsPushNotification : IPushNotificationWithConstantText;
public record DeletionStartsPushNotification : IPushNotification;
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

namespace Backbone.Modules.Devices.Application.Infrastructure.PushNotifications.ExternalEvents;

public record ExternalEventCreatedPushNotification : IPushNotificationWithConstantText;
public record ExternalEventCreatedPushNotification : IPushNotification;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Backbone.Modules.Devices.Application.Infrastructure.PushNotifications;

public record TestPushNotification : IPushNotificationWithConstantText
public record TestPushNotification : IPushNotification
{
public object? Data { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ public PushService(IPnsRegistrationsRepository pnsRegistrationRepository, PnsCon
_identitiesRepository = identitiesRepository;
}

public async Task SendNotification(IPushNotificationWithConstantText notification, SendPushNotificationFilter filter, CancellationToken cancellationToken)
public async Task SendNotification(IPushNotification notification, SendPushNotificationFilter filter, CancellationToken cancellationToken)
{
var notificationTexts = _notificationTextProvider.GetNotificationTextsForLanguages(notification.GetType(), await GetDistinctCommunicationLanguages(filter, cancellationToken));
await SendNotificationInternal(notification, filter, notificationTexts, cancellationToken);
}

public async Task SendNotification(IPushNotificationWithDynamicText notification, SendPushNotificationFilter filter, Dictionary<string, NotificationText> notificationTexts,
public async Task SendNotification(IPushNotification notification, SendPushNotificationFilter filter, Dictionary<string, NotificationText> notificationTexts,
CancellationToken cancellationToken)
{
await SendNotificationInternal(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@
<data name="DatawalletModificationsCreatedPushNotification.Title" xml:space="preserve">
<value>Neuigkeiten verfügbar</value>
</data>
<data name="DeletionProcessApprovedNotification.Body" xml:space="preserve">
<data name="DeletionProcessApprovedPushNotification.Body" xml:space="preserve">
<value>Ein Löschvorgang einer Ihrer Identitäten wurde bestätigt und wird in Kürze prozessiert.</value>
</data>
<data name="DeletionProcessApprovedNotification.Title" xml:space="preserve">
<data name="DeletionProcessApprovedPushNotification.Title" xml:space="preserve">
<value>Löschvorgang bestätigt</value>
</data>
<data name="DeletionProcessCancelledByOwnerNotification.Title" xml:space="preserve">
<data name="DeletionProcessCancelledByOwnerPushNotification.Title" xml:space="preserve">
<value>Löschvorgang abgebrochen</value>
</data>
<data name="DeletionProcessCancelledByOwnerNotification.Body" xml:space="preserve">
<data name="DeletionProcessCancelledByOwnerPushNotification.Body" xml:space="preserve">
<value>Ein Löschvorgang einer Ihrer Identitäten wurde von Ihnen abgebrochen.</value>
</data>
<data name="DeletionProcessCancelledBySupportNotification.Body" xml:space="preserve">
<data name="DeletionProcessCancelledBySupportPushNotification.Body" xml:space="preserve">
<value>Ein Löschvorgang einer Ihrer Identitäten wurde von unserem Support Team abgebrochen.</value>
</data>
<data name="DeletionProcessCancelledBySupportNotification.Title" xml:space="preserve">
<data name="DeletionProcessCancelledBySupportPushNotification.Title" xml:space="preserve">
<value>Löschvorgang abgebrochen</value>
</data>
<data name="DeletionProcessGracePeriodReminderPushNotification.Body" xml:space="preserve">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@
<data name="DatawalletModificationsCreatedPushNotification.Title" xml:space="preserve">
<value>Aggiornamenti disponibili</value>
</data>
<data name="DeletionProcessApprovedNotification.Body" xml:space="preserve">
<data name="DeletionProcessApprovedPushNotification.Body" xml:space="preserve">
<value>Un processo di eliminazione di una delle Sue identità è stato approvato e verrà elaborato a breve.</value>
</data>
<data name="DeletionProcessApprovedNotification.Title" xml:space="preserve">
<data name="DeletionProcessApprovedPushNotification.Title" xml:space="preserve">
<value>Un processo di eliminazione è stato approvato.</value>
</data>
<data name="DeletionProcessCancelledByOwnerNotification.Body" xml:space="preserve">
<data name="DeletionProcessCancelledByOwnerPushNotification.Body" xml:space="preserve">
<value>Un processo di eliminazione di una delle Sue identità è stato annullato da Lei.</value>
</data>
<data name="DeletionProcessCancelledByOwnerNotification.Title" xml:space="preserve">
<data name="DeletionProcessCancelledByOwnerPushNotification.Title" xml:space="preserve">
<value>Un processo di eliminazione è stato annullato.</value>
</data>
<data name="DeletionProcessCancelledBySupportNotification.Body" xml:space="preserve">
<data name="DeletionProcessCancelledBySupportPushNotification.Body" xml:space="preserve">
<value>Un processo di eliminazione di una delle Sue identità è stato annullato dal nostro team di supporto.</value>
</data>
<data name="DeletionProcessCancelledBySupportNotification.Title" xml:space="preserve">
<data name="DeletionProcessCancelledBySupportPushNotification.Title" xml:space="preserve">
<value>Un processo di eliminazione è stato annullato.</value>
</data>
<data name="DeletionProcessGracePeriodReminderPushNotification.Body" xml:space="preserve">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@
<data name="DatawalletModificationsCreatedPushNotification.Title" xml:space="preserve">
<value>Atualizações Disponíveis</value>
</data>
<data name="DeletionProcessApprovedNotification.Body" xml:space="preserve">
<data name="DeletionProcessApprovedPushNotification.Body" xml:space="preserve">
<value>Um dos processos de eliminação de uma das suas identidades foi aprovado e será processado brevemente.</value>
</data>
<data name="DeletionProcessApprovedNotification.Title" xml:space="preserve">
<data name="DeletionProcessApprovedPushNotification.Title" xml:space="preserve">
<value>Processo de eliminação aprovado</value>
</data>
<data name="TestPushNotification.Body" xml:space="preserve">
Expand All @@ -135,16 +135,16 @@
<data name="TestPushNotification.Title" xml:space="preserve">
<value>Teste</value>
</data>
<data name="DeletionProcessCancelledByOwnerNotification.Body" xml:space="preserve">
<data name="DeletionProcessCancelledByOwnerPushNotification.Body" xml:space="preserve">
<value>Um dos processos de eliminação de uma das suas identidades foi cancelado por si.</value>
</data>
<data name="DeletionProcessCancelledByOwnerNotification.Title" xml:space="preserve">
<data name="DeletionProcessCancelledByOwnerPushNotification.Title" xml:space="preserve">
<value>Um processo de eliminação foi cancelado</value>
</data>
<data name="DeletionProcessCancelledBySupportNotification.Body" xml:space="preserve">
<data name="DeletionProcessCancelledBySupportPushNotification.Body" xml:space="preserve">
<value>Um dos processos de eliminação de uma das suas identidades foi cancelado pela equipa de suporte.</value>
</data>
<data name="DeletionProcessCancelledBySupportNotification.Title" xml:space="preserve">
<data name="DeletionProcessCancelledBySupportPushNotification.Title" xml:space="preserve">
<value>Um processo de eliminação foi cancelado</value>
</data>
<data name="DeletionProcessGracePeriodReminderPushNotification.Body" xml:space="preserve">
Expand Down Expand Up @@ -177,4 +177,4 @@
<data name="ExternalEventCreatedPushNotification.Title" xml:space="preserve">
<value>Atualização recebida</value>
</data>
</root>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,22 @@
<data name="DatawalletModificationsCreatedPushNotification.Title" xml:space="preserve">
<value>Updates available</value>
</data>
<data name="DeletionProcessApprovedNotification.Body" xml:space="preserve">
<data name="DeletionProcessApprovedPushNotification.Body" xml:space="preserve">
<value>A deletion process of one of your identities has been was approved and will be processed shortly.</value>
</data>
<data name="DeletionProcessApprovedNotification.Title" xml:space="preserve">
<data name="DeletionProcessApprovedPushNotification.Title" xml:space="preserve">
<value>A deletion process has been approved</value>
</data>
<data name="DeletionProcessCancelledByOwnerNotification.Body" xml:space="preserve">
<data name="DeletionProcessCancelledByOwnerPushNotification.Body" xml:space="preserve">
<value>A deletion process of one of your identities has been cancelled by you.</value>
</data>
<data name="DeletionProcessCancelledByOwnerNotification.Title" xml:space="preserve">
<data name="DeletionProcessCancelledByOwnerPushNotification.Title" xml:space="preserve">
<value>A deletion process has been cancelled</value>
</data>
<data name="DeletionProcessCancelledBySupportNotification.Body" xml:space="preserve">
<data name="DeletionProcessCancelledBySupportPushNotification.Body" xml:space="preserve">
<value>A deletion process of one of your identities has been cancelled by our support team.</value>
</data>
<data name="DeletionProcessCancelledBySupportNotification.Title" xml:space="preserve">
<data name="DeletionProcessCancelledBySupportPushNotification.Title" xml:space="preserve">
<value>A deletion process has been cancelled</value>
</data>
<data name="DeletionProcessGracePeriodReminderPushNotification.Body" xml:space="preserve">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public async Task Happy_path()


A.CallTo(() => mockPushNotificationSender.SendNotification(
A<DeletionProcessApprovedNotification>.That.Matches(n => n.DaysUntilDeletion == IdentityDeletionConfiguration.Instance.LengthOfGracePeriodInDays),
A<DeletionProcessApprovedPushNotification>.That.Matches(n => n.DaysUntilDeletion == IdentityDeletionConfiguration.Instance.LengthOfGracePeriodInDays),
A<SendPushNotificationFilter>.That.Matches(f => f.IncludedIdentities.Contains(identity.Address)),
A<CancellationToken>._)
).MustHaveHappenedOnceExactly();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public async Task Happy_path()
response.Status.Should().Be(DeletionProcessStatus.Cancelled);

A.CallTo(() => mockPushNotificationSender.SendNotification(
A<DeletionProcessCancelledByOwnerNotification>._,
A<DeletionProcessCancelledByOwnerPushNotification>._,
A<SendPushNotificationFilter>.That.Matches(f => f.IncludedIdentities.Contains(activeIdentity.Address)),
A<CancellationToken>._)
).MustHaveHappenedOnceExactly();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public async Task Happy_path()
result.CancelledAt.Should().Be(utcNow);

A.CallTo(() => mockPushNotificationSender.SendNotification(
A<DeletionProcessCancelledBySupportNotification>._,
A<DeletionProcessCancelledBySupportPushNotification>._,
A<SendPushNotificationFilter>.That.Matches(f => f.IncludedIdentities.Contains(identity.Address)),
A<CancellationToken>._)
).MustHaveHappenedOnceExactly();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public async Task No_identities_with_a_deletion_process_waiting_for_approval_exi
// Assert
A.CallTo(() => mockIdentitiesRepository.Update(A<Identity>._, A<CancellationToken>._))
.MustNotHaveHappened();
A.CallTo(() => mockPushNotificationSender.SendNotification(A<IPushNotificationWithConstantText>._,
A.CallTo(() => mockPushNotificationSender.SendNotification(
A<DeletionProcessApprovedPushNotification>._,
A<SendPushNotificationFilter>._,
A<CancellationToken>._))
.MustNotHaveHappened();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public async Task No_identities_with_an_approved_deletion_process_exist()
var mockPushNotificationSender = A.Fake<IPushNotificationSender>();

A.CallTo(() => mockIdentitiesRepository.FindAllWithDeletionProcessInStatus(A<DeletionProcessStatus>._, A<CancellationToken>._, A<bool>._))
.Returns(new List<Identity>());
.Returns([]);

var handler = CreateHandler(mockIdentitiesRepository, mockPushNotificationSender);

Expand All @@ -30,7 +30,7 @@ public async Task No_identities_with_an_approved_deletion_process_exist()
A.CallTo(() => mockIdentitiesRepository.Update(A<Identity>._, A<CancellationToken>._))
.MustNotHaveHappened();
A.CallTo(() => mockPushNotificationSender.SendNotification(
A<IPushNotificationWithConstantText>._,
A<DeletionProcessGracePeriodReminderPushNotification>._,
A<SendPushNotificationFilter>._,
A<CancellationToken>._))
.MustNotHaveHappened();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private static IEnumerable<Type> GetNotificationTypes()
return
typeof(TestPushNotification)
.Assembly.GetTypes()
.Where(t => t.IsAssignableTo(typeof(IPushNotificationWithConstantText)) && !t.IsInterface);
.Where(t => t.IsAssignableTo(typeof(IPushNotification)) && !t.IsInterface);
}

private class AllSupportedLanguagesExceptEnglishCrossJoinedWithNotificationTypes : TheoryData<CommunicationLanguage, Type>
Expand All @@ -80,4 +80,4 @@ public AllSupportedLanguagesExceptEnglishCrossJoinedWithNotificationTypes()
}
}

public record PushNotificationWithoutExistingTexts : IPushNotificationWithConstantText;
public record PushNotificationWithoutExistingTexts : IPushNotification;

0 comments on commit 7452e39

Please sign in to comment.