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
{
private const string RisingTide = "/Lotus/Types/Keys/RailJackBuildQuest/RailjackBuildQuestKeyChain";
private const string RailjackShip = "/Lotus/Types/Game/CrewShip/Ships/RailJack";
private const string RailjackCephalon = "/Lotus/Types/Items/ShipFeatureItems/RailjackCephalonShipFeatureItem";
private const string RailjackKey = "/Lotus/Types/Items/ShipFeatureItems/RailjackKeyShipFeatureItem";
[Fact]
public async Task CompletedRisingTideImportRestoresActivationWithoutChangingOwnedEquipmentOrSpareParts()
{
var q = await LoginAugustClient();
var imported = RailjackSave();
await Import(q, imported);
var restored = JObject.Parse((await Call($"/control/v1/accounts/{q["accountId"]}/export", admin: true)).Body);
AssertRailjackReady(restored["Ship"]!);
foreach (var field in new[] { "CrewShips", "CrewShipHarnesses", "CrewShipWeapons", "QuestKeys", "ActiveQuest", "MiscItems", "RegularCredits" })
Assert.True(JToken.DeepEquals(imported[field], restored[field]), field);
Assert.True(JToken.DeepEquals(imported["Ship"]!["Rooms"], restored["Ship"]!["Rooms"]));
Assert.Equal("LISET", restored["Ship"]!.Value<string>("BootLocation"));
await Import(q, imported);
var repeated = JObject.Parse((await Call($"/control/v1/accounts/{q["accountId"]}/export", admin: true)).Body);
Assert.True(JToken.DeepEquals(restored, repeated));
}
[Fact]
public async Task GameQuestCompletionSuppliesShipHarnessAndActivationOnce()
{
var q = await LoginAugustClient();
await Import(q, new { QuestKeys = new[] { new { ItemType = RisingTide, Completed = false, Progress = new object[0] } }, ActiveQuest = RisingTide });
var quest = new JObject {
["ItemType"] = RisingTide, ["Completed"] = true,
["Progress"] = new JArray(GameData.Find("Keys", RisingTide)!["chainStages"]!.Select(_ => new JObject { ["c"] = 0, ["i"] = true, ["m"] = true, ["b"] = new JArray() })) };
var result = await Call("/api/updateQuest.php", new { QuestKeys = new JArray(quest) }, q);
Assert.True(result.Status == 200, result.Body);
var changes = JObject.Parse(result.Body)["InventoryChanges"]!;
Assert.Single(changes["CrewShips"]!);
Assert.Single(changes["CrewShipHarnesses"]!);
var ship = JObject.Parse((await Call("/api/getShip.php", query: q)).Body);
AssertRailjackReady(ship["Ship"]!);
var inventory = await InventoryOf(q);
Assert.Single(inventory["CrewShips"]!);
Assert.Single(inventory["CrewShipHarnesses"]!);
Assert.Equal("", inventory.Value<string>("ActiveQuest"));
var date = inventory["QuestKeys"]![0]!["CompletionDate"]!.DeepClone();
result = await Call("/api/updateQuest.php", new { QuestKeys = new JArray(quest) }, q);
Assert.Equal(200, result.Status);
Assert.Empty(JObject.Parse(result.Body)["InventoryChanges"]!);
Assert.True(JToken.DeepEquals(date, (await InventoryOf(q))["QuestKeys"]![0]!["CompletionDate"]));
Assert.True(JToken.DeepEquals(inventory, await InventoryOf(q)));
}
[Theory]
[InlineData(false, false)]
[InlineData(false, true)]
[InlineData(true, false)]
public async Task UnfinishedQuestOrMissingOwnedShipDoesNotActivateRailjack(bool completed, bool owned)
{
var q = await LoginAugustClient();
var imported = RailjackSave();
imported["QuestKeys"]![0]!["Completed"] = completed;
if (!owned) imported["CrewShips"] = new JArray();
await Import(q, imported);
await InventoryOf(q);
var ship = JObject.Parse((await Call("/api/getShip.php", query: q)).Body)["Ship"]!;
Assert.DoesNotContain(RailjackCephalon, ship["Features"]!.Values<string>());
Assert.DoesNotContain(RailjackKey, ship["Features"]!.Values<string>());
}
[Theory]
[InlineData(true)]
[InlineData(false)]
public async Task ExistingCompletedSaveIsRepairedWhicheverGameReadComesFirst(bool inventoryFirst)
{
var q = await LoginAugustClient();
var imported = RailjackSave();
// Simulate an existing on-disk account, bypassing the repaired import path.
await store.Update(s => {
var account = s.Obj("accounts").Obj(q["accountId"]);
account["Inventory"] = imported.DeepClone();
account.Obj("Inventory").Remove("Ship");
account.Obj("PersonalRooms")["Ship"] = imported["Ship"]!.DeepClone();
return true;
});
var first = await Call(inventoryFirst ? "/api/inventory.php" : "/api/getShip.php", query: q);
Assert.Equal(200, first.Status);
var repaired = await store.Read(s => Inventory.Export(s.Obj("accounts").Obj(q["accountId"])));
AssertRailjackReady(repaired["Ship"]!);
foreach (var field in new[] { "CrewShips", "CrewShipHarnesses", "CrewShipWeapons", "QuestKeys", "MiscItems", "ActiveQuest", "RegularCredits" })
Assert.True(JToken.DeepEquals(imported[field], repaired[field]), field);
await store.DisposeAsync(); store = new(root); engine = new(store, options);
var afterRestart = JObject.Parse((await Call("/api/getShip.php", query: q)).Body);
AssertRailjackReady(afterRestart["Ship"]!);
Assert.Single((await InventoryOf(q))["CrewShips"]!);
}
[Fact]
public async Task CompletingAnAlreadyCompletedQuestRepairsFeaturesAndReportsChangeOnlyOnce()
{
var q = await LoginAugustClient();
await Import(q, RailjackSave());
var before = await store.Update(s => {
var account = s.Obj("accounts").Obj(q["accountId"]);
account.Obj("PersonalRooms").Obj("Ship")["Features"] = new JArray();
return account.Obj("Inventory").DeepClone();
});
var quest = new QuestApi(new ItemCatalog(), TimeProvider.System);
Assert.True(await store.Update(s => quest.Manage(s.Obj("accounts").Obj(q["accountId"]), "completeKey", RisingTide)));
Assert.False(await store.Update(s => quest.Manage(s.Obj("accounts").Obj(q["accountId"]), "completeKey", RisingTide)));
var accountAfter = await store.Read(s => s.Obj("accounts").Obj(q["accountId"]));
AssertRailjackReady(accountAfter["PersonalRooms"]!["Ship"]!);
Assert.True(JToken.DeepEquals(before, accountAfter["Inventory"]));
Assert.Empty(accountAfter["QuestClaims"] ?? new JArray());
Assert.Empty(accountAfter["Inbox"]!);
}
private static JObject RailjackSave() => new() {
["QuestKeys"] = new JArray(new JObject { ["ItemType"] = RisingTide, ["Completed"] = true, ["Progress"] = new JArray(), ["CompletionDate"] = Wire.Date(1768720279447) }),
["CrewShips"] = new JArray(new JObject { ["ItemId"] = Wire.Oid("5e7f4da5453bd66d53227303"), ["ItemType"] = RailjackShip, ["ItemName"] = "Imported Railjack", ["Features"] = 99,
["Configs"] = new JArray(new JObject { ["Skins"] = new JArray("", "test-skin"), ["pricol"] = new JObject { ["t0"] = -16777216 } }),
["Weapon"] = new JObject { ["PILOT"] = new JObject { ["PRIMARY_A"] = new JObject { ["ItemId"] = Wire.Oid("68d93c7889ca50f9d53394fe"), ["mod"] = 1, ["cus"] = 0 } } },
["CrewMembers"] = new JObject { ["SLOT_A"] = new JObject { ["ItemId"] = Wire.Oid("696db0573f3dc3a021047efd") } } }),
["CrewShipHarnesses"] = new JArray(new JObject { ["ItemId"] = Wire.Oid("6067e345c6b1243aab220f2f"), ["ItemType"] = "/Lotus/Types/Game/CrewShip/RailJack/DefaultHarness", ["XP"] = 3401,
["Configs"] = new JArray(new JObject { ["Upgrades"] = new JArray("5e8441c4069715534a2d8724") }) }),
["CrewShipWeapons"] = new JArray(new JObject { ["ItemId"] = Wire.Oid("68d93c7889ca50f9d53394fe"), ["ItemType"] = "/Lotus/Weapons/CrewShip/Laser/Beam/ZektiRailJackBeamWeaponTierC" }),
["MiscItems"] = new JArray(new JObject { ["ItemType"] = RailjackCephalon, ["ItemCount"] = 2 }, new JObject { ["ItemType"] = RailjackKey, ["ItemCount"] = 1 }),
["ActiveQuest"] = "/Lotus/Types/Keys/BardQuest/BardQuestKeyChain", ["RegularCredits"] = 12345,
["Ship"] = new JObject { ["Features"] = new JArray("/Lotus/Types/Items/ShipFeatureItems/ArsenalFeatureItem"), ["BootLocation"] = "LISET",
["Rooms"] = new JArray(new JObject { ["Name"] = "BridgeRoom", ["MaxCapacity"] = 1599, ["PlacedDecos"] = new JArray(new JObject { ["Type"] = "/Lotus/Objects/Tenno/Props/Portrait" }) }) } };
private static void AssertRailjackReady(JToken ship)
{
var features = ship["Features"]!.Values<string>().ToArray();
Assert.Contains(RailjackCephalon, features);
Assert.Contains(RailjackKey, features);
foreach (var part in new[] { "Hull", "HoodBrace", "Hood", "NacelleLeft", "NacelleRight", "Tail" })
Assert.Contains($"/Lotus/Types/Items/ShipFeatureItems/Railjack/Railjack{part}FeatureItem", features);
Assert.Equal(features.Length, features.Distinct().Count());
}
}
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
{
private const string RisingTide = "/Lotus/Types/Keys/RailJackBuildQuest/RailjackBuildQuestKeyChain";
private const string RailjackShip = "/Lotus/Types/Game/CrewShip/Ships/RailJack";
private const string RailjackCephalon = "/Lotus/Types/Items/ShipFeatureItems/RailjackCephalonShipFeatureItem";
private const string RailjackKey = "/Lotus/Types/Items/ShipFeatureItems/RailjackKeyShipFeatureItem";
[Fact]
public async Task CompletedRisingTideImportRestoresActivationWithoutChangingOwnedEquipmentOrSpareParts()
{
var q = await LoginAugustClient();
var imported = RailjackSave();
await Import(q, imported);
var restored = JObject.Parse((await Call($"/control/v1/accounts/{q["accountId"]}/export", admin: true)).Body);
AssertRailjackReady(restored["Ship"]!);
foreach (var field in new[] { "CrewShips", "CrewShipHarnesses", "CrewShipWeapons", "QuestKeys", "ActiveQuest", "MiscItems", "RegularCredits" })
Assert.True(JToken.DeepEquals(imported[field], restored[field]), field);
Assert.True(JToken.DeepEquals(imported["Ship"]!["Rooms"], restored["Ship"]!["Rooms"]));
Assert.Equal("LISET", restored["Ship"]!.Value<string>("BootLocation"));
await Import(q, imported);
var repeated = JObject.Parse((await Call($"/control/v1/accounts/{q["accountId"]}/export", admin: true)).Body);
Assert.True(JToken.DeepEquals(restored, repeated));
}
[Fact]
public async Task GameQuestCompletionSuppliesShipHarnessAndActivationOnce()
{
var q = await LoginAugustClient();
await Import(q, new { QuestKeys = new[] { new { ItemType = RisingTide, Completed = false, Progress = new object[0] } }, ActiveQuest = RisingTide });
var quest = new JObject {
["ItemType"] = RisingTide, ["Completed"] = true,
["Progress"] = new JArray(GameData.Find("Keys", RisingTide)!["chainStages"]!.Select(_ => new JObject { ["c"] = 0, ["i"] = true, ["m"] = true, ["b"] = new JArray() })) };
var result = await Call("/api/updateQuest.php", new { QuestKeys = new JArray(quest) }, q);
Assert.True(result.Status == 200, result.Body);
var changes = JObject.Parse(result.Body)["InventoryChanges"]!;
Assert.Single(changes["CrewShips"]!);
Assert.Single(changes["CrewShipHarnesses"]!);
var ship = JObject.Parse((await Call("/api/getShip.php", query: q)).Body);
AssertRailjackReady(ship["Ship"]!);
var inventory = await InventoryOf(q);
Assert.Single(inventory["CrewShips"]!);
Assert.Single(inventory["CrewShipHarnesses"]!);
Assert.Equal("", inventory.Value<string>("ActiveQuest"));
var date = inventory["QuestKeys"]![0]!["CompletionDate"]!.DeepClone();
result = await Call("/api/updateQuest.php", new { QuestKeys = new JArray(quest) }, q);
Assert.Equal(200, result.Status);
Assert.Empty(JObject.Parse(result.Body)["InventoryChanges"]!);
Assert.True(JToken.DeepEquals(date, (await InventoryOf(q))["QuestKeys"]![0]!["CompletionDate"]));
Assert.True(JToken.DeepEquals(inventory, await InventoryOf(q)));
}
[Theory]
[InlineData(false, false)]
[InlineData(false, true)]
[InlineData(true, false)]
public async Task UnfinishedQuestOrMissingOwnedShipDoesNotActivateRailjack(bool completed, bool owned)
{
var q = await LoginAugustClient();
var imported = RailjackSave();
imported["QuestKeys"]![0]!["Completed"] = completed;
if (!owned) imported["CrewShips"] = new JArray();
await Import(q, imported);
await InventoryOf(q);
var ship = JObject.Parse((await Call("/api/getShip.php", query: q)).Body)["Ship"]!;
Assert.DoesNotContain(RailjackCephalon, ship["Features"]!.Values<string>());
Assert.DoesNotContain(RailjackKey, ship["Features"]!.Values<string>());
}
[Theory]
[InlineData(true)]
[InlineData(false)]
public async Task ExistingCompletedSaveIsRepairedWhicheverGameReadComesFirst(bool inventoryFirst)
{
var q = await LoginAugustClient();
var imported = RailjackSave();
// Simulate an existing on-disk account, bypassing the repaired import path.
await store.Update(s => {
var account = s.Obj("accounts").Obj(q["accountId"]);
account["Inventory"] = imported.DeepClone();
account.Obj("Inventory").Remove("Ship");
account.Obj("PersonalRooms")["Ship"] = imported["Ship"]!.DeepClone();
return true;
});
var first = await Call(inventoryFirst ? "/api/inventory.php" : "/api/getShip.php", query: q);
Assert.Equal(200, first.Status);
var repaired = await store.Read(s => Inventory.Export(s.Obj("accounts").Obj(q["accountId"])));
AssertRailjackReady(repaired["Ship"]!);
foreach (var field in new[] { "CrewShips", "CrewShipHarnesses", "CrewShipWeapons", "QuestKeys", "MiscItems", "ActiveQuest", "RegularCredits" })
Assert.True(JToken.DeepEquals(imported[field], repaired[field]), field);
await store.DisposeAsync(); store = new(root); engine = new(store, options);
var afterRestart = JObject.Parse((await Call("/api/getShip.php", query: q)).Body);
AssertRailjackReady(afterRestart["Ship"]!);
Assert.Single((await InventoryOf(q))["CrewShips"]!);
}
[Fact]
public async Task CompletingAnAlreadyCompletedQuestRepairsFeaturesAndReportsChangeOnlyOnce()
{
var q = await LoginAugustClient();
await Import(q, RailjackSave());
var before = await store.Update(s => {
var account = s.Obj("accounts").Obj(q["accountId"]);
account.Obj("PersonalRooms").Obj("Ship")["Features"] = new JArray();
return account.Obj("Inventory").DeepClone();
});
var quest = new QuestApi(new ItemCatalog(), TimeProvider.System);
Assert.True(await store.Update(s => quest.Manage(s.Obj("accounts").Obj(q["accountId"]), "completeKey", RisingTide)));
Assert.False(await store.Update(s => quest.Manage(s.Obj("accounts").Obj(q["accountId"]), "completeKey", RisingTide)));
var accountAfter = await store.Read(s => s.Obj("accounts").Obj(q["accountId"]));
AssertRailjackReady(accountAfter["PersonalRooms"]!["Ship"]!);
Assert.True(JToken.DeepEquals(before, accountAfter["Inventory"]));
Assert.Empty(accountAfter["QuestClaims"] ?? new JArray());
Assert.Empty(accountAfter["Inbox"]!);
}
private static JObject RailjackSave() => new() {
["QuestKeys"] = new JArray(new JObject { ["ItemType"] = RisingTide, ["Completed"] = true, ["Progress"] = new JArray(), ["CompletionDate"] = Wire.Date(1768720279447) }),
["CrewShips"] = new JArray(new JObject { ["ItemId"] = Wire.Oid("5e7f4da5453bd66d53227303"), ["ItemType"] = RailjackShip, ["ItemName"] = "Imported Railjack", ["Features"] = 99,
["Configs"] = new JArray(new JObject { ["Skins"] = new JArray("", "test-skin"), ["pricol"] = new JObject { ["t0"] = -16777216 } }),
["Weapon"] = new JObject { ["PILOT"] = new JObject { ["PRIMARY_A"] = new JObject { ["ItemId"] = Wire.Oid("68d93c7889ca50f9d53394fe"), ["mod"] = 1, ["cus"] = 0 } } },
["CrewMembers"] = new JObject { ["SLOT_A"] = new JObject { ["ItemId"] = Wire.Oid("696db0573f3dc3a021047efd") } } }),
["CrewShipHarnesses"] = new JArray(new JObject { ["ItemId"] = Wire.Oid("6067e345c6b1243aab220f2f"), ["ItemType"] = "/Lotus/Types/Game/CrewShip/RailJack/DefaultHarness", ["XP"] = 3401,
["Configs"] = new JArray(new JObject { ["Upgrades"] = new JArray("5e8441c4069715534a2d8724") }) }),
["CrewShipWeapons"] = new JArray(new JObject { ["ItemId"] = Wire.Oid("68d93c7889ca50f9d53394fe"), ["ItemType"] = "/Lotus/Weapons/CrewShip/Laser/Beam/ZektiRailJackBeamWeaponTierC" }),
["MiscItems"] = new JArray(new JObject { ["ItemType"] = RailjackCephalon, ["ItemCount"] = 2 }, new JObject { ["ItemType"] = RailjackKey, ["ItemCount"] = 1 }),
["ActiveQuest"] = "/Lotus/Types/Keys/BardQuest/BardQuestKeyChain", ["RegularCredits"] = 12345,
["Ship"] = new JObject { ["Features"] = new JArray("/Lotus/Types/Items/ShipFeatureItems/ArsenalFeatureItem"), ["BootLocation"] = "LISET",
["Rooms"] = new JArray(new JObject { ["Name"] = "BridgeRoom", ["MaxCapacity"] = 1599, ["PlacedDecos"] = new JArray(new JObject { ["Type"] = "/Lotus/Objects/Tenno/Props/Portrait" }) }) } };
private static void AssertRailjackReady(JToken ship)
{
var features = ship["Features"]!.Values<string>().ToArray();
Assert.Contains(RailjackCephalon, features);
Assert.Contains(RailjackKey, features);
foreach (var part in new[] { "Hull", "HoodBrace", "Hood", "NacelleLeft", "NacelleRight", "Tail" })
Assert.Contains($"/Lotus/Types/Items/ShipFeatureItems/Railjack/Railjack{part}FeatureItem", features);
Assert.Equal(features.Length, features.Distinct().Count());
}
}