using Newtonsoft.Json.Linq; using XFEWarframe.Core; using XFEWarframe.Core.Services; using Xunit; namespace XFEWarframe.Tests; public sealed partial class EngineTests { private static JObject EditorValues(JToken action) => new(action["fields"]!.Select(f => new JProperty(f.Value("key")!, f["value"]!.DeepClone()))); [Fact] public async Task ModularEditorCreatesEveryFamilyAndRejectsMismatchedPartsAtomically() { var q = await Login(); foreach (var category in new[] { "LongGuns", "Pistols", "Melee", "OperatorAmps", "Hoverboards", "MoaPets", "KubrowPets" }) { var view = await ReadEditor(q, category); var actions = (JArray)view["actions"]!; Assert.NotEmpty(actions); foreach (var action in actions) { view = await ReadEditor(q, category); var response = await Edit(q, view, action.Value("key")!, EditorValues(action)); Assert.True(response.Status == 200, response.Body); } view = await ReadEditor(q, category); Assert.Equal(actions.Count, view.Value("total")); var id = view["items"]![0]!.Value("key")!; view = await ReadEditor(q, category, id); var parts = view["actions"]!.First(x => x.Value("key") == "parts"); var values = EditorValues(parts); var before = view.Value("version"); values.Properties().First().Value = "/Lotus/Types/Items/MiscItems/Forma"; Assert.Equal(400, (await Edit(q, view, "parts", values, id)).Status); Assert.Equal(before, (await ReadEditor(q, category, id)).Value("version")); Assert.Equal(200, (await Edit(q, view, "parts", EditorValues(parts), id)).Status); } } [Fact] public async Task ValenceEditorConvertsPercentagesAndRetainsOtherFingerprintData() { var q = await Login(); await Give(q, "/Lotus/Weapons/Tenno/Rifle/BurstRifle"); var inv = await InventoryOf(q); var id = Wire.Id(inv["LongGuns"]![0]!["ItemId"]); await store.Update(s => s.Obj("accounts")[q["accountId"]]!["Inventory"]!["LongGuns"]![0]!["UpgradeFingerprint"] = "{\"retained\":5}"); var view = await ReadEditor(q, "LongGuns", id); Assert.Equal(200, (await Edit(q, view, "valence", new { element = "InnateHeatDamage", percentage = 60 }, id)).Status); var fp = JObject.Parse((await InventoryOf(q))["LongGuns"]![0]!.Value("UpgradeFingerprint")!); Assert.Equal(RivenCalculator.Scale, fp["buffs"]![0]!.Value("Value")); Assert.Equal(5, fp.Value("retained")); view = await ReadEditor(q, "LongGuns", id); Assert.Equal(400, (await Edit(q, view, "valence", new { element = "InnateHeatDamage", percentage = 60.01 }, id)).Status); Assert.Equal(200, (await Edit(q, view, "valence", new { element = "", percentage = 25 }, id)).Status); Assert.Null((await InventoryOf(q))["LongGuns"]![0]!["UpgradeFingerprint"]); } [Fact] public async Task EditorCanRemoveStringCosmeticsWithoutDeletingOtherItems() { var q = await Login(); await Import(q, new { FlavourItems = new[] { "/Lotus/test/one", "/Lotus/test/two" } }); var view = await ReadEditor(q, "FlavourItems", "/Lotus/test/one"); Assert.Equal(2, view.Value("total")); Assert.Equal(200, (await Edit(q, view, "remove", item: "/Lotus/test/one")).Status); var items = (await InventoryOf(q))["FlavourItems"]!; Assert.Single(items); Assert.Equal("/Lotus/test/two", items[0]!.ToString()); } }