XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEWarframe

【WinUI】基于Warframe游戏本体的公开服务器以及安装器

公开
关注 0 Fork 0 Star 0
UTF-8
using Newtonsoft.Json.Linq;
using XFEWarframe.Core;
using XFEWarframe.Core.Data;
using Xunit;

namespace XFEWarframe.Tests;

public sealed partial class EngineTests
{
    [Fact] public async Task InventoryPresentationExposesRarityFlawedImposterAndLegacyWithoutChangingIdentity()
    {
        var q = await Login();
        var catalog = new ItemCatalog().WithLanguage("en");
        var examples = new[]
        {
            (catalog.Entries.First(x => x.Meta.Value<bool>("isStarter")).Type, "starter"),
            (catalog.Entries.First(x => x.Meta.Value<bool>("isFrivolous")).Type, "frivolous"),
            (LegacyMods.All.Properties().First().Name, "u5mod")
        };
        foreach (var (type, reason) in examples)
        {
            var response = await Call("/control/v1/catalog", query: new() { ["q"] = type, ["lang"] = "en" }, admin: true);
            Assert.Equal(200, response.Status);
            var row = JObject.Parse(response.Body)["items"]!.Single(x => x.Value<string>("type") == type);
            Assert.Equal(reason, row["presentation"]!.Value<string>("badReason"));
            Assert.NotEmpty(row["presentation"]!.Value<string>("warning")!);
            if (reason == "u5mod") { Assert.Equal(5, row["presentation"]!.Value<int>("legacyVersion")); Assert.EndsWith("(U5)", row.Value<string>("name")); }
            else Assert.Contains(reason == "starter" ? "Flawed" : "Imposter", row.Value<string>("name"));
        }
        const string serration = "/Lotus/Upgrades/Mods/Rifle/WeaponDamageAmountMod";
        await Give(q, serration);
        var before = await RawInventory(q);
        var view = await ReadEditor(q, "RawUpgrades");
        var owned = view["items"]!.Single(x => x.Value<string>("type") == serration);
        Assert.Equal("UNCOMMON", owned["presentation"]!.Value<string>("rarity"));
        Assert.NotEmpty(owned["presentation"]!.Value<string>("rarityLabel")!);
        Assert.True(JToken.DeepEquals(before, await RawInventory(q)));
    }

    [Fact] public async Task QuestRowsMatchUpstreamFirstRunReplayStageCompletionAndActiveMarkers()
    {
        var q = await Login();
        const string type = "/Lotus/Types/Keys/VorsPrize/VorsPrizeQuestKey";
        foreach (var (progress, completed, expectedStage, expectedReplays) in new[]
        {
            (new JArray(), false, 0, 0),
            (new JArray(new JObject(), new JObject()), false, 2, 0),
            (new JArray(new JObject { ["c"] = 1 }, new JObject { ["c"] = 1 }, new JObject()), false, 1, 2),
            (new JArray(new JObject { ["c"] = 2 }, new JObject { ["c"] = 2 }), true, 1, 3)
        })
        {
            var patch = new JObject { ["ActiveQuest"] = type, ["QuestKeys"] = new JArray(new JObject { ["ItemType"] = type, ["Completed"] = completed, ["Progress"] = progress }) };
            Assert.Equal(200, (await Call($"/control/v1/accounts/{q["accountId"]}/import", new { inventory = patch }, admin: true)).Status);
            var before = await RawInventory(q);
            var view = await ReadEditor(q, "QuestKeys"); var summary = view["items"]![0]!["quest"]!;
            Assert.Equal(expectedStage, summary.Value<int>("stage")); Assert.Equal(expectedReplays, summary.Value<int>("replays"));
            Assert.Equal(completed, summary.Value<bool>("completed")); Assert.True(summary.Value<bool>("active"));
            Assert.True(JToken.DeepEquals(before, await RawInventory(q)));
        }
    }

    [Fact] public async Task PlayerCatalogAndInventoryKeepAnnotationsThroughPagedJsonContract()
    {
        var player = await RegisterPlayer(); var token = player.Value<string>("token");
        var q = await Login("portal@example.invalid", XFEWarframe.Core.Services.Accounts.GamePassword("PortalTest-123"));
        var type = new ItemCatalog().Entries.First(x => x.Meta.Value<bool>("isStarter")).Type;
        await Give(q, type);
        var response = await Portal("inventory", token: token, query: new() { ["lang"] = "en", ["q"] = type });
        Assert.Equal(200, response.Status); var row = JObject.Parse(response.Body)["items"]![0]!;
        Assert.Equal(type, row.Value<string>("type")); Assert.Contains("Flawed", row.Value<string>("tags"));
    }
}