mirror of
https://github.com/Radarr/Radarr
synced 2026-05-07 11:51:00 +02:00
Merge 00ab58232c into 9226876792
This commit is contained in:
commit
382c608a29
4 changed files with 91 additions and 5 deletions
|
|
@ -0,0 +1,68 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.Movies;
|
||||
using NzbDrone.Core.Notifications;
|
||||
using NzbDrone.Core.Notifications.Gotify;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.NotificationTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class GotifyServiceFixture : CoreTest<Gotify>
|
||||
{
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
Subject.Definition = new NotificationDefinition
|
||||
{
|
||||
Settings = new GotifySettings
|
||||
{
|
||||
Server = "https://example.invalid",
|
||||
AppToken = "token",
|
||||
Priority = 5,
|
||||
IncludeMoviePoster = false,
|
||||
IncludeInstanceNameInTitle = false,
|
||||
MetadataLinks = Enumerable.Empty<int>(),
|
||||
PreferredMetadataLink = (int)MetadataLinkType.Tmdb
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
[TestCase(false, "MyRadarr", false)]
|
||||
[TestCase(true, "MyRadarr", true)]
|
||||
[TestCase(true, "", false)]
|
||||
[TestCase(true, " ", false)]
|
||||
public void OnDownload_should_append_instance_name_to_title_only_when_enabled_and_non_empty(bool includeInstanceNameInTitle, string instanceName, bool shouldAppendInstanceName)
|
||||
{
|
||||
((GotifySettings)Subject.Definition.Settings).IncludeInstanceNameInTitle = includeInstanceNameInTitle;
|
||||
|
||||
Mocker.GetMock<IConfigFileProvider>()
|
||||
.SetupGet(c => c.InstanceName)
|
||||
.Returns(instanceName);
|
||||
|
||||
var message = new DownloadMessage
|
||||
{
|
||||
Movie = new Movie { Title = "Movie" },
|
||||
Message = "downloaded"
|
||||
};
|
||||
|
||||
Subject.OnDownload(message);
|
||||
|
||||
var suffix = $" - {instanceName}";
|
||||
|
||||
Predicate<GotifyMessage> titleHasCorrectSuffix = m =>
|
||||
shouldAppendInstanceName
|
||||
? m.Title.EndsWith(suffix)
|
||||
: !m.Title.EndsWith(" - ") && !m.Title.EndsWith(suffix);
|
||||
|
||||
Mocker.GetMock<IGotifyProxy>()
|
||||
.Verify(p => p.SendNotification(
|
||||
It.Is<GotifyMessage>(m => titleHasCorrectSuffix(m)),
|
||||
It.IsAny<GotifySettings>()),
|
||||
Times.Once());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1282,6 +1282,8 @@
|
|||
"NotificationsGotifySettingsPriorityHelpText": "Priority of the notification",
|
||||
"NotificationsGotifySettingsServer": "Gotify Server",
|
||||
"NotificationsGotifySettingsServerHelpText": "Gotify server URL, including http(s):// and port if needed",
|
||||
"NotificationsGotifySettingsIncludeAppName": "Include {appName} in Title",
|
||||
"NotificationsGotifySettingsIncludeAppNameHelpText": "Optionally suffix message title with {appName} to differentiate notifications from different applications",
|
||||
"NotificationsJoinSettingsApiKeyHelpText": "The API Key from your Join account settings (click Join API button).",
|
||||
"NotificationsJoinSettingsDeviceIds": "Device IDs",
|
||||
"NotificationsJoinSettingsDeviceIdsHelpText": "Deprecated, use Device Names instead. Comma separated list of Device IDs you'd like to send notifications to. If unset, all devices will receive notifications.",
|
||||
|
|
@ -1383,7 +1385,7 @@
|
|||
"NotificationsTelegramSettingsChatId": "Chat ID",
|
||||
"NotificationsTelegramSettingsChatIdHelpText": "You must start a conversation with the bot or add it to your group to receive messages",
|
||||
"NotificationsTelegramSettingsIncludeAppName": "Include {appName} in Title",
|
||||
"NotificationsTelegramSettingsIncludeAppNameHelpText": "Optionally prefix message title with {appName} to differentiate notifications from different applications",
|
||||
"NotificationsTelegramSettingsIncludeAppNameHelpText": "Optionally suffix message title with {appName} to differentiate notifications from different applications",
|
||||
"NotificationsTelegramSettingsIncludeInstanceName": "Include Instance Name in Title",
|
||||
"NotificationsTelegramSettingsIncludeInstanceNameHelpText": "Optionally include Instance name in notification",
|
||||
"NotificationsTelegramSettingsMetadataLinks": "Metadata Links",
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
using FluentValidation.Results;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.Localization;
|
||||
using NzbDrone.Core.MediaCover;
|
||||
using NzbDrone.Core.Movies;
|
||||
|
|
@ -17,12 +18,14 @@ public class Gotify : NotificationBase<GotifySettings>
|
|||
|
||||
private readonly IGotifyProxy _proxy;
|
||||
private readonly ILocalizationService _localizationService;
|
||||
private readonly IConfigFileProvider _configFileProvider;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public Gotify(IGotifyProxy proxy, ILocalizationService localizationService, Logger logger)
|
||||
public Gotify(IGotifyProxy proxy, ILocalizationService localizationService, IConfigFileProvider configFileProvider, Logger logger)
|
||||
{
|
||||
_proxy = proxy;
|
||||
_localizationService = localizationService;
|
||||
_configFileProvider = configFileProvider;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
|
|
@ -81,11 +84,16 @@ public override ValidationResult Test()
|
|||
try
|
||||
{
|
||||
var isMarkdown = false;
|
||||
const string title = "Test Notification";
|
||||
var title = "Test Notification";
|
||||
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine("This is a test message from Radarr");
|
||||
|
||||
if (Settings.IncludeInstanceNameInTitle && _configFileProvider.InstanceName.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
title += $" - {_configFileProvider.InstanceName}";
|
||||
}
|
||||
|
||||
var payload = new GotifyMessage
|
||||
{
|
||||
Title = title,
|
||||
|
|
@ -130,6 +138,11 @@ private void SendNotification(string title, string message, Movie movie)
|
|||
|
||||
sb.AppendLine(message);
|
||||
|
||||
if (Settings.IncludeInstanceNameInTitle && _configFileProvider.InstanceName.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
title += $" - {_configFileProvider.InstanceName}";
|
||||
}
|
||||
|
||||
var payload = new GotifyMessage
|
||||
{
|
||||
Title = title,
|
||||
|
|
|
|||
|
|
@ -64,10 +64,13 @@ public GotifySettings()
|
|||
[FieldDefinition(3, Label = "NotificationsGotifySettingIncludeMoviePoster", Type = FieldType.Checkbox, HelpText = "NotificationsGotifySettingIncludeMoviePosterHelpText")]
|
||||
public bool IncludeMoviePoster { get; set; }
|
||||
|
||||
[FieldDefinition(4, Label = "NotificationsGotifySettingsMetadataLinks", Type = FieldType.Select, SelectOptions = typeof(MetadataLinkType), HelpText = "NotificationsGotifySettingsMetadataLinksMovieHelpText")]
|
||||
[FieldDefinition(4, Label = "NotificationsTelegramSettingsIncludeAppName", Type = FieldType.Checkbox, HelpText = "NotificationsTelegramSettingsIncludeAppNameHelpText")]
|
||||
public bool IncludeInstanceNameInTitle { get; set; }
|
||||
|
||||
[FieldDefinition(5, Label = "NotificationsGotifySettingsMetadataLinks", Type = FieldType.Select, SelectOptions = typeof(MetadataLinkType), HelpText = "NotificationsGotifySettingsMetadataLinksMovieHelpText")]
|
||||
public IEnumerable<int> MetadataLinks { get; set; }
|
||||
|
||||
[FieldDefinition(5, Label = "NotificationsGotifySettingsPreferredMetadataLink", Type = FieldType.Select, SelectOptions = typeof(MetadataLinkType), HelpText = "NotificationsGotifySettingsPreferredMetadataLinkHelpText")]
|
||||
[FieldDefinition(6, Label = "NotificationsGotifySettingsPreferredMetadataLink", Type = FieldType.Select, SelectOptions = typeof(MetadataLinkType), HelpText = "NotificationsGotifySettingsPreferredMetadataLinkHelpText")]
|
||||
public int PreferredMetadataLink { get; set; }
|
||||
|
||||
public override NzbDroneValidationResult Validate()
|
||||
|
|
|
|||
Loading…
Reference in a new issue