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.
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user