Newsbot.Collector/Newsbot.Collector.Tests/Jobs/DiscordNotificationJobTest.cs

100 lines
3.3 KiB
C#

using Newsbot.Collector.Domain.Entities;
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 DiscordClient(uri);
var client = new DiscordNotificationJob();
var msg = client.GenerateDiscordMessage(new SourceEntity
{
Id = Guid.NewGuid(),
Site = "Unit Test",
Source = "placeholder",
Type = "a",
Value = "a",
Enabled = true,
Url = "https://github.com",
Tags = "Unit, Testing"
},
new ArticlesEntity
{
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",
},
new IconEntity()
{
Id = Guid.NewGuid(),
FileName = "https://www.redditstatic.com/desktop2x/img/favicon/android-icon-192x192.png"
}, new AuthorEntity
{
Id = Guid.NewGuid(),
Name = "test"
});
webhookClient.SendMessage(msg);
}
[Fact]
public void SkipsCodeCommitWhenSubscriptionDoesNotWantThem()
{
var client = new DiscordNotificationJob();
try
{
client.SendSubscriptionNotification(
new Guid(),
new ArticlesEntity
{
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",
CodeIsCommit = true
},
new SourceEntity
{
Id = Guid.NewGuid(),
Site = "Unit Test",
Source = "placeholder",
Type = "a",
Value = "a",
Enabled = true,
Url = "https://github.com",
Tags = "Unit, Testing"
},
new IconEntity()
{
Id = Guid.NewGuid(),
FileName = "https://www.redditstatic.com/desktop2x/img/favicon/android-icon-192x192.png"
},
new DiscordNotificationEntity
{
CodeAllowCommits = false,
CodeAllowReleases = true
}, new AuthorEntity
{
Name = "a"
});
Assert.Fail("Expected a error to come back.");
}
catch (MessageTypeNotRequestedException)
{
Console.Write($"Message did not send as expected");
}
}
}