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 ModularCraftingConsumesOwnedPartsAndRejectsMissingIngredientsAtomically() { var q = await Login(); var offer = ModularApi.Sales(20720)[0]!["Weapons"]![0]!; var parts = offer["ModularParts"]!.Select(x => x.ToString()).ToArray(); await Import(q, new { RegularCredits = 8000 }); foreach (var part in parts.Take(2)) await Give(q, part); var body = new { WeaponType = offer.Value("ItemType"), Parts = parts }; var before = await InventoryOf(q); Assert.Equal(400, (await Call("/api/modularWeaponCrafting.php", body, q)).Status); Assert.True(JToken.DeepEquals(before, await InventoryOf(q))); await Give(q, parts[2]); var result = await Call("/api/modularWeaponCrafting.php", body, q); Assert.True(result.Status == 200, result.Body); var after = await InventoryOf(q); Assert.Equal(4000, after.Value("RegularCredits")); Assert.True(JToken.DeepEquals(offer["ModularParts"], after["Melee"]![0]!["ModularParts"])); Assert.All(parts, part => Assert.Equal(0, Count(after, "MiscItems", part))); } [Fact] public async Task PetStasisAndRenamingPreserveOtherCompanionsAndChargeOnce() { var q = await Login(); var first = Wire.NewId(); var second = Wire.NewId(); await Import(q, new { PremiumCredits = 15, KubrowPets = new[] { new { ItemId = Wire.Oid(first), ItemType = "/Lotus/Types/Friendly/Pets/KubrowPet", Details = new { Name = "First", Status = "STATUS_AVAILABLE" } }, new { ItemId = Wire.Oid(second), ItemType = "/Lotus/Types/Friendly/Pets/KubrowPet", Details = new { Name = "Second", Status = "STATUS_STASIS" } } } }); var result = await Call("/api/retrievePetFromStasis.php", new { petId = second }, q); Assert.True(result.Status == 200, result.Body); var pets = (await InventoryOf(q))["KubrowPets"]!; Assert.Equal("STATUS_STASIS", pets[0]!["Details"]!.Value("Status")); Assert.Equal("STATUS_AVAILABLE", pets[1]!["Details"]!.Value("Status")); Assert.Equal(200, (await Call("/api/sendPetToStasis.php", new { petId = second }, q)).Status); Assert.Equal(200, (await Call("/api/renamePet.php", new { petId = second, name = "New Name" }, q)).Status); Assert.Equal(400, (await Call("/api/renamePet.php", new { petId = second, name = "Cannot Afford" }, q)).Status); Assert.Equal("New Name", (await InventoryOf(q))["KubrowPets"]![1]!["Details"]!.Value("Name")); } [Fact] public async Task DecorationsMoveAndResetConserveInventoryAndRoomCapacity() { var q = await Login(); var entry = GameData.Table("Resources").Properties().First(x => x.Value.Value("productCategory") == "ShipDecorations" && x.Value["deco"] is not null && x.Value.Value("capacityCost") > 0); await Give(q, entry.Name); var type = entry.Value.Value("deco"); var cost = entry.Value.Value("capacityCost"); var placed = await Call("/api/shipDecorations.php", new { Type = type, Room = "BridgeRoom", Pos = new[] { 0, 0, 0 }, Rot = new[] { 0, 0, 0 } }, q); Assert.True(placed.Status == 200, placed.Body); var id = JObject.Parse(placed.Body).Value("DecoId"); Assert.Equal(0, Count(await InventoryOf(q), "ShipDecorations", entry.Name)); var response = await Call("/api/shipDecorations.php", new { Type = type, Room = "LisetRoom", OldRoom = "BridgeRoom", MoveId = id, Pos = new[] { 1, 2, 3 }, Rot = new[] { 0, 0, 0 } }, q); Assert.True(response.Status == 200, response.Body); var ship = JObject.Parse((await Call("/api/getShip.php", query: q)).Body); Assert.Equal(q["accountId"], ship.Value("ShipOwnerId")); Assert.Equal(1600, ship["Ship"]!["Rooms"]!.First(x => x.Value("Name") == "BridgeRoom").Value("MaxCapacity")); Assert.Equal(1000 - cost, ship["Ship"]!["Rooms"]!.First(x => x.Value("Name") == "LisetRoom").Value("MaxCapacity")); Assert.Equal(200, (await Call("/api/shipDecorations.php", new { Room = "LisetRoom" }, new(q) { ["reset"] = "1" })).Status); Assert.Equal(1, Count(await InventoryOf(q), "ShipDecorations", entry.Name)); Assert.Equal(404, (await Call("/api/shipDecorations.php", new { Type = type, Room = "LisetRoom", RemoveId = id }, q)).Status); Assert.Equal(1, Count(await InventoryOf(q), "ShipDecorations", entry.Name)); } [Fact] public async Task GardenRequiresMaturityAndCannotBeHarvestedTwice() { var time = new TestClock(new DateTimeOffset(2026, 9, 24, 12, 0, 0, TimeSpan.Zero)); engine = new(store, options, time); var q = await Login(); Assert.Equal(200, (await Call("/api/getShip.php", query: q)).Status); Assert.Equal(409, (await Call("/api/gardening.php", new { Mode = "HarvestAll" }, q)).Status); time.Now = time.Now.AddHours(22); var harvest = await Call("/api/gardening.php", new { Mode = "HarvestAll" }, q); Assert.True(harvest.Status == 200, harvest.Body); var changes = JObject.Parse(harvest.Body)["InventoryChanges"]!["MiscItems"]!; Assert.InRange(changes.Sum(x => x.Value("ItemCount")), 12, 24); var before = await InventoryOf(q); Assert.Equal(409, (await Call("/api/gardening.php", new { Mode = "HarvestAll" }, q)).Status); Assert.True(JToken.DeepEquals(before, await InventoryOf(q))); } [Fact] public async Task ExtractorResourcesAreRolledOnceAndCollectionCannotBeReplayed() { var time = new TestClock(new DateTimeOffset(2026, 9, 24, 12, 0, 0, TimeSpan.Zero)); engine = new(store, options, time); var q = await Login(); await Give(q, "/Lotus/Types/Ship/BasicResourceDrone"); await Import(q, new { noResourceExtractorDronesDamage = true }); var id = Wire.Id((await InventoryOf(q))["Drones"]![0]!["ItemId"]); var deploy = new Dictionary(q) { ["droneId"] = id, ["systemIndex"] = "1" }; Assert.Equal(200, (await Call("/api/drones.php", query: deploy)).Status); Assert.Equal(409, (await Call("/api/drones.php", query: deploy)).Status); var active = await Call("/api/drones.php", query: new(q) { ["GetActive"] = "1" }); Assert.True(active.Status == 200, active.Body); var resource = JObject.Parse(active.Body)["ActiveDrones"]![0]!["Resources"]![0]!; time.Now = time.Now.AddHours(4); var collect = new Dictionary(q) { ["collectDroneId"] = id }; Assert.Equal(200, (await Call("/api/drones.php", query: collect)).Status); Assert.Equal(resource.Value("BinTotal"), Count(await InventoryOf(q), "MiscItems", resource.Value("ItemType")!)); Assert.Equal(409, (await Call("/api/drones.php", query: collect)).Status); } [Fact] public async Task IdentifyingRailjackSalvageConsumesTheRawPartAndPersistsItsRoll() { var q = await Login(); var entry = GameData.Table("RailjackWeapons").Properties().First(x => x.Value["defaultUpgrades"] is JArray { Count: > 0 }); await Give(q, entry.Name); Assert.Equal(1, Count(await InventoryOf(q), "CrewShipRawSalvage", entry.Name)); var identify = await Call("/api/crewShipIdentifySalvage.php", new { ItemType = entry.Name }, q); Assert.True(identify.Status == 200, identify.Body); var after = await InventoryOf(q); Assert.Equal(0, Count(after, "CrewShipRawSalvage", entry.Name)); Assert.NotEmpty(JObject.Parse(after["CrewShipSalvagedWeapons"]![0]!.Value("UpgradeFingerprint")!)["buffs"]!); Assert.Equal(400, (await Call("/api/crewShipIdentifySalvage.php", new { ItemType = entry.Name }, q)).Status); Assert.True(JToken.DeepEquals(after, await InventoryOf(q))); } }