test(friend): end-to-end multi-viewer apply→approve→friendship flow
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -284,4 +284,54 @@ public class FriendControllerTests
|
||||
var response = await client.PostAsync("/friend/info", JsonBody("{}"));
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.Unauthorized));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Multi_viewer_flow_A_sends_B_approves_both_see_friend()
|
||||
{
|
||||
using var factory = new SVSimTestFactory();
|
||||
long viewerA = await SeedViewer(factory, 76_561_198_000_020_001UL, "Alice");
|
||||
long viewerB = await SeedViewer(factory, 76_561_198_000_020_002UL, "Bob");
|
||||
|
||||
// A sends apply to B.
|
||||
using (var clientA = factory.CreateAuthenticatedClient(viewerA))
|
||||
{
|
||||
var resp = await clientA.PostAsync("/friend/send_apply", JsonBody($$"""{"friend_id":{{(int)viewerB}}}"""));
|
||||
Assert.That(resp.StatusCode, Is.EqualTo(HttpStatusCode.OK));
|
||||
}
|
||||
|
||||
// B sees the apply in receive_apply_info.
|
||||
int applyId;
|
||||
using (var clientB = factory.CreateAuthenticatedClient(viewerB))
|
||||
{
|
||||
var resp = await clientB.PostAsync("/friend/receive_apply_info", JsonBody("{}"));
|
||||
var raw = await resp.Content.ReadAsStringAsync();
|
||||
using var doc = JsonDocument.Parse(raw);
|
||||
var applies = doc.RootElement.GetProperty("receive_applies");
|
||||
Assert.That(applies.GetArrayLength(), Is.EqualTo(1));
|
||||
applyId = applies[0].GetProperty("id").GetInt32();
|
||||
Assert.That(applies[0].GetProperty("name").GetString(), Is.EqualTo("Alice"));
|
||||
}
|
||||
|
||||
// B approves.
|
||||
using (var clientB = factory.CreateAuthenticatedClient(viewerB))
|
||||
{
|
||||
var resp = await clientB.PostAsync("/friend/approve_apply", JsonBody($$"""{"apply_id":{{applyId}}}"""));
|
||||
Assert.That(resp.StatusCode, Is.EqualTo(HttpStatusCode.OK));
|
||||
}
|
||||
|
||||
// Both A and B now see each other in /friend/info.
|
||||
async Task<string> GetFriendName(long ownerId)
|
||||
{
|
||||
using var client = factory.CreateAuthenticatedClient(ownerId);
|
||||
var resp = await client.PostAsync("/friend/info", JsonBody("{}"));
|
||||
var raw = await resp.Content.ReadAsStringAsync();
|
||||
using var doc = JsonDocument.Parse(raw);
|
||||
var friends = doc.RootElement.GetProperty("friends");
|
||||
Assert.That(friends.GetArrayLength(), Is.EqualTo(1));
|
||||
return friends[0].GetProperty("name").GetString()!;
|
||||
}
|
||||
|
||||
Assert.That(await GetFriendName(viewerA), Is.EqualTo("Bob"));
|
||||
Assert.That(await GetFriendName(viewerB), Is.EqualTo("Alice"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user