test(backend): add embedding text and innovation stage tests
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using TarninaHub.Application.Abstractions;
|
||||
using TarninaHub.Application.Dtos;
|
||||
using TarninaHub.Controllers;
|
||||
|
||||
namespace TarninaHub.Tests.Controllers;
|
||||
|
||||
public class InnovationsControllerTests
|
||||
{
|
||||
private static InnovationsController CreateController(IInnovationService service)
|
||||
{
|
||||
var controller = new InnovationsController(service);
|
||||
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);
|
||||
}
|
||||
|
||||
private sealed class StubInnovationService : IInnovationService
|
||||
{
|
||||
public Task<IReadOnlyList<InnovationResponse>> ListAsync(
|
||||
string? challengeId,
|
||||
string? stage,
|
||||
string? query,
|
||||
bool onlyPublished,
|
||||
CancellationToken cancellationToken) => Task.FromResult<IReadOnlyList<InnovationResponse>>([]);
|
||||
|
||||
public Task<InnovationResponse?> GetAsync(string innovationId, CancellationToken cancellationToken) =>
|
||||
Task.FromResult<InnovationResponse?>(null);
|
||||
|
||||
public Task<InnovationResponse> CreateAsync(
|
||||
InnovationRequest request,
|
||||
CancellationToken cancellationToken) => Task.FromResult(new InnovationResponse(
|
||||
"innovation:new",
|
||||
request.Title,
|
||||
request.Summary ?? string.Empty,
|
||||
request.Description ?? string.Empty,
|
||||
request.ChallengeId,
|
||||
request.Stage,
|
||||
request.Cost,
|
||||
request.Contact,
|
||||
request.Media ?? [],
|
||||
request.Published,
|
||||
DateTimeOffset.UtcNow));
|
||||
|
||||
public Task<InnovationResponse?> UpdateAsync(
|
||||
string innovationId,
|
||||
InnovationRequest request,
|
||||
CancellationToken cancellationToken) => Task.FromResult<InnovationResponse?>(null);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user