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.
63 lines
1.8 KiB
C#
63 lines
1.8 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.Matchmaking;
|
|
using TarninaHub.Tests.Stubs;
|
|
|
|
namespace TarninaHub.Tests.Controllers;
|
|
|
|
public class InnovationsControllerTests
|
|
{
|
|
private static InnovationsController CreateController(IInnovationService service)
|
|
{
|
|
var controller = new InnovationsController(
|
|
service,
|
|
new StubMatchmakingService(),
|
|
new StubTestFeedbackService());
|
|
var identity = new ClaimsIdentity(
|
|
[new Claim("sub", "user:tester"), new Claim("role", "admin")],
|
|
authenticationType: "test");
|
|
|
|
controller.ControllerContext = new ControllerContext
|
|
{
|
|
HttpContext = new DefaultHttpContext { User = new ClaimsPrincipal(identity) },
|
|
};
|
|
|
|
return controller;
|
|
}
|
|
|
|
private static InnovationRequest SampleRequest(string stage) => new(
|
|
"Klub sąsiedzki",
|
|
"Streszczenie",
|
|
"Opis",
|
|
"social_challenge:seniorzy",
|
|
stage,
|
|
null,
|
|
null,
|
|
null,
|
|
true);
|
|
|
|
[Fact]
|
|
public async Task Create_RejectsUnknownStage()
|
|
{
|
|
var controller = CreateController(new StubInnovationService());
|
|
|
|
var result = await controller.Create(SampleRequest("draft"), CancellationToken.None);
|
|
|
|
Assert.IsType<ObjectResult>(result.Result);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Create_AcceptsKnownStage()
|
|
{
|
|
var controller = CreateController(new StubInnovationService());
|
|
|
|
var result = await controller.Create(SampleRequest("pilot"), CancellationToken.None);
|
|
|
|
Assert.IsType<CreatedAtActionResult>(result.Result);
|
|
}
|
|
}
|