using System.Text.Json; using ChatAgent.Api.Plugins; using ChatAgent.Shared.Models; namespace ChatAgent.Api.Tests; public class ExtractionPluginTests { private readonly ExtractionPlugin _plugin = new(); [Fact] public void ValidateExtractedFields_AllRequiredPresent_ReturnsValid() { var fields = new ExtractedFields { Client = "Acme Corp", Project = "Phase 2", Hours = 3, Rate = 150, Currency = "USD", Date = "2026-04-01" }; var resultJson = _plugin.ValidateExtractedFields(JsonSerializer.Serialize(fields)); var result = JsonSerializer.Deserialize(resultJson); Assert.NotNull(result); Assert.True(result.IsValid); Assert.Empty(result.Errors); } [Fact] public void ValidateExtractedFields_MissingRequired_ReturnsErrors() { // Missing Client and Hours var fields = new ExtractedFields { Project = "Phase 2", Rate = 150, Currency = "USD", Date = "2026-04-01" }; var resultJson = _plugin.ValidateExtractedFields(JsonSerializer.Serialize(fields)); var result = JsonSerializer.Deserialize(resultJson); Assert.NotNull(result); Assert.False(result.IsValid); Assert.Contains(result.Errors, e => e.Contains("Client")); Assert.Contains(result.Errors, e => e.Contains("Hours")); } [Fact] public void ValidateExtractedFields_InvalidJson_ReturnsError() { var resultJson = _plugin.ValidateExtractedFields("not valid json"); var result = JsonSerializer.Deserialize(resultJson); Assert.NotNull(result); Assert.False(result.IsValid); Assert.Contains(result.Errors, e => e.Contains("Invalid JSON")); } [Fact] public void ValidateExtractedFields_ZeroHours_ReturnsError() { var fields = new ExtractedFields { Client = "Acme Corp", Project = "Phase 2", Hours = 0, Rate = 150, Currency = "USD", Date = "2026-04-01" }; var resultJson = _plugin.ValidateExtractedFields(JsonSerializer.Serialize(fields)); var result = JsonSerializer.Deserialize(resultJson); Assert.NotNull(result); Assert.False(result.IsValid); Assert.Contains(result.Errors, e => e.Contains("Hours")); } [Fact] public void ValidateExtractedFields_OptionalFieldsMissing_StillValid() { // Description and PoNumber are optional var fields = new ExtractedFields { Client = "Acme Corp", Project = "Phase 2", Hours = 3, Rate = 150, Currency = "USD", Date = "2026-04-01" // Description and PoNumber intentionally omitted }; var resultJson = _plugin.ValidateExtractedFields(JsonSerializer.Serialize(fields)); var result = JsonSerializer.Deserialize(resultJson); Assert.NotNull(result); Assert.True(result.IsValid); } }