72 lines
2.2 KiB
C#
72 lines
2.2 KiB
C#
using System.Net;
|
|
using System.Net;
|
|
using System.Net.Http.Json;
|
|
using GameList.Tests.Support;
|
|
|
|
namespace GameList.Tests;
|
|
|
|
public class SuggestionTests
|
|
{
|
|
[Fact]
|
|
public async Task Player_cannot_exceed_five_suggestions()
|
|
{
|
|
using var factory = new TestWebApplicationFactory();
|
|
var client = factory.CreateClientWithCookies();
|
|
await client.RegisterAsync("suggestor");
|
|
|
|
for (var i = 0; i < 5; i++)
|
|
{
|
|
var resp = await client.PostAsJsonAsync("/api/suggestions", new
|
|
{
|
|
Name = $"Game {i}",
|
|
Genre = (string?)null,
|
|
Description = (string?)null,
|
|
ScreenshotUrl = (string?)null,
|
|
YoutubeUrl = (string?)null,
|
|
GameUrl = (string?)null,
|
|
MinPlayers = (int?)null,
|
|
MaxPlayers = (int?)null
|
|
});
|
|
resp.EnsureSuccessStatusCode();
|
|
}
|
|
|
|
var sixth = await client.PostAsJsonAsync("/api/suggestions", new
|
|
{
|
|
Name = "Overflow",
|
|
Genre = (string?)null,
|
|
Description = (string?)null,
|
|
ScreenshotUrl = (string?)null,
|
|
YoutubeUrl = (string?)null,
|
|
GameUrl = (string?)null,
|
|
MinPlayers = (int?)null,
|
|
MaxPlayers = (int?)null
|
|
});
|
|
|
|
Assert.Equal(HttpStatusCode.BadRequest, sixth.StatusCode);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Unreachable_screenshot_url_is_rejected()
|
|
{
|
|
using var factory = new TestWebApplicationFactory();
|
|
factory.HttpHandler.SetResponder(_ => new HttpResponseMessage(HttpStatusCode.BadRequest));
|
|
|
|
var client = factory.CreateClientWithCookies();
|
|
await client.RegisterAsync("imgtester");
|
|
|
|
var response = await client.PostAsJsonAsync("/api/suggestions", new
|
|
{
|
|
Name = "Needs image",
|
|
Genre = (string?)null,
|
|
Description = (string?)null,
|
|
ScreenshotUrl = "http://example.com/image.png",
|
|
YoutubeUrl = (string?)null,
|
|
GameUrl = (string?)null,
|
|
MinPlayers = (int?)null,
|
|
MaxPlayers = (int?)null
|
|
});
|
|
|
|
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
|
}
|
|
}
|