using Newtonsoft.Json.Linq; using XFEWarframe.Core.Services; using Xunit; namespace XFEWarframe.Tests; public sealed partial class EngineTests { [Fact] public async Task AddMissingQuestPreservesProgressRejectsDuplicatesAndSupportsNameAndPathSearch() { var account = await Login(); var before = (await InventoryOf(account))["QuestKeys"]!.DeepClone(); var view = await ReadEditor(account, "QuestKeys"); var create = view["creationActions"]!.Single(); Assert.Equal("create.quest", create.Value("key")); var option = create["fields"]![0]!["options"]!.First()!; var type = option.Value("value")!; var name = option.Value("label")!; var added = await Edit(account, view, "create.quest", new { type }); Assert.True(added.Status == 200, added.Body); var inventory = await InventoryOf(account); foreach (var existing in before) Assert.True(JToken.DeepEquals(existing, inventory["QuestKeys"]!.Single(x => x.Value("ItemType") == existing.Value("ItemType")))); var quest = inventory["QuestKeys"]!.Single(x => x.Value("ItemType") == type); Assert.False(quest.Value("Completed")); Assert.Empty(quest["Progress"] ?? new JArray()); var refreshed = await ReadEditor(account, "QuestKeys", type); Assert.DoesNotContain(refreshed["creationActions"]![0]!["fields"]![0]!["options"]!, x => x.Value("value") == type); Assert.Equal(400, (await Edit(account, refreshed, "create.quest", new { type })).Status); Assert.Equal(409, (await Edit(account, view, "create.quest", new { type })).Status); Assert.Equal(400, (await Edit(account, refreshed, "create.quest", new { type = "/Lotus/InvalidQuest" })).Status); foreach (var query in new[] { name, type, "no-such-quest-xyz" }) { var result = await Call($"/control/v1/accounts/{account["accountId"]}/editor", query: new() { ["category"] = "QuestKeys", ["q"] = query }, admin: true); Assert.Equal(200, result.Status); var search = JObject.Parse(result.Body); if (query.StartsWith("no-such", StringComparison.Ordinal)) Assert.Empty(search["items"]!); else Assert.Contains(search["items"]!, x => x.Value("key") == type); } Assert.True(JToken.DeepEquals(inventory, await InventoryOf(account))); } [Fact] public async Task MissingQuestCreationRequiresSpecificAndItemGrantPermissions() { var player = await RegisterPlayer(); var token = player.Value("token"); var account = await Login("portal@example.invalid", Accounts.GamePassword("PortalTest-123")); await SetEditorPermissions(new JObject { ["quest"] = true }); var category = new Dictionary { ["category"] = "QuestKeys" }; var view = JObject.Parse((await Portal("editor", token: token, query: category)).Body); Assert.Empty(view["creationActions"]!); var admin = await ReadEditor(account, "QuestKeys"); var type = admin["creationActions"]![0]!["fields"]![0]!["options"]![0]!.Value("value")!; object Body(JObject value) => new { version = value.Value("version"), category = "QuestKeys", action = "create.quest", values = new { type } }; Assert.Equal(403, (await Portal("editor", Body(view), token)).Status); await SetEditorPermissions(new JObject { ["create.quest"] = true }); await Call("/control/v1/config", new { allowPlayerItemGrant = false }, admin: true); view = JObject.Parse((await Portal("editor", token: token, query: category)).Body); Assert.Empty(view["creationActions"]!); Assert.Equal(403, (await Portal("editor", Body(view), token)).Status); await Call("/control/v1/config", new { allowPlayerItemGrant = true }, admin: true); view = JObject.Parse((await Portal("editor", token: token, query: category)).Body); Assert.Single(view["creationActions"]!); var response = await Portal("editor", Body(view), token); Assert.True(response.Status == 200, response.Body); Assert.Single((await InventoryOf(account))["QuestKeys"]!, x => x.Value("ItemType") == type); await SetEditorPermissions(new JObject { ["create.quest"] = false }); Assert.Equal(403, (await Portal("editor", Body(view), token)).Status); } }