101 lines
4.2 KiB
C#
101 lines
4.2 KiB
C#
using System.Net;
|
|
using System.Net.Http.Json;
|
|
using NeonSprawl.Server.Game.AbilityInput;
|
|
using Xunit;
|
|
|
|
namespace NeonSprawl.Server.Tests.Game.AbilityInput;
|
|
|
|
public sealed class HotbarLoadoutApiTests
|
|
{
|
|
[Fact]
|
|
public async Task GetHotbarLoadout_ShouldReturnEightSlots_WhenPlayerKnown()
|
|
{
|
|
await using var factory = new InMemoryWebApplicationFactory();
|
|
var client = factory.CreateClient();
|
|
|
|
var response = await client.GetAsync("/game/players/dev-local-1/hotbar-loadout");
|
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
|
|
|
var body = await response.Content.ReadFromJsonAsync<HotbarLoadoutResponse>();
|
|
Assert.NotNull(body);
|
|
Assert.Equal(HotbarLoadoutResponse.CurrentSchemaVersion, body!.SchemaVersion);
|
|
Assert.Equal(HotbarLoadoutResponse.SlotCountV1, body.SlotCount);
|
|
Assert.Equal(HotbarLoadoutResponse.SlotCountV1, body.Slots.Count);
|
|
Assert.All(body.Slots, slot => Assert.Null(slot.AbilityId));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task PostHotbarLoadout_ShouldPersistBindings_AndRoundTripInGet()
|
|
{
|
|
await using var factory = new InMemoryWebApplicationFactory();
|
|
var client = factory.CreateClient();
|
|
|
|
var post = await client.PostAsJsonAsync(
|
|
"/game/players/dev-local-1/hotbar-loadout",
|
|
new HotbarLoadoutUpdateRequest
|
|
{
|
|
SchemaVersion = HotbarLoadoutUpdateRequest.CurrentSchemaVersion,
|
|
Slots =
|
|
[
|
|
new HotbarSlotBindingJson { SlotIndex = 0, AbilityId = PrototypeAbilityRegistry.PrototypePulse },
|
|
new HotbarSlotBindingJson { SlotIndex = 3, AbilityId = PrototypeAbilityRegistry.PrototypeBurst },
|
|
],
|
|
});
|
|
Assert.Equal(HttpStatusCode.OK, post.StatusCode);
|
|
|
|
var postBody = await post.Content.ReadFromJsonAsync<HotbarLoadoutUpdateResponse>();
|
|
Assert.NotNull(postBody);
|
|
Assert.True(postBody!.Updated);
|
|
Assert.Null(postBody.ReasonCode);
|
|
Assert.Equal(PrototypeAbilityRegistry.PrototypePulse, postBody.Loadout.Slots[0].AbilityId);
|
|
Assert.Equal(PrototypeAbilityRegistry.PrototypeBurst, postBody.Loadout.Slots[3].AbilityId);
|
|
|
|
var get = await client.GetFromJsonAsync<HotbarLoadoutResponse>("/game/players/dev-local-1/hotbar-loadout");
|
|
Assert.NotNull(get);
|
|
Assert.Equal(PrototypeAbilityRegistry.PrototypePulse, get!.Slots[0].AbilityId);
|
|
Assert.Equal(PrototypeAbilityRegistry.PrototypeBurst, get.Slots[3].AbilityId);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task PostHotbarLoadout_ShouldDenyOutOfBounds_WithReasonCode()
|
|
{
|
|
await using var factory = new InMemoryWebApplicationFactory();
|
|
var client = factory.CreateClient();
|
|
|
|
var post = await client.PostAsJsonAsync(
|
|
"/game/players/dev-local-1/hotbar-loadout",
|
|
new HotbarLoadoutUpdateRequest
|
|
{
|
|
SchemaVersion = HotbarLoadoutUpdateRequest.CurrentSchemaVersion,
|
|
Slots = [new HotbarSlotBindingJson { SlotIndex = 8, AbilityId = PrototypeAbilityRegistry.PrototypePulse }],
|
|
});
|
|
Assert.Equal(HttpStatusCode.OK, post.StatusCode);
|
|
|
|
var body = await post.Content.ReadFromJsonAsync<HotbarLoadoutUpdateResponse>();
|
|
Assert.NotNull(body);
|
|
Assert.False(body!.Updated);
|
|
Assert.Equal(HotbarLoadoutApi.ReasonSlotOutOfBounds, body.ReasonCode);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task PostHotbarLoadout_ShouldDenyUnknownAbility_WithReasonCode()
|
|
{
|
|
await using var factory = new InMemoryWebApplicationFactory();
|
|
var client = factory.CreateClient();
|
|
|
|
var post = await client.PostAsJsonAsync(
|
|
"/game/players/dev-local-1/hotbar-loadout",
|
|
new HotbarLoadoutUpdateRequest
|
|
{
|
|
SchemaVersion = HotbarLoadoutUpdateRequest.CurrentSchemaVersion,
|
|
Slots = [new HotbarSlotBindingJson { SlotIndex = 2, AbilityId = "missing_ability" }],
|
|
});
|
|
Assert.Equal(HttpStatusCode.OK, post.StatusCode);
|
|
|
|
var body = await post.Content.ReadFromJsonAsync<HotbarLoadoutUpdateResponse>();
|
|
Assert.NotNull(body);
|
|
Assert.False(body!.Updated);
|
|
Assert.Equal(HotbarLoadoutApi.ReasonUnknownAbility, body.ReasonCode);
|
|
}
|
|
}
|