fix(notifications): fixed an error that could happen when Ombi sends out a issue notification

pull/4422/head
tidusjar 3 years ago
parent 473c172492
commit 7442dcf59d

@ -76,6 +76,7 @@ namespace Ombi.Notifications.Tests
{ "IssueUser", "User" },
{ "IssueUserAlias", "alias" },
{ "RequestType", "Movie" },
{ "PosterPath", "aaaaa" }
}
};
var req = F.Build<MovieRequests>()
@ -94,6 +95,39 @@ namespace Ombi.Notifications.Tests
Assert.That("Movie", Is.EqualTo(sut.Type));
}
[Test]
public void IssueNotificationTests_NoRequest()
{
var notificationOptions = new NotificationOptions
{
Substitutes = new Dictionary<string, string>
{
{ "IssueDescription", "Desc" },
{ "IssueCategory", "Cat" },
{ "IssueStatus", "state" },
{ "IssueSubject", "sub" },
{ "NewIssueComment", "a" },
{ "IssueUser", "User" },
{ "IssueUserAlias", "alias" },
{ "RequestType", "Movie" },
{ "PosterPath", "aaaaa" }
}
};
var customization = new CustomizationSettings();
var userPrefs = new UserNotificationPreferences();
sut.Setup(notificationOptions, (MovieRequests)null, customization, userPrefs);
Assert.That("Desc", Is.EqualTo(sut.IssueDescription));
Assert.That("Cat", Is.EqualTo(sut.IssueCategory));
Assert.That("state", Is.EqualTo(sut.IssueStatus));
Assert.That("a", Is.EqualTo(sut.NewIssueComment));
Assert.That("User", Is.EqualTo(sut.UserName));
Assert.That("alias", Is.EqualTo(sut.Alias));
Assert.That("Movie", Is.EqualTo(sut.Type));
Assert.That("https://image.tmdb.org/t/p/w300/aaaaa", Is.EqualTo(sut.PosterImage));
}
[Test]
public void MovieNotificationUserPreferences()
{

@ -40,7 +40,7 @@ namespace Ombi.Notifications
Overview = req?.Overview;
AdditionalInformation = opts?.AdditionalInformation ?? string.Empty;
var img = req?.PosterPath ?? string.Empty;
var img = req?.PosterPath ?? string.Empty;
if (img.HasValue())
{
PosterImage = $"https://image.tmdb.org/t/p/w300/{req?.PosterPath?.TrimStart('/') ?? string.Empty}";
@ -113,7 +113,14 @@ namespace Ombi.Notifications
Type = opts.Substitutes.TryGetValue(NotificationSubstitues.RequestType, out val) && Enum.TryParse(val, out RequestType type)
? HumanizeReturnType(type)
: string.Empty;
PosterImage = opts.Substitutes.TryGetValue(NotificationSubstitues.PosterPath, out val) ? $"https://image.tmdb.org/t/p/w300/{val.TrimStart('/')}" : string.Empty;
if (opts.Substitutes.TryGetValue(NotificationSubstitues.PosterPath, out val) && val.HasValue())
{
PosterImage = $"https://image.tmdb.org/t/p/w300/{val.TrimStart('/')}";
}
else
{
PosterImage = string.Empty;
}
}
private void LoadCommon(BaseRequest req, CustomizationSettings s, UserNotificationPreferences pref, NotificationOptions opts)

Loading…
Cancel
Save