Verified that nexus entries are purged by the updates job

This commit is contained in:
Timothy Baldridge 2020-04-10 16:48:53 -06:00
parent c4ef7f3be1
commit 26a42d3ceb
2 changed files with 55 additions and 2 deletions

View File

@ -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<BuildServerFixture> fixture) : base(output, fixture)
{
}
[Fact]
public async Task CanRunNexusUpdateJob()
{
var sql = Fixture.GetService<SqlService>();
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));
}
}
}
}

View File

@ -12,13 +12,13 @@ namespace Wabbajack.Lib.NexusApi
public class NexusUpdatesFeeds
{
public static async Task<IEnumerable<UpdateRecord>> GetUpdates()
public static async Task<List<UpdateRecord>> 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;
}