using Newtonsoft.Json.Linq; using XFEWarframe.Core; using XFEWarframe.Core.Data; using XFEWarframe.Core.Services; using Xunit; namespace XFEWarframe.Tests; public sealed partial class EngineTests { [Fact] public async Task GiftUsesServerPriceAndPaidPlatinumAndConcurrentClaimGrantsOnce() { var sender = await Login(); var recipient = await Login("recipient@test.local"); const string type = "/Lotus/Types/Items/MiscItems/OrokinReactor"; var price = GameData.Find("Resources", type)!.Value("platinumCost"); await Give(recipient, "/Lotus/Powersuits/Excalibur/Excalibur"); await Import(sender, new { PlayerLevel = 5, PremiumCredits = price * 2 + 50, PremiumCreditsFree = 50, GiftsRemaining = 5 }); var request = new JObject { ["PurchaseParams"] = new JObject { ["Source"] = 0, ["UsePremium"] = true, ["StoreItem"] = GameData.StoreType(type), ["Quantity"] = 2, ["ExpectedPrice"] = 1 }, ["RecipientId"] = Wire.Oid(recipient["accountId"]) }; var before = await InventoryOf(sender); Assert.Equal(409, (await Call("/api/gifting.php", request, sender)).Status); Assert.True(JToken.DeepEquals(before, await InventoryOf(sender))); request["PurchaseParams"]!["ExpectedPrice"] = price * 2; var sent = await Call("/api/gifting.php", request, sender); Assert.True(sent.Status == 200, sent.Body); var after = await InventoryOf(sender); Assert.Equal(50, after.Value("PremiumCredits")); Assert.Equal(50, after.Value("PremiumCreditsFree")); Assert.Equal(4, after.Value("GiftsRemaining")); Assert.Equal(0, Count(await InventoryOf(recipient), "MiscItems", type)); var inbox = JObject.Parse((await Call("/api/inbox.php", query: recipient)).Body)["Inbox"]!; var gift = inbox.First(x => x["gifts"] is JArray); var query = new Dictionary(recipient) { ["messageId"] = Wire.Id(gift["messageId"]) }; var reads = await Task.WhenAll(Enumerable.Range(0, 5).Select(_ => Call("/api/inbox.php", query: query))); Assert.All(reads, x => Assert.Equal(200, x.Status)); Assert.Single(reads, x => x.Body.Contains("InventoryChanges", StringComparison.Ordinal)); Assert.Equal(2, Count(await InventoryOf(recipient), "MiscItems", type)); var acknowledgements = JObject.Parse((await Call("/api/inbox.php", query: sender)).Body)["Inbox"]!.Where(x => x.Value("sub") == "/Lotus/Language/Menu/GiftReceivedConfirmationSubject"); Assert.Single(acknowledgements); Assert.Equal(400, (await Call("/api/gifting.php", request, sender)).Status); Assert.Equal(4, (await InventoryOf(sender)).Value("GiftsRemaining")); } [Fact] public async Task HelminthFoodHasServerSideAppetiteAndInsufficientBatchRollsBack() { var time = new TestClock(new DateTimeOffset(2026, 9, 24, 12, 0, 0, TimeSpan.Zero)); engine = new(store, options, time); var q = await Login(); var food = GameData.Table("Resources").Properties().First(x => x.Value["helminthSnack"] is JObject snack && snack.Value("gain") == .3 && HelminthApi.Resources.Any(r => snack.Value("type") == HelminthApi.ResourcePrefix + r)); var snack = food.Value["helminthSnack"]!; await Import(q, new { MiscItems = new[] { new { ItemType = food.Name, ItemCount = snack.Value("count") * 2 } } }); var contribution = new { ItemType = food.Name, Date = 0 }; var query = new Dictionary(q) { ["mode"] = "c" }; var first = await Call("/api/infestedFoundry.php", new { ResourceContributions = new[] { contribution } }, query); Assert.True(first.Status == 200, first.Body); var before = await InventoryOf(q); Assert.Equal(300, before["InfestedFoundry"]!["Resources"]![0]!.Value("Count")); Assert.Equal(400, (await Call("/api/infestedFoundry.php", new { ResourceContributions = new[] { contribution, contribution } }, query)).Status); Assert.True(JToken.DeepEquals(before, await InventoryOf(q))); Assert.Equal(200, (await Call("/api/infestedFoundry.php", new { ResourceContributions = new[] { contribution } }, query)).Status); var after = await InventoryOf(q); Assert.Equal(450, after["InfestedFoundry"]!["Resources"]![0]!.Value("Count")); Assert.Equal(29970, after["InfestedFoundry"]!.Value("XP")); } [Fact] public async Task SubsumeCompletesAfterOneDayAndUnlockedAbilityConsumesNutrientsOnce() { var time = new TestClock(new DateTimeOffset(2026, 9, 24, 12, 0, 0, TimeSpan.Zero)); engine = new(store, options, time); var q = await Login(); const string recipeType = "/Lotus/Types/Recipes/AbilityOverrides/AlchemistVialBlueprint"; var recipe = GameData.Find("Recipes", recipeType)!; var nutrients = new JArray(HelminthApi.Resources.Select(x => new JObject { ["ItemType"] = HelminthApi.ResourcePrefix + x, ["Count"] = 1000 })); await Give(q, "/Lotus/Powersuits/Alchemist/Alchemist"); await Give(q, "/Lotus/Powersuits/Excalibur/Excalibur"); await Import(q, new { InfestedFoundry = new { Resources = nutrients, XP = 300000, Slots = 3 } }); var inv = await InventoryOf(q); var consumed = inv["Suits"]![0]!["ItemId"]!; var target = inv["Suits"]![1]!["ItemId"]!; var start = await Call("/api/infestedFoundry.php", new { SuitId = consumed, Recipe = recipeType }, new(q) { ["mode"] = "a" }); Assert.True(start.Status == 200, start.Body); Assert.Single((await InventoryOf(q))["Suits"]!); Assert.Equal(0, Count(await InventoryOf(q), "Recipes", recipeType)); var install = new { ItemCategory = "Suits", ItemId = target, Operations = new[] { new { OperationType = "UOT_ABILITY_OVERRIDE", UpgradeRequirement = recipe.Value("resultType"), PolarizeSlot = 1, PolarityRemap = new[] { new { Slot = 0 }, new { Slot = 1 } } } } }; Assert.Equal(403, (await Call("/api/upgrades.php", install, q)).Status); time.Now = time.Now.AddDays(1); var complete = await InventoryOf(q); Assert.Equal(1, Count(complete, "Recipes", recipeType)); Assert.Null(complete["InfestedFoundry"]!["LastConsumedSuit"]); var installed = await Call("/api/upgrades.php", install, q); Assert.True(installed.Status == 200, installed.Body); var after = await InventoryOf(q); Assert.Equal(recipe.Value("resultType"), after["Suits"]![0]!["Configs"]![1]!["AbilityOverride"]!.Value("Ability")); Assert.Equal(2, after["InfestedFoundry"]!.Value("Slots")); Assert.Equal(409, (await Call("/api/upgrades.php", install, q)).Status); Assert.True(JToken.DeepEquals(after, await InventoryOf(q))); Assert.Equal(409, (await Call("/api/infestedFoundry.php", new { }, new(q) { ["mode"] = "r" })).Status); } [Fact] public async Task ShardUninstallRequiresNutrientsAndCannotRefundTwice() { var q = await Login(); await Give(q, "/Lotus/Powersuits/Excalibur/Excalibur"); const string color = "ACC_RED_MYTHIC"; var shard = HelminthApi.Shard(color); await Give(q, shard); var suit = (await InventoryOf(q))["Suits"]![0]!["ItemId"]!; var install = new { SuitId = suit, Slot = 0, Color = color, UpgradeType = "/Lotus/Upgrades/Invigorations/ArchonCrystalUpgrades/ArchonCrystalUpgradeWarframeAbilityStrength" }; Assert.Equal(200, (await Call("/api/infestedFoundry.php", install, new(q) { ["mode"] = "s" })).Status); Assert.Equal(409, (await Call("/api/infestedFoundry.php", install, new(q) { ["mode"] = "s" })).Status); var remove = new { SuitId = suit, Slot = 0 }; Assert.Equal(400, (await Call("/api/infestedFoundry.php", remove, new(q) { ["mode"] = "x" })).Status); Assert.Equal(0, Count(await InventoryOf(q), "MiscItems", shard)); await Import(q, new { InfestedFoundry = new { Resources = new[] { new { ItemType = HelminthApi.ResourcePrefix + "Oxides", Count = 300 } } } }); var removed = await Call("/api/infestedFoundry.php", remove, new(q) { ["mode"] = "x" }); Assert.True(removed.Status == 200, removed.Body); Assert.Equal(1, Count(await InventoryOf(q), "MiscItems", shard)); Assert.Equal(409, (await Call("/api/infestedFoundry.php", remove, new(q) { ["mode"] = "x" })).Status); } }