Files
Hy2026/tests/TarninaHub.Tests/Controllers/IdeasControllerTests.cs
T
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

55 lines
1.7 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 IdeasControllerTests
{
private static IdeasController CreateController(IIdeaService ideaService, INotificationService notifications)
{
var controller = new IdeasController(
ideaService,
new StubIdeaAssistant(),
notifications);
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_NotifiesStaffAndReturnsCreated()
{
var ideaService = new StubIdeaService { Idea = SampleIdea() };
var notifications = new StubNotificationService();
var controller = CreateController(ideaService, notifications);
var result = await controller.Create(
new CreateIdeaRequest("Nowy pomysł", "Opis nowego pomysłu mieszkańca.", null),
CancellationToken.None);
Assert.IsType<CreatedAtActionResult>(result.Result);
Assert.Equal(1, notifications.StaffNotifications);
}
private static IdeaResponse SampleIdea() => new(
"idea:new",
"Nowy pomysł",
"Opis nowego pomysłu mieszkańca.",
"user:tester",
"draft",
null,
DateTimeOffset.UtcNow);
}