feat(guild): change_role atomic transfer + friend_list
- ChangeRoleAsync: Leader-only role management with SubLeader cap check. Atomic leader transfer loads both member rows + Guild.LeaderViewerId in one _db.SaveChangesAsync call (no split saves). Emits ChangeLeader (6) or ChangeSubLeader (7) chat events. Same-role is no-op / returns Ok. - /guild/change_role controller: calls ChangeRoleAsync, returns full updated member list (GuildChangeRoleResponse.Members[]). - /guild/friend_list controller: calls IFriendService.GetFriendsAsync, then annotates each friend with is_join_guild from Viewer.GuildId column. - IGuildRepository.UpdateLeaderViewerIdAsync: added for completeness even though the atomic transfer path bypasses it via direct EF mutation. - Tests: 8 GuildServiceChangeRoleTests (role changes, cap, atomic transfer, no-op, permission); 3 GuildChangeRoleFriendListFlowTests (HTTP roundtrip, is_join_guild); 2 GuildWireShape tests (literal JSON shape); 1508 pass. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@ using NUnit.Framework;
|
||||
using System.Text.Json;
|
||||
using SVSim.EmulatedEntrypoint.Models.Dtos.Common.Guild;
|
||||
using SVSim.EmulatedEntrypoint.Models.Dtos.Guild;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace SVSim.UnitTests.Wire;
|
||||
|
||||
@@ -99,6 +100,115 @@ public class GuildWireShape
|
||||
Assert.That(arr[0].TryGetProperty("detail", out _), Is.False, "search list entries are flat, no detail wrapper");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GuildChangeRole_response_serializes_members_array_with_role_and_stringified_ids()
|
||||
{
|
||||
// GuildChangeRoleTask.Parse() reads base.ResponseData["data"]["members"] — it must be
|
||||
// an array of GuildMemberInfo objects, each having role + viewer_id (stringified).
|
||||
var resp = new GuildChangeRoleResponse
|
||||
{
|
||||
Members = new()
|
||||
{
|
||||
new GuildMemberInfoDto
|
||||
{
|
||||
ViewerId = 76_561_198_300_000_009L,
|
||||
Name = "TestLeader",
|
||||
EmblemId = 100_000_000L,
|
||||
CountryCode = "JP",
|
||||
Rank = 1,
|
||||
DegreeId = 0,
|
||||
IsOfficialMarkDisplayed = 0,
|
||||
Role = 1, // Leader
|
||||
},
|
||||
new GuildMemberInfoDto
|
||||
{
|
||||
ViewerId = 76_561_198_300_000_010L,
|
||||
Name = "TestMember",
|
||||
EmblemId = 100_000_000L,
|
||||
CountryCode = "",
|
||||
Rank = 1,
|
||||
DegreeId = 0,
|
||||
IsOfficialMarkDisplayed = 0,
|
||||
Role = 0, // Regular
|
||||
},
|
||||
}
|
||||
};
|
||||
var json = JsonSerializer.Serialize(resp, Opts);
|
||||
using var doc = JsonDocument.Parse(json);
|
||||
var root = doc.RootElement;
|
||||
|
||||
Assert.That(root.TryGetProperty("members", out var members), Is.True, "response must have 'members' key");
|
||||
Assert.That(members.ValueKind, Is.EqualTo(JsonValueKind.Array), "members must be an array");
|
||||
Assert.That(members.GetArrayLength(), Is.EqualTo(2));
|
||||
|
||||
var first = members[0];
|
||||
// viewer_id must be stringified (StringifiedLongConverter).
|
||||
Assert.That(first.GetProperty("viewer_id").ValueKind, Is.EqualTo(JsonValueKind.String),
|
||||
"viewer_id must be stringified");
|
||||
Assert.That(first.GetProperty("role").ValueKind, Is.EqualTo(JsonValueKind.String),
|
||||
"role must be stringified");
|
||||
Assert.That(first.GetProperty("role").GetString(), Is.EqualTo("1"),
|
||||
"Leader role must serialize as '1'");
|
||||
|
||||
// is_official_mark_displayed must always be present (JsonIgnore Never).
|
||||
Assert.That(first.TryGetProperty("is_official_mark_displayed", out var isMark), Is.True,
|
||||
"is_official_mark_displayed must always be emitted");
|
||||
Assert.That(isMark.GetInt32(), Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GuildFriendList_response_serializes_friends_array_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
|
||||
{
|
||||
Friends = new()
|
||||
{
|
||||
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,
|
||||
},
|
||||
}
|
||||
};
|
||||
var json = JsonSerializer.Serialize(resp, 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));
|
||||
|
||||
// First entry: is_join_guild = false.
|
||||
var first = friends[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];
|
||||
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");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GuildInfo_non_joined_serializes_to_prod_shape()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user