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(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); }