Skip to content

Commit

Permalink
fix(notifications): 🐛 This is a fix for some of the duplicate notific…
Browse files Browse the repository at this point in the history
…ation issues #3825
  • Loading branch information
tidusjar committed Feb 12, 2022
1 parent 53bff29 commit 22bb422
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 9 deletions.
42 changes: 42 additions & 0 deletions src/Ombi.Notifications.Tests/NotificationServiceTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Moq.AutoMock;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Ombi.Notifications.Tests
{
[TestFixture]
public class NotificationServiceTests
{

private NotitficationServiceTestFacade _subject;

[SetUp]
public void Setup()
{
var mocker = new AutoMocker();
mocker.Use(NullLogger.Instance);
_subject = mocker.CreateInstance<NotitficationServiceTestFacade>();
}

[Test]
public void PopulateAgentsTests()
{
Assert.That(_subject.Agents, Has.Count.EqualTo(12));
Assert.That(_subject.Agents.DistinctBy(x => x.NotificationName).ToList(), Has.Count.EqualTo(12));
}
}


public class NotitficationServiceTestFacade : NotificationService
{
public NotitficationServiceTestFacade(IServiceProvider provider, ILogger<NotificationService> log) : base(provider, log)
{
}

public List<INotification> Agents => base.NotificationAgents;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="6.0.0" />
<packagereference Include="Microsoft.NET.Test.Sdk" Version="16.8.0"></packagereference>
<PackageReference Include="Moq" Version="4.10.0" />
<PackageReference Include="Moq.AutoMock" Version="0.4.0" />
</ItemGroup>

<ItemGroup>
Expand Down
16 changes: 9 additions & 7 deletions src/Ombi.Notifications/BaseNotification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected BaseNotification(ISettingsService<T> settings, INotificationTemplatesR
AlbumRepository = album;
UserNotificationPreferences = notificationUserPreferences;
_userManager = um;
Settings.ClearCache();
Settings?.ClearCache();
}

protected ISettingsService<T> Settings { get; }
Expand Down Expand Up @@ -64,7 +64,11 @@ public async Task NotifyAsync(NotificationOptions model)

public async Task NotifyAsync(NotificationOptions model, Settings.Settings.Models.Settings settings)
{
if (settings == null) await NotifyAsync(model);
if (settings == null)
{
await NotifyAsync(model);
return;
}

var notificationSettings = (T)settings;

Expand Down Expand Up @@ -114,15 +118,13 @@ public async Task NotifyAsync(NotificationOptions model, Settings.Settings.Model
case NotificationType.IssueComment:
await IssueComment(model, notificationSettings);
break;
case NotificationType.AdminNote:
case NotificationType.PartiallyAvailable:
await PartiallyAvailable(model, notificationSettings);
break;
case NotificationType.AdminNote:
case NotificationType.WelcomeEmail:
break;
case NotificationType.Newsletter:
break;
case NotificationType.PartiallyAvailable:
await PartiallyAvailable(model, notificationSettings);
break;
default:
throw new ArgumentOutOfRangeException();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Ombi.Notifications/NotificationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public NotificationService(IServiceProvider provider, ILogger<NotificationServic
PopulateAgents();
}

private List<INotification> NotificationAgents { get; }
protected List<INotification> NotificationAgents { get; }
private ILogger<NotificationService> Log { get; }

/// <summary>
Expand Down Expand Up @@ -55,7 +55,7 @@ private async Task NotifyAsync(INotification notification, NotificationOptions m

}

private void PopulateAgents()
protected void PopulateAgents()
{
var baseSearchType = typeof(BaseNotification<>).Name;

Expand Down

0 comments on commit 22bb422

Please # to comment.