diff --git a/Wabbajack.BuildServer.Test/ModListValidationTests.cs b/Wabbajack.BuildServer.Test/ModListValidationTests.cs index cf3d9080..54809320 100644 --- a/Wabbajack.BuildServer.Test/ModListValidationTests.cs +++ b/Wabbajack.BuildServer.Test/ModListValidationTests.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Security.Policy; using System.Text; using System.Threading.Tasks; +using HtmlAgilityPack; using Wabbajack.BuildServer.Model.Models; using Wabbajack.BuildServer.Models; using Wabbajack.BuildServer.Models.JobQueue; @@ -41,23 +42,35 @@ namespace Wabbajack.BuildServer.Test var modlists = await MakeModList(); Consts.ModlistMetadataURL = modlists.ToString(); Utils.Log("Updating modlists"); - var result = await AuthorAPI.UpdateServerModLists(); - Assert.NotNull(result); - - var sql = Fixture.GetService(); - var settings = Fixture.GetService(); - var job = await sql.GetJob(); - - Assert.NotNull(job); - Assert.IsType(job.Payload); - - - var jobResult = await job.Payload.Execute(sql, settings); - Assert.Equal(JobResultType.Success, jobResult.ResultType); + await RevalidateLists(); Utils.Log("Checking validated results"); var data = await ModlistMetadata.LoadFromGithub(); + Assert.Single(data); + Assert.Equal(0, data.First().ValidationSummary.Failed); + Assert.Equal(1, data.First().ValidationSummary.Passed); + await CheckListFeeds(0, 1); + + Utils.Log("Break List"); + var archive = "test_archive.txt".RelativeTo(Fixture.ServerPublicFolder); + await archive.MoveToAsync(archive.WithExtension(new Extension(".moved")), true); + + await RevalidateLists(); + + data = await ModlistMetadata.LoadFromGithub(); + Assert.Single(data); + Assert.Equal(1, data.First().ValidationSummary.Failed); + Assert.Equal(0, data.First().ValidationSummary.Passed); + + await CheckListFeeds(1, 0); + + Utils.Log("Fix List"); + await archive.WithExtension(new Extension(".moved")).MoveToAsync(archive, false); + + await RevalidateLists(); + + data = await ModlistMetadata.LoadFromGithub(); Assert.Single(data); Assert.Equal(0, data.First().ValidationSummary.Failed); Assert.Equal(1, data.First().ValidationSummary.Passed); @@ -66,13 +79,36 @@ namespace Wabbajack.BuildServer.Test } + private async Task RevalidateLists() + { + var result = await AuthorAPI.UpdateServerModLists(); + Assert.NotNull(result); + + var sql = Fixture.GetService(); + var settings = Fixture.GetService(); + var job = await sql.GetJob(); + + Assert.NotNull(job); + Assert.IsType(job.Payload); + + + var jobResult = await job.Payload.Execute(sql, settings); + Assert.Equal(JobResultType.Success, jobResult.ResultType); + } + private async Task CheckListFeeds(int failed, int passed) { var statusJson = await _client.GetJsonAsync(MakeURL("lists/status/test_list.json")); Assert.Equal(failed, statusJson.Archives.Count(a => a.IsFailing)); Assert.Equal(passed, statusJson.Archives.Count(a => !a.IsFailing)); + + var statusHtml = await _client.GetHtmlAsync(MakeURL("lists/status/test_list.html")); + Assert.NotEmpty(statusHtml.DocumentNode.Descendants().Where(n => n.InnerHtml == $"Failed ({failed}):")); + Assert.NotEmpty(statusHtml.DocumentNode.Descendants().Where(n => n.InnerHtml == $"Passed ({passed}):")); + var statusRss = await _client.GetHtmlAsync(MakeURL("lists/status/test_list/broken.rss")); + Assert.Equal(failed, statusRss.DocumentNode.SelectNodes("//item")?.Count ?? 0); } diff --git a/Wabbajack.Common/Http/Client.cs b/Wabbajack.Common/Http/Client.cs index 03cd7b88..098f8866 100644 --- a/Wabbajack.Common/Http/Client.cs +++ b/Wabbajack.Common/Http/Client.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Net; using System.Net.Http; using System.Threading.Tasks; +using HtmlAgilityPack; namespace Wabbajack.Common.Http { @@ -104,5 +105,13 @@ namespace Wabbajack.Common.Http var result = await GetStringAsync(s); return result.FromJsonString(); } + + public async Task GetHtmlAsync(string s) + { + var body = await GetStringAsync(s); + var doc = new HtmlDocument(); + doc.LoadHtml(body); + return doc; + } } } diff --git a/Wabbajack.Common/Wabbajack.Common.csproj b/Wabbajack.Common/Wabbajack.Common.csproj index 7ff53fbc..de256fc8 100644 --- a/Wabbajack.Common/Wabbajack.Common.csproj +++ b/Wabbajack.Common/Wabbajack.Common.csproj @@ -27,6 +27,7 @@ +