Files
Rafał Tyński cca20a9965 test(backend): cover step 17 modules and extract stubs
Add tests for partnership workflow, middleman adaptation and idea notifications; extract reusable test stubs into separate files; add architecture guard forbidding object-valued dictionaries in data contracts.
2026-10-04 03:49:51 +02:00

66 lines
2.2 KiB
C#

using System.Security.Claims;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using TarninaHub.Application.Abstractions;
using TarninaHub.Application.Dtos;
using TarninaHub.Controllers;
using TarninaHub.Tests.Stubs;
namespace TarninaHub.Tests.Controllers;
public class ApplicationsControllerTests
{
private static ApplicationsController CreateController(
IApplicationService applicationService,
IIdeaService? ideaService = null)
{
var controller = new ApplicationsController(applicationService, ideaService ?? new StubIdeaService());
var identity = new ClaimsIdentity(
[new Claim("sub", "user:tester"), new Claim("role", "user")],
authenticationType: "test");
controller.ControllerContext = new ControllerContext
{
HttpContext = new DefaultHttpContext { User = new ClaimsPrincipal(identity) },
};
return controller;
}
[Fact]
public async Task Create_ReturnsConflictWhenCallNotOpen()
{
var service = new StubApplicationService(
new CreateApplicationResult(CreateApplicationOutcome.CallNotOpen, null));
var controller = CreateController(service);
var result = await controller.Create(
new CreateApplicationRequest("grant_call:x", "idea:y", null),
CancellationToken.None);
var conflict = Assert.IsType<ConflictObjectResult>(result.Result);
Assert.Equal(StatusCodes.Status409Conflict, conflict.StatusCode);
}
[Fact]
public async Task Create_ReturnsCreatedWhenSuccessful()
{
var application = new ApplicationResponse(
"application:new",
"grant_call:x",
"idea:y",
new Dictionary<string, string?>(),
"draft",
DateTimeOffset.UtcNow);
var service = new StubApplicationService(
new CreateApplicationResult(CreateApplicationOutcome.Created, application));
var controller = CreateController(service);
var result = await controller.Create(
new CreateApplicationRequest("grant_call:x", "idea:y", null),
CancellationToken.None);
Assert.IsType<CreatedAtActionResult>(result.Result);
}
}