diff --git a/ShoppingAssistantApi.Application/Models/ProductSearch/ProductName.cs b/ShoppingAssistantApi.Application/Models/ProductSearch/ProductName.cs new file mode 100644 index 0000000..559ab3d --- /dev/null +++ b/ShoppingAssistantApi.Application/Models/ProductSearch/ProductName.cs @@ -0,0 +1,6 @@ +namespace ShoppingAssistantApi.Application.Models.ProductSearch; + +public class ProductName +{ + public string Name { get; set; } +} \ No newline at end of file diff --git a/ShoppingAssistantApi.Tests/ShoppingAssistantApi.Tests.csproj b/ShoppingAssistantApi.Tests/ShoppingAssistantApi.Tests.csproj index c36f3b4..85fc768 100644 --- a/ShoppingAssistantApi.Tests/ShoppingAssistantApi.Tests.csproj +++ b/ShoppingAssistantApi.Tests/ShoppingAssistantApi.Tests.csproj @@ -13,6 +13,7 @@ + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/ShoppingAssistantApi.Tests/Tests/ProductTests.cs b/ShoppingAssistantApi.Tests/Tests/ProductTests.cs new file mode 100644 index 0000000..d5b786c --- /dev/null +++ b/ShoppingAssistantApi.Tests/Tests/ProductTests.cs @@ -0,0 +1,61 @@ +using System.Collections.ObjectModel; +using Microsoft.VisualBasic; +using MongoDB.Bson; +using Moq; +using Newtonsoft.Json; +using ShoppingAssistantApi.Application.Models.Dtos; +using ShoppingAssistantApi.Application.IServices; +using ShoppingAssistantApi.Application.Models.OpenAi; +using ShoppingAssistantApi.Application.Models.ProductSearch; +using ShoppingAssistantApi.Domain.Entities; +using ShoppingAssistantApi.Domain.Enums; +using ShoppingAssistantApi.Tests.TestExtentions; +using ShoppingAssistantApi.Infrastructure.Services; + +namespace ShoppingAssistantApi.Tests.Tests; + +public class ProductTests : TestsBase +{ + private Mock _openAiServiceMock; + + private Mock _productServiceMock; + + public ProductTests(TestingFactory factory) : base(factory) + { + _openAiServiceMock = new Mock(); + _productServiceMock = new Mock(); + } + + + [Fact] + public async Task GetProductFromSearch_ReturnsProductList() + { + var message = new Message + { + Id = ObjectId.Parse("ab6c2c2d9edf39abcd1ef9ab"), + Text = "what are the best graphics cards you know?", + CreatedById = ObjectId.Parse("ab6c2c2d9edf39abcd1ef9ab"), + Role = "user" + }; + var cancellationToken = CancellationToken.None; + + var productServiceMock = new Mock(); + var expectedProductList = new List { "NVIDIA GeForce RTX 3080", "AMD Radeon RX 6900 XT" }; + productServiceMock.Setup(x => x.GetProductFromSearch(message, cancellationToken)) + .ReturnsAsync(expectedProductList); + + var openAiServiceMock = new Mock(); + var expectedOpenAiMessage = new OpenAiMessage + { + Role = OpenAiRole.User, + Content = "[\n { \"Name\": \"NVIDIA GeForce RTX 3080\" },\n { \"Name\": \"AMD Radeon RX 6900 XT\" }\n]" + }; + openAiServiceMock.Setup(x => x.GetChatCompletion(It.IsAny(), cancellationToken)) + .ReturnsAsync(expectedOpenAiMessage); + + var productList = JsonConvert.DeserializeObject>(expectedOpenAiMessage.Content).Select(info => info.Name).ToList(); + + Assert.Equal(expectedProductList, productList); + } + +} \ No newline at end of file