using Newtonsoft.Json.Linq; using XFEWarframe.Core; using XFEWarframe.Core.Services; using Xunit; namespace XFEWarframe.Tests; public sealed partial class EngineTests { [Fact] public async Task AuthorizedPlayerCanSaveEverySuitOperationOfferedToAdministrator() { var now = new DateTimeOffset(2026, 10, 1, 12, 0, 0, TimeSpan.Zero); engine = new(store, options, new TestClock(now)); var player = await RegisterPlayer(); var token = player.Value("token"); var q = await Login("portal@example.invalid", Accounts.GamePassword("PortalTest-123")); var other = await Login("other@example.invalid"); await Give(q, "/Lotus/Powersuits/Excalibur/Excalibur"); await Give(other, "/Lotus/Powersuits/Excalibur/Excalibur"); var otherBefore = (await InventoryOf(other))["Suits"]!.DeepClone(); var suits = (JArray)(await InventoryOf(q))["Suits"]!.DeepClone(); var item = Wire.Id(suits[0]!["ItemId"]); suits[0]!["ModSlotPurchases"] = 3; suits[0]!["Configs"] = new JArray(Enumerable.Range(0, 6).Select(i => new JObject { ["Name"] = "配装" + i, ["Upgrades"] = new JArray("keep-mod-" + i), ["Colors"] = new JObject { ["t0"] = 12345 } })); await Import(q, new JObject { ["Suits"] = suits }); var permissions = new JObject(); foreach (var key in new[] { "rename", "experience", "forma", "features", "remove", "shards", "umbra", "invigoration", "ability", "exalted" }) permissions[key] = true; await SetEditorPermissions(permissions); async Task ReadAsync() { var response = await Portal("editor", token: token, query: new() { ["category"] = "Suits", ["item"] = item }); Assert.True(response.Status == 200, response.Body); var view = JObject.Parse(response.Body); var admin = await ReadEditor(q, item: item); Assert.True(JToken.DeepEquals(admin["actions"], view["actions"]), "Player action fields and choices must match the administrator's."); return view; } async Task ApplyAsync(string action, object? values = null) { var view = await ReadAsync(); Assert.Contains(view["actions"]!, x => x.Value("key") == action); var result = await Portal("editor", new { version = view.Value("version"), category = "Suits", item, action, values = values ?? new { } }, token); Assert.True(result.Status == 200, action + ": " + result.Body); } async Task SuitAsync() => (await InventoryOf(q))["Suits"]![0]!; // The original game session must remain valid. await ApplyAsync("rename", new { name = "玩家战甲" }); Assert.Equal("玩家战甲", (await SuitAsync()).Value("ItemName")); await ApplyAsync("experience", new { xp = 2718 }); Assert.Equal(2718, (await SuitAsync()).Value("XP")); await ApplyAsync("max"); Assert.Equal(900000, (await SuitAsync()).Value("XP")); await ApplyAsync("forma", new { count = 5 }); Assert.Equal(5, (await SuitAsync()).Value("Polarized")); await ApplyAsync("features", new JObject { ["1"] = true, ["2"] = true }); Assert.Equal(3, (await SuitAsync()).Value("Features")); var initial = await ReadAsync(); var shard = initial["actions"]!.First(x => x.Value("key") == "shards.add")["fields"]![0]!["options"]![0]!.Value("value")!; await ApplyAsync("shards.add", new { type = shard, count = 3 }); Assert.Equal(3, (await SuitAsync())["ArchonCrystalUpgrades"]!.Count()); await ApplyAsync("umbra", EditorValues(initial, "umbra")); Assert.Equal(now.AddDays(1).ToUnixTimeMilliseconds(), Wire.DateMs((await SuitAsync())["UmbraDate"])); var invigoration = initial["actions"]!.First(x => x.Value("key") == "invigoration"); var invigorate = EditorValues(invigoration); foreach (var key in new[] { "offensive", "defensive" }) invigorate[key] = invigoration["fields"]!.First(x => x.Value("key") == key)["options"]![0]!["value"]!.DeepClone(); await ApplyAsync("invigoration", invigorate); Assert.Equal(now.AddDays(7).ToUnixTimeMilliseconds(), Wire.DateMs((await SuitAsync())["UpgradesExpiry"])); Assert.Equal(invigorate.Value("offensive"), (await SuitAsync()).Value("OffensiveUpgrade")); Assert.Equal(invigorate.Value("defensive"), (await SuitAsync()).Value("DefensiveUpgrade")); var ability = initial["actions"]!.First(x => x.Value("key") == "ability.0")["fields"]![0]!["options"]!.First(x => x.Value("value") != "").Value("value")!; for (var i = 0; i < 6; i++) { await ApplyAsync("ability." + i, new { ability, slot = i % 4 + 1 }); var config = (await SuitAsync())["Configs"]![i]!; Assert.Equal(ability, config["AbilityOverride"]!.Value("Ability")); Assert.Equal(i % 4, config["AbilityOverride"]!.Value("Index")); Assert.Equal("配装" + i, config.Value("Name")); Assert.Equal("keep-mod-" + i, config["Upgrades"]![0]!.ToString()); Assert.Equal(12345, config["Colors"]!.Value("t0")); } await ApplyAsync("shards.remove", new { type = shard }); Assert.Empty((await SuitAsync())["ArchonCrystalUpgrades"] ?? new JArray()); await ApplyAsync("umbra.remove"); Assert.Null((await SuitAsync())["UmbraDate"]); await ApplyAsync("invigoration.remove"); Assert.Null((await SuitAsync())["UpgradesExpiry"]); Assert.Null((await SuitAsync())["OffensiveUpgrade"]); Assert.Null((await SuitAsync())["DefensiveUpgrade"]); await ApplyAsync("remove"); Assert.Empty((await InventoryOf(q))["Suits"]!); Assert.True(JToken.DeepEquals(otherBefore, (await InventoryOf(other))["Suits"])); } }