using Newtonsoft.Json.Linq;
using XFEWarframe.Core;
using Xunit;
namespace XFEWarframe.Tests;
public sealed partial class EngineTests
{
private async Task<JObject> ReadEditor(Dictionary<string, string> account, string category = "Suits", string? item = null)
{
var query = new Dictionary<string, string> { ["category"] = category };
if (item is not null) query["item"] = item;
var response = await Call($"/control/v1/accounts/{account["accountId"]}/editor", query: query, admin: true);
Assert.True(response.Status == 200, response.Body); return JObject.Parse(response.Body);
}
private Task<ApiResponse> Edit(Dictionary<string, string> account, JObject view, string action, object? values = null, string? item = null) =>
Call($"/control/v1/accounts/{account["accountId"]}/editor", new { version = view.Value<string>("version"), category = view.Value<string>("category"), action, item, values = values ?? new { } }, admin: true);
[Fact] public async Task DesktopEditorRequiresAdminAndDoesNotRotateGameSession()
{
var q = await Login(); var before = await InventoryOf(q);
var path = $"/control/v1/accounts/{q["accountId"]}/editor";
Assert.Equal(401, (await Call(path, query: q)).Status);
var view = await ReadEditor(q, "settings");
Assert.Equal(200, (await Edit(q, view, "settings", new { spoofMasteryRank = -1 })).Status);
var after = await InventoryOf(q); // The same game nonce must remain valid.
Assert.Equal(-1, after.Value<int>("spoofMasteryRank"));
Assert.Equal(before.Value<long>("PremiumCredits"), after.Value<long>("PremiumCredits"));
}
[Fact] public async Task EditorRejectsStaleSnapshotAndRollsBackMixedInvalidSettings()
{
var q = await Login(); var view = await ReadEditor(q, "settings");
Assert.Equal(200, (await Edit(q, view, "settings", new { spoofMasteryRank = 20 })).Status);
Assert.Equal(409, (await Edit(q, view, "settings", new { spoofMasteryRank = 10 })).Status);
view = await ReadEditor(q, "settings");
Assert.Equal(400, (await Edit(q, view, "settings", new { spoofMasteryRank = 5, unknownCheat = true })).Status);
Assert.Equal(20, (await InventoryOf(q)).Value<int>("spoofMasteryRank"));
view = await ReadEditor(q, "settings");
Assert.Equal(400, (await Edit(q, view, "settings", new { spoofMasteryRank = -2 })).Status);
Assert.Equal(400, (await Edit(q, view, "settings", new { spoofMasteryRank = 1.5 })).Status);
}
[Fact] public async Task ExperienceEditorSetsTotalAndMaintainsEarnedMastery()
{
var q = await Login(); await Give(q, "/Lotus/Powersuits/Excalibur/Excalibur");
var view = await ReadEditor(q); var id = view["items"]![0]!.Value<string>("key")!;
Assert.Equal(200, (await Edit(q, view, "experience", new { xp = 3000 }, id)).Status);
view = await ReadEditor(q);
Assert.Equal(200, (await Edit(q, view, "experience", new { xp = 5000 }, id)).Status);
var inv = await InventoryOf(q); Assert.Equal(5000, inv["Suits"]![0]!.Value<long>("XP"));
view = await ReadEditor(q);
Assert.Equal(200, (await Edit(q, view, "experience", new { xp = 0 }, id)).Status);
inv = await InventoryOf(q); Assert.Equal(0, inv["Suits"]![0]!.Value<long>("XP"));
Assert.Equal(5000, inv["XPInfo"]!.First(x => x.Value<string>("ItemType") == "/Lotus/Powersuits/Excalibur/Excalibur").Value<long>("XP"));
}
[Fact] public async Task EditorCannotEditAnotherAccountsEquipmentOrUnsupportedConfig()
{
var a = await Login(); var b = await Login("editor-other@test.local"); await Give(a, "/Lotus/Powersuits/Excalibur/Excalibur");
var view = await ReadEditor(a); var id = view["items"]![0]!.Value<string>("key")!;
var other = await ReadEditor(b);
Assert.Equal(404, (await Edit(b, other, "rename", new { name = "stolen" }, id)).Status);
view = await ReadEditor(a, item: id);
var actions = view["actions"]!.Select(x => x.Value<string>("key")).ToArray();
Assert.Contains("ability.2", actions); Assert.DoesNotContain("ability.3", actions);
Assert.Equal(400, (await Edit(a, view, "ability.3", new { ability = "", slot = 0 }, id)).Status);
Assert.Equal(400, (await Edit(a, view, "shards.add", new { type = "/Lotus/Upgrades/Invalid", count = 1 }, id)).Status);
}
[Fact] public async Task EditorHidesForcedFeaturesAndRejectsTheirMutation()
{
var q = await Login(); await Give(q, "/Lotus/Powersuits/Excalibur/Excalibur");
var view = await ReadEditor(q, "settings");
Assert.Equal(200, (await Edit(q, view, "settings", new { unlockDoubleCapacityPotatoesEverywhere = true })).Status);
view = await ReadEditor(q); var id = view["items"]![0]!.Value<string>("key")!;
view = await ReadEditor(q, item: id);
var features = view["actions"]!.First(x => x.Value<string>("key") == "features")["fields"]!;
Assert.DoesNotContain(features, x => x.Value<string>("key") == "1");
Assert.Equal(400, (await Edit(q, view, "features", new JObject { ["1"] = false, ["2"] = false }, id)).Status);
}
[Fact] public async Task FocusUnlockIsFreeIdempotentAndTemplatesPreserveEquipment()
{
var q = await Login(); await Give(q, "/Lotus/Powersuits/Excalibur/Excalibur");
var view = await ReadEditor(q, "progress");
var response = await Edit(q, view, "unlock.focus"); Assert.True(response.Status == 200, response.Body);
var inv = await InventoryOf(q); Assert.Equal(5, inv["FocusUpgrades"]!.Count());
view = await ReadEditor(q, "progress");
Assert.Equal(200, (await Edit(q, view, "unlock.focus")).Status);
Assert.Equal(5, (await InventoryOf(q))["FocusUpgrades"]!.Count());
view = await ReadEditor(q, "templates"); Assert.Equal(9, view["actions"]!.Count());
Assert.Equal(200, (await Edit(q, view, "template.clearWishlist")).Status);
Assert.True(JToken.DeepEquals(inv["Suits"], (await InventoryOf(q))["Suits"]));
}
[Fact] public async Task UpgradeFromRawModConsumesOneAndPreservesRemainingStack()
{
var q = await Login(); const string type = "/Lotus/Upgrades/Mods/Rifle/WeaponDamageAmountMod";
await Give(q, type, 3); var view = await ReadEditor(q, "RawUpgrades", type);
var response = await Edit(q, view, "mod.rank", new { rank = 5 }, type); Assert.True(response.Status == 200, response.Body);
var inv = await InventoryOf(q); Assert.Equal(2, inv["RawUpgrades"]!.First(x => x.Value<string>("ItemType") == type).Value<int>("ItemCount"));
var mod = inv["Upgrades"]!.First(x => x.Value<string>("ItemType") == type);
Assert.Equal(5, JObject.Parse(mod.Value<string>("UpgradeFingerprint")!).Value<int>("lvl"));
}
}
using Newtonsoft.Json.Linq;
using XFEWarframe.Core;
using Xunit;
namespace XFEWarframe.Tests;
public sealed partial class EngineTests
{
private async Task<JObject> ReadEditor(Dictionary<string, string> account, string category = "Suits", string? item = null)
{
var query = new Dictionary<string, string> { ["category"] = category };
if (item is not null) query["item"] = item;
var response = await Call($"/control/v1/accounts/{account["accountId"]}/editor", query: query, admin: true);
Assert.True(response.Status == 200, response.Body); return JObject.Parse(response.Body);
}
private Task<ApiResponse> Edit(Dictionary<string, string> account, JObject view, string action, object? values = null, string? item = null) =>
Call($"/control/v1/accounts/{account["accountId"]}/editor", new { version = view.Value<string>("version"), category = view.Value<string>("category"), action, item, values = values ?? new { } }, admin: true);
[Fact] public async Task DesktopEditorRequiresAdminAndDoesNotRotateGameSession()
{
var q = await Login(); var before = await InventoryOf(q);
var path = $"/control/v1/accounts/{q["accountId"]}/editor";
Assert.Equal(401, (await Call(path, query: q)).Status);
var view = await ReadEditor(q, "settings");
Assert.Equal(200, (await Edit(q, view, "settings", new { spoofMasteryRank = -1 })).Status);
var after = await InventoryOf(q); // The same game nonce must remain valid.
Assert.Equal(-1, after.Value<int>("spoofMasteryRank"));
Assert.Equal(before.Value<long>("PremiumCredits"), after.Value<long>("PremiumCredits"));
}
[Fact] public async Task EditorRejectsStaleSnapshotAndRollsBackMixedInvalidSettings()
{
var q = await Login(); var view = await ReadEditor(q, "settings");
Assert.Equal(200, (await Edit(q, view, "settings", new { spoofMasteryRank = 20 })).Status);
Assert.Equal(409, (await Edit(q, view, "settings", new { spoofMasteryRank = 10 })).Status);
view = await ReadEditor(q, "settings");
Assert.Equal(400, (await Edit(q, view, "settings", new { spoofMasteryRank = 5, unknownCheat = true })).Status);
Assert.Equal(20, (await InventoryOf(q)).Value<int>("spoofMasteryRank"));
view = await ReadEditor(q, "settings");
Assert.Equal(400, (await Edit(q, view, "settings", new { spoofMasteryRank = -2 })).Status);
Assert.Equal(400, (await Edit(q, view, "settings", new { spoofMasteryRank = 1.5 })).Status);
}
[Fact] public async Task ExperienceEditorSetsTotalAndMaintainsEarnedMastery()
{
var q = await Login(); await Give(q, "/Lotus/Powersuits/Excalibur/Excalibur");
var view = await ReadEditor(q); var id = view["items"]![0]!.Value<string>("key")!;
Assert.Equal(200, (await Edit(q, view, "experience", new { xp = 3000 }, id)).Status);
view = await ReadEditor(q);
Assert.Equal(200, (await Edit(q, view, "experience", new { xp = 5000 }, id)).Status);
var inv = await InventoryOf(q); Assert.Equal(5000, inv["Suits"]![0]!.Value<long>("XP"));
view = await ReadEditor(q);
Assert.Equal(200, (await Edit(q, view, "experience", new { xp = 0 }, id)).Status);
inv = await InventoryOf(q); Assert.Equal(0, inv["Suits"]![0]!.Value<long>("XP"));
Assert.Equal(5000, inv["XPInfo"]!.First(x => x.Value<string>("ItemType") == "/Lotus/Powersuits/Excalibur/Excalibur").Value<long>("XP"));
}
[Fact] public async Task EditorCannotEditAnotherAccountsEquipmentOrUnsupportedConfig()
{
var a = await Login(); var b = await Login("editor-other@test.local"); await Give(a, "/Lotus/Powersuits/Excalibur/Excalibur");
var view = await ReadEditor(a); var id = view["items"]![0]!.Value<string>("key")!;
var other = await ReadEditor(b);
Assert.Equal(404, (await Edit(b, other, "rename", new { name = "stolen" }, id)).Status);
view = await ReadEditor(a, item: id);
var actions = view["actions"]!.Select(x => x.Value<string>("key")).ToArray();
Assert.Contains("ability.2", actions); Assert.DoesNotContain("ability.3", actions);
Assert.Equal(400, (await Edit(a, view, "ability.3", new { ability = "", slot = 0 }, id)).Status);
Assert.Equal(400, (await Edit(a, view, "shards.add", new { type = "/Lotus/Upgrades/Invalid", count = 1 }, id)).Status);
}
[Fact] public async Task EditorHidesForcedFeaturesAndRejectsTheirMutation()
{
var q = await Login(); await Give(q, "/Lotus/Powersuits/Excalibur/Excalibur");
var view = await ReadEditor(q, "settings");
Assert.Equal(200, (await Edit(q, view, "settings", new { unlockDoubleCapacityPotatoesEverywhere = true })).Status);
view = await ReadEditor(q); var id = view["items"]![0]!.Value<string>("key")!;
view = await ReadEditor(q, item: id);
var features = view["actions"]!.First(x => x.Value<string>("key") == "features")["fields"]!;
Assert.DoesNotContain(features, x => x.Value<string>("key") == "1");
Assert.Equal(400, (await Edit(q, view, "features", new JObject { ["1"] = false, ["2"] = false }, id)).Status);
}
[Fact] public async Task FocusUnlockIsFreeIdempotentAndTemplatesPreserveEquipment()
{
var q = await Login(); await Give(q, "/Lotus/Powersuits/Excalibur/Excalibur");
var view = await ReadEditor(q, "progress");
var response = await Edit(q, view, "unlock.focus"); Assert.True(response.Status == 200, response.Body);
var inv = await InventoryOf(q); Assert.Equal(5, inv["FocusUpgrades"]!.Count());
view = await ReadEditor(q, "progress");
Assert.Equal(200, (await Edit(q, view, "unlock.focus")).Status);
Assert.Equal(5, (await InventoryOf(q))["FocusUpgrades"]!.Count());
view = await ReadEditor(q, "templates"); Assert.Equal(9, view["actions"]!.Count());
Assert.Equal(200, (await Edit(q, view, "template.clearWishlist")).Status);
Assert.True(JToken.DeepEquals(inv["Suits"], (await InventoryOf(q))["Suits"]));
}
[Fact] public async Task UpgradeFromRawModConsumesOneAndPreservesRemainingStack()
{
var q = await Login(); const string type = "/Lotus/Upgrades/Mods/Rifle/WeaponDamageAmountMod";
await Give(q, type, 3); var view = await ReadEditor(q, "RawUpgrades", type);
var response = await Edit(q, view, "mod.rank", new { rank = 5 }, type); Assert.True(response.Status == 200, response.Body);
var inv = await InventoryOf(q); Assert.Equal(2, inv["RawUpgrades"]!.First(x => x.Value<string>("ItemType") == type).Value<int>("ItemCount"));
var mod = inv["Upgrades"]!.First(x => x.Value<string>("ItemType") == type);
Assert.Equal(5, JObject.Parse(mod.Value<string>("UpgradeFingerprint")!).Value<int>("lvl"));
}
}