test(backend): add embedding text and innovation stage tests
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
using TarninaHub.Application.Mappings;
|
||||
using TarninaHub.Application.Text;
|
||||
using TarninaHub.Domain.Enums;
|
||||
|
||||
namespace TarninaHub.Tests.Application;
|
||||
|
||||
public class EmbeddingAndStageTests
|
||||
{
|
||||
[Fact]
|
||||
public void EmbeddingTextBuilder_JoinsNonEmptyParts()
|
||||
{
|
||||
var text = EmbeddingTextBuilder.Build("Tytuł", "Streszczenie", null, "Seniorzy");
|
||||
|
||||
Assert.Equal("Tytuł\nStreszczenie\nSeniorzy", text);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EmbeddingTextBuilder_TrimsAndSkipsBlank()
|
||||
{
|
||||
var text = EmbeddingTextBuilder.Build(" Tytuł ", " ", "Opis", null);
|
||||
|
||||
Assert.Equal("Tytuł\nOpis", text);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("idea", true)]
|
||||
[InlineData("pilot", true)]
|
||||
[InlineData("scaling", true)]
|
||||
[InlineData("service", true)]
|
||||
[InlineData("draft", false)]
|
||||
[InlineData("", false)]
|
||||
public void InnovationStageWire_Validates(string value, bool expected)
|
||||
{
|
||||
Assert.Equal(expected, InnovationStageWire.IsValid(value));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(InnovationStage.Idea, "idea")]
|
||||
[InlineData(InnovationStage.Pilot, "pilot")]
|
||||
[InlineData(InnovationStage.Scaling, "scaling")]
|
||||
[InlineData(InnovationStage.Service, "service")]
|
||||
public void InnovationStageWire_RoundTrips(InnovationStage stage, string wire)
|
||||
{
|
||||
Assert.Equal(wire, stage.ToWire());
|
||||
Assert.Equal(stage, InnovationStageWire.Parse(wire));
|
||||
}
|
||||
}
|
||||
@@ -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