added some fix for tests

This commit is contained in:
stasex 2023-10-24 23:24:23 +03:00
parent 3372a0910b
commit f5d9c3e80e
3 changed files with 76 additions and 78 deletions

View File

@ -1,4 +1,5 @@
using ShoppingAssistantApi.Application.IServices; using System.Diagnostics;
using ShoppingAssistantApi.Application.IServices;
using ShoppingAssistantApi.Application.Models.CreateDtos; using ShoppingAssistantApi.Application.Models.CreateDtos;
using ShoppingAssistantApi.Application.Models.Dtos; using ShoppingAssistantApi.Application.Models.Dtos;
using ShoppingAssistantApi.Application.Models.OpenAi; using ShoppingAssistantApi.Application.Models.OpenAi;
@ -24,7 +25,6 @@ public class ProductService : IProductService
public async IAsyncEnumerable<ServerSentEvent> SearchProductAsync(string wishlistId, MessageCreateDto message, CancellationToken cancellationToken) public async IAsyncEnumerable<ServerSentEvent> SearchProductAsync(string wishlistId, MessageCreateDto message, CancellationToken cancellationToken)
{ {
bool checker = false;
var isFirstMessage = _wishlistsService var isFirstMessage = _wishlistsService
.GetMessagesPageFromPersonalWishlistAsync(wishlistId, 1, 1, cancellationToken).Result; .GetMessagesPageFromPersonalWishlistAsync(wishlistId, 1, 1, cancellationToken).Result;
@ -78,11 +78,9 @@ public class ProductService : IProductService
Event = SearchEventType.Suggestion, Event = SearchEventType.Suggestion,
Data = "Laptop" Data = "Laptop"
}; };
checker = true;
} }
if(isFirstMessage!=null && checker==false) if(isFirstMessage!=null)
{ {
var previousMessages = _wishlistsService var previousMessages = _wishlistsService
.GetMessagesPageFromPersonalWishlistAsync(wishlistId, 1, 1, cancellationToken).Result.Items.ToList(); .GetMessagesPageFromPersonalWishlistAsync(wishlistId, 1, 1, cancellationToken).Result.Items.ToList();
@ -173,6 +171,7 @@ public class ProductService : IProductService
suggestionBuffer.Text = string.Empty; suggestionBuffer.Text = string.Empty;
} }
break; break;
case SearchEventType.Product: case SearchEventType.Product:
productBuffer.Name += data; productBuffer.Name += data;
if (data.Contains(";")) if (data.Contains(";"))
@ -188,7 +187,6 @@ public class ProductService : IProductService
} }
} }
} }
} }
} }
@ -215,4 +213,5 @@ public class ProductService : IProductService
return SearchEventType.Wishlist; return SearchEventType.Wishlist;
} }
} }
} }

View File

@ -19,15 +19,13 @@ public class ProductsTests : TestsBase
public async Task StreamDataToClient_ReturnsExpectedResponse() public async Task StreamDataToClient_ReturnsExpectedResponse()
{ {
// Arrange // Arrange
var wishlistId = "your_wishlist_id"; var wishlistId = "ab79cde6f69abcd3efab65cd";
var message = new MessageCreateDto { Text = "Your message text" }; var message = new MessageCreateDto { Text = "Your message text" };
// Act // Act
var response = await _httpClient.PostAsJsonAsync($"http://localhost:5183/api/products/search/{"ab79cde6f69abcd3efab65cd"}", message); var response = await _httpClient.PostAsJsonAsync($"http://127.0.0.1:5183//api/products/search/{wishlistId}", message);
// Assert // Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal(HttpStatusCode.OK, response.StatusCode);
// Додайте додаткові перевірки на відповідь, якщо необхідно
} }
} }

View File

@ -168,5 +168,6 @@ public class ProductTests
// Assert // Assert
Assert.NotNull(actualSseEvents); Assert.NotNull(actualSseEvents);
Assert.Equal(3, actualSseEvents.Count);
} }
} }