using System.Net; using System.Text; using System.Text.Json; using NUnit.Framework; using SVSim.UnitTests.Infrastructure; namespace SVSim.UnitTests.Controllers; public class GiftControllerTests { private const string BaseAuthBlock = @"""viewer_id"":""0"",""steam_id"":0,""steam_session_ticket"":"""""; [Test] public async Task GiftTop_returns_five_tutorial_gifts_for_unclaimed_viewer() { using var factory = new SVSimTestFactory(); long viewerId = await factory.SeedViewerAsync(tutorialState: 31); using var client = factory.CreateAuthenticatedClient(viewerId); var response = await client.PostAsync("/tutorial/gift_top", new StringContent($$"""{"page":1,{{BaseAuthBlock}}}""", Encoding.UTF8, "application/json")); Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK)); using var doc = JsonDocument.Parse(await response.Content.ReadAsStringAsync()); var root = doc.RootElement; var presents = root.GetProperty("present_list"); Assert.That(presents.GetArrayLength(), Is.EqualTo(5)); // Expect the legendary pack entry (present_id 71478630) to be present. bool foundLegendaryGift = false; foreach (var p in presents.EnumerateArray()) { if (p.GetProperty("present_id").GetString() == "71478630") { foundLegendaryGift = true; Assert.That(p.GetProperty("reward_type").GetString(), Is.EqualTo("4")); Assert.That(p.GetProperty("reward_detail_id").GetString(), Is.EqualTo("90001")); Assert.That(p.GetProperty("reward_count").GetString(), Is.EqualTo("1")); Assert.That(p.GetProperty("item_type").GetInt32(), Is.EqualTo(2)); Assert.That(p.GetProperty("message").GetString(), Is.EqualTo("For completing the tutorial")); } } Assert.That(foundLegendaryGift, Is.True, "Legendary starter pack gift (71478630) must be in present_list."); Assert.That(root.GetProperty("present_history_list").GetArrayLength(), Is.EqualTo(0)); Assert.That(root.GetProperty("limit_over_present_list").GetArrayLength(), Is.EqualTo(0)); } }