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:
@@ -163,8 +163,9 @@ public class GuildChangeRoleFriendListFlowTests
|
||||
// ─── /guild/friend_list ───────────────────────────────────────────────────────
|
||||
|
||||
[Test]
|
||||
public async Task FriendList_returns_friends_array_with_is_join_guild_field()
|
||||
public async Task FriendList_returns_bare_array_with_is_join_guild_field()
|
||||
{
|
||||
// GuildFriendListTask.Parse() reads base.ResponseData["data"][i] directly — data is a bare array.
|
||||
using var factory = new SVSimTestFactory();
|
||||
long viewerA = await factory.SeedViewerAsync(76_561_198_500_000_005UL, "CrfViewerA");
|
||||
long viewerB = await factory.SeedViewerAsync(76_561_198_500_000_006UL, "CrfViewerB");
|
||||
@@ -186,16 +187,12 @@ public class GuildChangeRoleFriendListFlowTests
|
||||
using var doc = JsonDocument.Parse(body);
|
||||
var root = doc.RootElement;
|
||||
|
||||
if (root.TryGetProperty("result_code", out var rc))
|
||||
Assert.That(rc.GetInt32(), Is.Not.EqualTo(2), $"friend_list returned error: {body}");
|
||||
// Response must be a bare JSON array at root — NOT an object with a "friends" key.
|
||||
Assert.That(root.ValueKind, Is.EqualTo(JsonValueKind.Array),
|
||||
$"friend_list data must be a bare array at root: {body}");
|
||||
Assert.That(root.GetArrayLength(), Is.EqualTo(1), "viewerA has 1 friend");
|
||||
|
||||
// Response must have "friends" array.
|
||||
Assert.That(root.TryGetProperty("friends", out var friends), Is.True,
|
||||
$"response must have 'friends' key: {body}");
|
||||
Assert.That(friends.ValueKind, Is.EqualTo(JsonValueKind.Array));
|
||||
Assert.That(friends.GetArrayLength(), Is.EqualTo(1), "viewerA has 1 friend");
|
||||
|
||||
var friend = friends[0];
|
||||
var friend = root[0];
|
||||
Assert.That(GetStringifiedLong(friend, "viewer_id"), Is.EqualTo(viewerB));
|
||||
|
||||
// is_join_guild must be present — viewerB has no guild, so false.
|
||||
@@ -237,10 +234,13 @@ public class GuildChangeRoleFriendListFlowTests
|
||||
Assert.That(resp.IsSuccessStatusCode, Is.True);
|
||||
|
||||
using var doc = JsonDocument.Parse(body);
|
||||
var friends = doc.RootElement.GetProperty("friends");
|
||||
Assert.That(friends.GetArrayLength(), Is.EqualTo(1));
|
||||
// Response is a bare array — GuildFriendListTask reads data[i] directly.
|
||||
var arr = doc.RootElement;
|
||||
Assert.That(arr.ValueKind, Is.EqualTo(JsonValueKind.Array),
|
||||
$"friend_list data must be a bare array at root: {body}");
|
||||
Assert.That(arr.GetArrayLength(), Is.EqualTo(1));
|
||||
|
||||
var friend = friends[0];
|
||||
var friend = arr[0];
|
||||
Assert.That(friend.GetProperty("is_join_guild").GetBoolean(), Is.True,
|
||||
"viewerB is in a guild so is_join_guild must be true");
|
||||
}
|
||||
@@ -257,10 +257,10 @@ public class GuildChangeRoleFriendListFlowTests
|
||||
Assert.That(resp.IsSuccessStatusCode, Is.True);
|
||||
|
||||
using var doc = JsonDocument.Parse(body);
|
||||
if (doc.RootElement.TryGetProperty("result_code", out var rc))
|
||||
Assert.That(rc.GetInt32(), Is.Not.EqualTo(2), $"friend_list error: {body}");
|
||||
|
||||
Assert.That(doc.RootElement.TryGetProperty("friends", out var friends), Is.True);
|
||||
Assert.That(friends.GetArrayLength(), Is.EqualTo(0), "No friends means empty array");
|
||||
// Response is a bare array at root — no wrapper object.
|
||||
var root = doc.RootElement;
|
||||
Assert.That(root.ValueKind, Is.EqualTo(JsonValueKind.Array),
|
||||
$"friend_list must return a bare array even when empty: {body}");
|
||||
Assert.That(root.GetArrayLength(), Is.EqualTo(0), "No friends means empty array");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user