Add comprehensive backend test suite and helper access
This commit is contained in:
28
GameList.Tests/MiddlewareTests.cs
Normal file
28
GameList.Tests/MiddlewareTests.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System.Net;
|
||||
using GameList.Tests.Support;
|
||||
|
||||
namespace GameList.Tests;
|
||||
|
||||
public class MiddlewareTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task Deleted_player_cookie_is_signed_out()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
var client = factory.CreateClientWithCookies();
|
||||
await client.RegisterAsync("ghost");
|
||||
|
||||
var playerId = await client.GetProfileIdAsync();
|
||||
|
||||
await factory.WithDbContextAsync(async db =>
|
||||
{
|
||||
var player = await db.Players.FindAsync(playerId);
|
||||
db.Players.Remove(player!);
|
||||
await db.SaveChangesAsync();
|
||||
});
|
||||
|
||||
var resp = await client.GetAsync("/api/state");
|
||||
Assert.Equal(HttpStatusCode.Unauthorized, resp.StatusCode);
|
||||
Assert.Contains(resp.Headers, h => h.Key.Equals("Set-Cookie", StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user