fix(guild): friend_list returns bare array-at-root (matches GuildFriendListTask.Parse)

GuildFriendListTask.Parse() reads base.ResponseData[data][i] directly —
data must be a bare JSON array, not {friends:[...]}.  Delete the
GuildFriendListResponse wrapper DTO; promote GuildInviteCandidateDto to its
own file.  Controller now returns List<GuildInviteCandidateDto> so the
middleware wraps it as data:[…].  Update wire-shape and integration tests to
assert array-at-root.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-06-27 14:35:20 -04:00
parent f2b996a593
commit 484b51086a
4 changed files with 58 additions and 68 deletions

View File

@@ -157,56 +157,58 @@ public class GuildWireShape
}
[Test]
public void GuildFriendList_response_serializes_friends_array_with_is_join_guild()
public void GuildFriendList_response_is_bare_array_at_root_with_is_join_guild()
{
// GuildFriendListTask.Parse() iterates data[i] and reads jsonData2["is_join_guild"].ToBoolean()
// from each entry. The root wrapper is "friends" in our DTO.
var resp = new GuildFriendListResponse
// GuildFriendListTask.Parse() reads base.ResponseData["data"] and iterates with data[i] directly.
// data must be a bare JSON array — NOT an object with a "friends" key.
var list = new List<GuildInviteCandidateDto>
{
Friends = new()
new GuildInviteCandidateDto
{
new GuildInviteCandidateDto
{
ViewerId = 76_561_198_300_000_001L,
Name = "Friend1",
EmblemId = 100_000_000L,
CountryCode = "JP",
Rank = 1,
DegreeId = 0,
IsJoinGuild = false,
},
new GuildInviteCandidateDto
{
ViewerId = 76_561_198_300_000_002L,
Name = "Friend2",
EmblemId = 100_000_000L,
CountryCode = "",
Rank = 1,
DegreeId = 0,
IsJoinGuild = true,
},
}
ViewerId = 76_561_198_300_000_001L,
Name = "Friend1",
EmblemId = 100_000_000L,
CountryCode = "JP",
Rank = 1,
DegreeId = 0,
IsJoinGuild = false,
},
new GuildInviteCandidateDto
{
ViewerId = 76_561_198_300_000_002L,
Name = "Friend2",
EmblemId = 100_000_000L,
CountryCode = "",
Rank = 1,
DegreeId = 0,
IsJoinGuild = true,
},
};
var json = JsonSerializer.Serialize(resp, Opts);
var json = JsonSerializer.Serialize(list, Opts);
using var doc = JsonDocument.Parse(json);
var root = doc.RootElement;
Assert.That(root.TryGetProperty("friends", out var friends), Is.True, "response must have 'friends' key");
Assert.That(friends.ValueKind, Is.EqualTo(JsonValueKind.Array));
Assert.That(friends.GetArrayLength(), Is.EqualTo(2));
// Root must be an array directly — GuildFriendListTask reads data[i], not data["friends"][i].
Assert.That(root.ValueKind, Is.EqualTo(JsonValueKind.Array),
"friend_list data must be a bare array, not a wrapper object");
Assert.That(root.GetArrayLength(), Is.EqualTo(2));
// First entry: is_join_guild = false.
var first = friends[0];
var first = root[0];
Assert.That(first.TryGetProperty("is_join_guild", out var jg1), Is.True, "is_join_guild must be present");
Assert.That(jg1.GetBoolean(), Is.False);
// Second entry: is_join_guild = true.
var second = friends[1];
var second = root[1];
Assert.That(second.GetProperty("is_join_guild").GetBoolean(), Is.True);
// viewer_id must be stringified.
Assert.That(first.GetProperty("viewer_id").ValueKind, Is.EqualTo(JsonValueKind.String),
"viewer_id must be stringified in friend_list entries");
// No "friends" wrapper key must exist.
Assert.That(root.ValueKind, Is.Not.EqualTo(JsonValueKind.Object),
"root must not be an object — no 'friends' wrapper allowed");
}
[Test]