Newsbot.Collector/Newsbot.Collector.Tests/Jobs/DiscordNotificationJobTest.cs
James Tombleson 70440aa3f5
Features/subscription details dto (#29)
* DTO was updated to reflect the new options

* SubscriptionsController.cs added id's as part of the path not query

* Refactored DiscordNotificationJob.cs to break apart the nesting

* Added a test to make sure commits would not be sent based on model values
2023-04-14 21:39:02 -07:00

94 lines
3.2 KiB
C#

using Newsbot.Collector.Domain.Models;
using Newsbot.Collector.Services.Jobs;
using Newsbot.Collector.Services.Notifications.Discord;
namespace Newsbot.Collector.Tests.Jobs;
public class DiscordNotificationJobTest
{
[Fact]
public void PostTestMessage()
{
var uri = "";
var webhookClient = new DiscordWebhookClient(uri);
var client = new DiscordNotificationJob();
var msg = client.GenerateDiscordMessage(new SourceModel
{
ID = Guid.NewGuid(),
Site = "Unit Test",
Source = "placeholder",
Type = "a",
Value = "a",
Enabled = true,
Url = "https://github.com",
Tags = "Unit, Testing"
},
new ArticlesModel
{
Tags = "more,unit,testing",
Title = "Nope not real",
URL = "https://github.com/jtom38",
PubDate = DateTime.Now,
Thumbnail = "https://cdn.arstechnica.net/wp-content/uploads/2023/03/GettyImages-944827400-800x534.jpg",
Description = "Please work",
AuthorName = "No one knows"
},
new IconModel
{
Id = Guid.NewGuid(),
FileName = "https://www.redditstatic.com/desktop2x/img/favicon/android-icon-192x192.png"
});
webhookClient.SendMessage(msg);
}
[Fact]
public void SkipsCodeCommitWhenSubscriptionDoesNotWantThem()
{
var client = new DiscordNotificationJob();
try
{
client.SendSubscriptionNotification(
new Guid(),
new ArticlesModel
{
Tags = "more,unit,testing",
Title = "Nope not real",
URL = "https://github.com/jtom38",
PubDate = DateTime.Now,
Thumbnail =
"https://cdn.arstechnica.net/wp-content/uploads/2023/03/GettyImages-944827400-800x534.jpg",
Description = "Please work",
AuthorName = "No one knows",
CodeIsCommit = true
},
new SourceModel
{
ID = Guid.NewGuid(),
Site = "Unit Test",
Source = "placeholder",
Type = "a",
Value = "a",
Enabled = true,
Url = "https://github.com",
Tags = "Unit, Testing"
},
new IconModel
{
Id = Guid.NewGuid(),
FileName = "https://www.redditstatic.com/desktop2x/img/favicon/android-icon-192x192.png"
},
new SubscriptionModel
{
CodeAllowCommits = false,
CodeAllowReleases = true
});
Assert.Fail("Expected a error to come back.");
}
catch (MessageTypeNotRequestedException)
{
Console.Write($"Message did not send as expected");
}
}
}