Newsbot.Collector/Newsbot.Collector.Tests/Jobs/CodeProjectWatcherJobTests.cs
James Tombleson 117653c001
Features/add code projects watcher (#26)
* Migration added to update Articles to define if Release or Commit

* CodeProjectWatcher Job was created from GithubWatcher as this will target services like gitlab and also gitea.

* article model was updated to reflect migration changes

* Added CodeProjects to startup

* Seed was updated with CodeProjects and some new defaults

* Added Delete call for Sources

* Added a route to cleanup all records based on SourceId

* Added CodeProject const values to load from config

* minor changes to the rss controller

* Added codeprojects to the routes to trigger the job
2023-04-10 22:59:13 -07:00

88 lines
2.8 KiB
C#

using Microsoft.Extensions.Configuration;
using Newsbot.Collector.Domain.Consts;
using Newsbot.Collector.Domain.Models;
using Newsbot.Collector.Domain.Models.Config;
using Newsbot.Collector.Services.Jobs;
namespace Newsbot.Collector.Tests.Jobs;
public class CodeProjectWatcherJobTests
{
[Fact]
public void CanReturnReleases()
{
var client = new CodeProjectWatcherJob(new CodeProjectWatcherJobOptions
{
ConnectionStrings = TestHelper.LoadConfig().GetSection(ConfigConst.SectionConnectionStrings)
.Get<ConfigSectionConnectionStrings>(),
FeaturePullCommits = true,
FeaturePullReleases = true
});
var results = client.CheckForReleases(new SourceModel
{
ID = Guid.NewGuid(),
Url = "https://github.com/jtom38/dvb",
Type = SourceTypes.CodeProject,
Site = SourceTypes.CodeProject,
Name = "jtom38/dvb",
Source = "feed",
Enabled = true
});
if (!results.Any())
{
Assert.Fail("Expected at least one item");
}
}
[Fact]
public void CollectsTagsButNoReleases()
{
var client = new CodeProjectWatcherJob(new CodeProjectWatcherJobOptions
{
ConnectionStrings = TestHelper.LoadConfig().GetSection(ConfigConst.SectionConnectionStrings)
.Get<ConfigSectionConnectionStrings>(),
FeaturePullCommits = true,
FeaturePullReleases = true
});
var results = client.CheckForReleases(new SourceModel
{
ID = Guid.NewGuid(),
Url = "https://github.com/python/cpython",
Type = SourceTypes.CodeProject,
Site = SourceTypes.CodeProject,
Name = "python.cpython",
Source = "feed",
Enabled = true
});
if (!results.Any())
{
Assert.Fail("Expected at least one item");
}
}
[Fact]
public void CollectsCommits()
{
var client = new CodeProjectWatcherJob(new CodeProjectWatcherJobOptions
{
ConnectionStrings = TestHelper.LoadConfig().GetSection(ConfigConst.SectionConnectionStrings)
.Get<ConfigSectionConnectionStrings>(),
FeaturePullCommits = true,
FeaturePullReleases = true
});
var results = client.CheckForCommits(new SourceModel
{
ID = Guid.NewGuid(),
Url = "https://github.com/jtom38/dvb",
Type = SourceTypes.CodeProject,
Site = SourceTypes.CodeProject,
Name = "jtom38/dvb",
Source = "feed",
Enabled = true
});
if (!results.Any())
{
Assert.Fail("Expected at least one item");
}
}
}