import_viewer: round-trip ViewerMission + ViewerEventCounter
This commit is contained in:
@@ -5,6 +5,7 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using SVSim.Database;
|
||||
using SVSim.Database.Enums;
|
||||
using SVSim.Database.Models;
|
||||
using SVSim.EmulatedEntrypoint.Models.Dtos.Requests.Admin;
|
||||
using SVSim.EmulatedEntrypoint.Models.Dtos.Responses.Admin;
|
||||
using SVSim.UnitTests.Infrastructure;
|
||||
@@ -484,4 +485,104 @@ public class AdminControllerTests
|
||||
Assert.That(viewer.MissionData.MissionChangeTime,
|
||||
Is.EqualTo(DateTimeOffset.FromUnixTimeSeconds(1_700_000_000L).UtcDateTime));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ImportViewer_Missions_RoundTripsWithCounter()
|
||||
{
|
||||
using var factory = new SVSimTestFactory();
|
||||
using (var seedScope = factory.Services.CreateScope())
|
||||
{
|
||||
var db = seedScope.ServiceProvider.GetRequiredService<SVSimDbContext>();
|
||||
db.MissionCatalog.Add(new MissionCatalogEntry
|
||||
{
|
||||
Id = 9001, LotType = 6 /* daily */,
|
||||
EventType = "battle_win_total", EventArg = null
|
||||
});
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
var client = factory.CreateClient();
|
||||
ulong steamId = 70000000000000002UL;
|
||||
|
||||
var resp = await client.PostAsJsonAsync("/admin/import_viewer", new ImportViewerRequest
|
||||
{
|
||||
SteamId = steamId,
|
||||
Missions = new List<ImportMission>
|
||||
{
|
||||
new() { MissionId = 9001, MissionStatus = 1, TotalCount = 7 }
|
||||
}
|
||||
});
|
||||
resp.EnsureSuccessStatusCode();
|
||||
var body = await resp.Content.ReadFromJsonAsync<ImportViewerResponse>(JsonOptions);
|
||||
Assert.That(body!.SkippedMissionCount, Is.EqualTo(0));
|
||||
Assert.That(body.SkippedMissionCounterCount, Is.EqualTo(0));
|
||||
|
||||
using var scope = factory.Services.CreateScope();
|
||||
var verifyDb = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
|
||||
var viewerId = await verifyDb.Viewers
|
||||
.Where(v => v.SocialAccountConnections
|
||||
.Any(s => s.AccountType == SocialAccountType.Steam && s.AccountId == steamId))
|
||||
.Select(v => v.Id).SingleAsync();
|
||||
Assert.That(verifyDb.ViewerMissions.Count(m => m.ViewerId == viewerId && m.MissionCatalogId == 9001), Is.EqualTo(1));
|
||||
Assert.That(verifyDb.ViewerEventCounters
|
||||
.Count(c => c.ViewerId == viewerId && c.EventKey == "battle_win_total" && c.Count == 7), Is.EqualTo(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ImportViewer_Missions_UnknownMissionIdSkipped()
|
||||
{
|
||||
using var factory = new SVSimTestFactory();
|
||||
var client = factory.CreateClient();
|
||||
ulong steamId = 70000000000000003UL;
|
||||
|
||||
var resp = await client.PostAsJsonAsync("/admin/import_viewer", new ImportViewerRequest
|
||||
{
|
||||
SteamId = steamId,
|
||||
Missions = new List<ImportMission>
|
||||
{
|
||||
new() { MissionId = 999999, MissionStatus = 1, TotalCount = 3 }
|
||||
}
|
||||
});
|
||||
resp.EnsureSuccessStatusCode();
|
||||
var body = await resp.Content.ReadFromJsonAsync<ImportViewerResponse>(JsonOptions);
|
||||
Assert.That(body!.SkippedMissionCount, Is.EqualTo(1));
|
||||
|
||||
using var scope = factory.Services.CreateScope();
|
||||
var verifyDb2 = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
|
||||
Assert.That(verifyDb2.ViewerMissions.Any(), Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ImportViewer_Missions_CatalogPresentButCounterUnresolvable()
|
||||
{
|
||||
using var factory = new SVSimTestFactory();
|
||||
using (var seedScope = factory.Services.CreateScope())
|
||||
{
|
||||
var seedDb = seedScope.ServiceProvider.GetRequiredService<SVSimDbContext>();
|
||||
seedDb.MissionCatalog.Add(new MissionCatalogEntry
|
||||
{
|
||||
Id = 9002, LotType = 6,
|
||||
EventType = null /* unresolvable */, EventArg = null
|
||||
});
|
||||
await seedDb.SaveChangesAsync();
|
||||
}
|
||||
var client = factory.CreateClient();
|
||||
ulong steamId = 70000000000000004UL;
|
||||
|
||||
var resp = await client.PostAsJsonAsync("/admin/import_viewer", new ImportViewerRequest
|
||||
{
|
||||
SteamId = steamId,
|
||||
Missions = new List<ImportMission>
|
||||
{
|
||||
new() { MissionId = 9002, MissionStatus = 1, TotalCount = 5 }
|
||||
}
|
||||
});
|
||||
var body = await resp.Content.ReadFromJsonAsync<ImportViewerResponse>(JsonOptions);
|
||||
Assert.That(body!.SkippedMissionCount, Is.EqualTo(0));
|
||||
Assert.That(body.SkippedMissionCounterCount, Is.EqualTo(1));
|
||||
|
||||
using var scope = factory.Services.CreateScope();
|
||||
var verifyDb3 = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
|
||||
Assert.That(verifyDb3.ViewerMissions.Count(m => m.MissionCatalogId == 9002), Is.EqualTo(1));
|
||||
Assert.That(verifyDb3.ViewerEventCounters.Any(), Is.False);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user