mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
add GetMostRecentSnapshotMetaAsyncShould tests
This commit is contained in:
parent
c78abcc588
commit
e6df789dcc
3 changed files with 41 additions and 2 deletions
|
|
@ -27,7 +27,7 @@ public override async Task TrySaveAsync()
|
|||
|
||||
private async Task UpdateWaybackData()
|
||||
{
|
||||
var snapshotMeta = await WaybackService.GetMostRecentSnapshotMeta(ListUrl);
|
||||
var snapshotMeta = await WaybackService.GetMostRecentSnapshotMetaAsync(ListUrl);
|
||||
if (snapshotMeta != null)
|
||||
{
|
||||
ListUrl = SnapEntity.WaybackUrl = snapshotMeta.UrlRaw;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ public static class WaybackService
|
|||
{
|
||||
private const string WaybackAvailabilityApiUrlPrefix = "https://archive.org/wayback/available?url=";
|
||||
|
||||
public static async Task<SnapshotMetaDto> GetMostRecentSnapshotMeta(string url)
|
||||
public static async Task<SnapshotMetaDto> GetMostRecentSnapshotMetaAsync(string url)
|
||||
{
|
||||
var closest = (await GetWaybackAvailability(url))?.ArchivedSnapshots?.Closest;
|
||||
return closest != null
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
using System;
|
||||
using System.Net.Http;
|
||||
using FilterLists.Services.Wayback;
|
||||
using Xunit;
|
||||
|
||||
namespace FilterLists.Services.Tests.Wayback
|
||||
{
|
||||
public class GetMostRecentSnapshotMetaAsyncShould
|
||||
{
|
||||
[Fact]
|
||||
public async void ReturnAccessibleUrlRawIfInWaybackMachine()
|
||||
{
|
||||
const string url = "https://github.com/collinbarrett/FilterLists";
|
||||
var meta = await WaybackService.GetMostRecentSnapshotMetaAsync(url);
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
var response = await client.GetAsync(meta.UrlRaw);
|
||||
Assert.True(response.IsSuccessStatusCode);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void ReturnNullIfUrlNotInWaybackMachine()
|
||||
{
|
||||
const string url = "https://raw.githubusercontent.com/collinbarrett/FilterLists/master/doesnotexist";
|
||||
var meta = await WaybackService.GetMostRecentSnapshotMetaAsync(url);
|
||||
Assert.Null(meta);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void ReturnRecentTimestampUtcIfInWaybackMachine()
|
||||
{
|
||||
const string url = "https://github.com/collinbarrett/FilterLists";
|
||||
var meta = await WaybackService.GetMostRecentSnapshotMetaAsync(url);
|
||||
Assert.True(meta.TimestampUtc > DateTime.Now.AddYears(-5).ToUniversalTime() &&
|
||||
meta.TimestampUtc < DateTime.UtcNow);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue