diff --git a/Wabbajack.BuildServer.Test/JobTests.cs b/Wabbajack.BuildServer.Test/JobTests.cs new file mode 100644 index 00000000..9d588658 --- /dev/null +++ b/Wabbajack.BuildServer.Test/JobTests.cs @@ -0,0 +1,53 @@ +using System; +using System.Linq; +using System.Threading.Tasks; +using Wabbajack.BuildServer.Model.Models; +using Wabbajack.BuildServer.Models.JobQueue; +using Wabbajack.BuildServer.Models.Jobs; +using Wabbajack.Common; +using Wabbajack.Lib.NexusApi; +using Xunit; +using Xunit.Abstractions; + +namespace Wabbajack.BuildServer.Test +{ + + public class JobTests : ABuildServerSystemTest + { + public JobTests(ITestOutputHelper output, SingletonAdaptor fixture) : base(output, fixture) + { + } + + [Fact] + public async Task CanRunNexusUpdateJob() + { + var sql = Fixture.GetService(); + + var oldRecords = await NexusUpdatesFeeds.GetUpdates(); + foreach (var record in oldRecords) + { + await sql.AddNexusModInfo(record.Game, record.ModId, DateTime.UtcNow - TimeSpan.FromDays(1), + new ModInfo()); + await sql.AddNexusModFiles(record.Game, record.ModId, DateTime.UtcNow - TimeSpan.FromDays(1), + new NexusApiClient.GetModFilesResponse()); + + Assert.NotNull(await sql.GetModFiles(record.Game, record.ModId)); + Assert.NotNull(await sql.GetNexusModInfoString(record.Game, record.ModId)); + } + + Utils.Log($"Ingested {oldRecords.Count()} nexus records"); + + // We know this will load the same records as above, but the date will be more recent, so the above records + // should no longer exist in SQL after this job is run + await sql.EnqueueJob(new Job {Payload = new GetNexusUpdatesJob()}); + await RunAllJobs(); + + foreach (var record in oldRecords) + { + Assert.Null(await sql.GetModFiles(record.Game, record.ModId)); + Assert.Null(await sql.GetNexusModInfoString(record.Game, record.ModId)); + } + + } + } +} diff --git a/Wabbajack.Lib/NexusApi/NexusUpdatesFeeds.cs b/Wabbajack.Lib/NexusApi/NexusUpdatesFeeds.cs index c33655c2..164d2250 100644 --- a/Wabbajack.Lib/NexusApi/NexusUpdatesFeeds.cs +++ b/Wabbajack.Lib/NexusApi/NexusUpdatesFeeds.cs @@ -12,13 +12,13 @@ namespace Wabbajack.Lib.NexusApi public class NexusUpdatesFeeds { - public static async Task> GetUpdates() + public static async Task> GetUpdates() { var updated = GetFeed(new Uri("https://www.nexusmods.com/rss/updatedtoday")); var newToday = GetFeed(new Uri("https://www.nexusmods.com/rss/newtoday")); var sorted = (await updated).Concat(await newToday).OrderByDescending(f => f.TimeStamp); - var deduped = sorted.GroupBy(g => (g.Game, g.ModId)).Select(g => g.First()); + var deduped = sorted.GroupBy(g => (g.Game, g.ModId)).Select(g => g.First()).ToList(); return deduped; }