From 5973598063afbca77332b94683928bc48e30acc1 Mon Sep 17 00:00:00 2001 From: Mykhailo Bilodid Date: Sat, 18 Nov 2023 01:46:59 +0200 Subject: [PATCH] SA-143 all tests and issues fixed --- .../Repositories/BaseRepository.cs | 3 +- .../TestExtentions/DbInitializer.cs | 91 +++++++++++++++++++ .../Tests/WishlistsTests.cs | 11 ++- 3 files changed, 99 insertions(+), 6 deletions(-) diff --git a/ShoppingAssistantApi.Persistance/Repositories/BaseRepository.cs b/ShoppingAssistantApi.Persistance/Repositories/BaseRepository.cs index e222f77..1087ee9 100644 --- a/ShoppingAssistantApi.Persistance/Repositories/BaseRepository.cs +++ b/ShoppingAssistantApi.Persistance/Repositories/BaseRepository.cs @@ -55,7 +55,8 @@ public abstract class BaseRepository : IBaseRepository where T public async Task GetTotalCountAsync() { - return (int)(await this._collection.EstimatedDocumentCountAsync()); + var filter = Builders.Filter.Eq("IsDeleted", false); + return (int)(await this._collection.CountDocumentsAsync(x => !x.IsDeleted)); } public async Task GetCountAsync(Expression> predicate, CancellationToken cancellationToken) diff --git a/ShoppingAssistantApi.Tests/TestExtentions/DbInitializer.cs b/ShoppingAssistantApi.Tests/TestExtentions/DbInitializer.cs index f4346d7..360aa2b 100644 --- a/ShoppingAssistantApi.Tests/TestExtentions/DbInitializer.cs +++ b/ShoppingAssistantApi.Tests/TestExtentions/DbInitializer.cs @@ -109,6 +109,7 @@ public class DbInitializer var wishlistId2 = ObjectId.Parse("ab6c2c2d9edf39abcd1ef9ab"); var wishlistId3 = ObjectId.Parse("ab7c8c2d9edf39abcd1ef9ab"); var wishlistId4 = ObjectId.Parse("ab8c8c2d9edf39abcd1ef9ab"); + var wishlistId5 = ObjectId.Parse("65575253dbe88a3c118e1ca2"); var wishlists = new Wishlist[] { @@ -121,6 +122,14 @@ public class DbInitializer CreatedDateUtc = DateTime.UtcNow }, new Wishlist + { + Id = wishlistId5, + Name = "Gaming PC", + Type = WishlistTypes.Product.ToString(), + CreatedById = user1.Id, + CreatedDateUtc = DateTime.UtcNow + }, + new Wishlist { Id = wishlistId2, Name = "Generic Wishlist Name", @@ -162,6 +171,8 @@ public class DbInitializer var wishlistId2 = ObjectId.Parse("ab6c2c2d9edf39abcd1ef9ab"); var wishlistId3 = ObjectId.Parse("ab7c8c2d9edf39abcd1ef9ab"); var wishlistId4 = ObjectId.Parse("ab8c8c2d9edf39abcd1ef9ab"); + var wishlistId5 = ObjectId.Parse("65575253dbe88a3c118e1ca2"); + var messages = new Message[] { @@ -211,6 +222,51 @@ public class DbInitializer CreatedDateUtc = DateTime.UtcNow.AddSeconds(50) }, new Message + { + Text = "Message 1", + Role = MessageRoles.User.ToString(), + WishlistId = wishlistId5, + CreatedById = user1.Id, + CreatedDateUtc = DateTime.UtcNow + }, + new Message + { + Text = "Message 2", + Role = MessageRoles.Application.ToString(), + WishlistId = wishlistId5, + CreatedDateUtc = DateTime.UtcNow.AddSeconds(5) + }, + new Message + { + Text = "Message 3", + Role = MessageRoles.User.ToString(), + WishlistId = wishlistId5, + CreatedById = user1.Id, + CreatedDateUtc = DateTime.UtcNow.AddSeconds(20) + }, + new Message + { + Text = "Message 4", + Role = MessageRoles.Application.ToString(), + WishlistId = wishlistId5, + CreatedDateUtc = DateTime.UtcNow.AddSeconds(25) + }, + new Message + { + Text = "Message 5", + Role = MessageRoles.User.ToString(), + WishlistId = wishlistId5, + CreatedById = user1.Id, + CreatedDateUtc = DateTime.UtcNow.AddSeconds(45) + }, + new Message + { + Text = "Message 6", + Role = MessageRoles.Application.ToString(), + WishlistId = wishlistId5, + CreatedDateUtc = DateTime.UtcNow.AddSeconds(50) + }, + new Message { Text = "Prompt", Role = MessageRoles.User.ToString(), @@ -249,6 +305,7 @@ public class DbInitializer var wishlistId1 = ObjectId.Parse("ab79cde6f69abcd3efab65cd"); var wishlistId2 = ObjectId.Parse("ab6c2c2d9edf39abcd1ef9ab"); + var wishlistId3 = ObjectId.Parse("65575253dbe88a3c118e1ca2"); var products = new Product[] { @@ -285,6 +342,40 @@ public class DbInitializer WishlistId = wishlistId1, CreatedById = user1.Id, CreatedDateUtc = DateTime.UtcNow + }, + new Product + { + Name = "AMD Ryzen 5 5600G 6-Core 12-Thread Unlocked Desktop Processor with Radeon Graphics", + Description = "Features best-in-class graphics performance in a desktop processor for smooth 1080p gaming, no graphics card required", + Rating = 4.8, + Price = 120, + Url = "https://a.co/d/5ceuIrq", + ImagesUrls = new string[] + { + "https://m.media-amazon.com/images/I/51f2hkWjTlL._AC_SL1200_.jpg", + "https://m.media-amazon.com/images/I/51iji7Gel-L._AC_SL1200_.jpg" + }, + WasOpened = false, + WishlistId = wishlistId3, + CreatedById = user1.Id, + CreatedDateUtc = DateTime.UtcNow + }, + new Product + { + Name = "Samsung 970 EVO Plus SSD 2TB NVMe M.2 Internal Solid State Hard Drive, V-NAND Technology, Storage and Memory Expansion for Gaming, Graphics w/ Heat Control, Max Speed, MZ-V7S2T0B/AM ", + Description = "7 Year Limited Warranty: The 970 EVO Plus provides up to 1200 TBW (Terabytes Written) with 5-years of protection for exceptional endurance powered by the latest V-NAND technology and Samsung's reputation for quality ", + Rating = 4.8, + Price = 153, + Url = "https://a.co/d/gxnuqs1", + ImagesUrls = new string[] + { + "https://m.media-amazon.com/images/I/51Brl+iYtvL._AC_SL1001_.jpg", + "https://m.media-amazon.com/images/I/51GOfLlVwoL._AC_SL1001_.jpg" + }, + WasOpened = false, + WishlistId = wishlistId3, + CreatedById = user1.Id, + CreatedDateUtc = DateTime.UtcNow }, }; diff --git a/ShoppingAssistantApi.Tests/Tests/WishlistsTests.cs b/ShoppingAssistantApi.Tests/Tests/WishlistsTests.cs index 4d1e5d8..3ed5336 100644 --- a/ShoppingAssistantApi.Tests/Tests/WishlistsTests.cs +++ b/ShoppingAssistantApi.Tests/Tests/WishlistsTests.cs @@ -26,6 +26,7 @@ public class WishlistsTests : TestsBase private const string TestingValidWishlistId = "ab79cde6f69abcd3efab65cd"; + private const string TestingValidWishlistId2 = "65575253dbe88a3c118e1ca2"; public WishlistsTests(TestingFactory factory) : base(factory) @@ -178,7 +179,7 @@ public class WishlistsTests : TestsBase }", variables = new { - wishlistId = TestingValidWishlistId + wishlistId = TestingValidWishlistId2 } }; @@ -246,7 +247,7 @@ public class WishlistsTests : TestsBase }", variables = new { - wishlistId = TestingValidWishlistId, + wishlistId = TestingValidWishlistId2, pageNumber = 1, pageSize = 2 } @@ -823,7 +824,7 @@ public class WishlistsTests : TestsBase }", variables = new { - wishlistId = TestingValidWishlistId, + wishlistId = TestingValidWishlistId2, pageNumber = 100, pageSize = 2 } @@ -878,7 +879,7 @@ public class WishlistsTests : TestsBase query = "query productsPageFromPersonalWishlist($wishlistId: String!, $pageNumber: Int!, $pageSize: Int!) { productsPageFromPersonalWishlist (wishlistId: $wishlistId, pageNumber: $pageNumber, pageSize: $pageSize) { hasNextPage, hasPreviousPage, items { id, url, name, description, rating, imagesUrls, wasOpened, wishlistId }, pageNumber, pageSize, totalItems, totalPages } }", variables = new { - wishlistId = TestingValidWishlistId, + wishlistId = TestingValidWishlistId2, pageNumber = 1, pageSize = 100 } @@ -890,7 +891,7 @@ public class WishlistsTests : TestsBase Assert.NotNull(pagedList); Assert.Equal("Samsung 970 EVO Plus SSD 2TB NVMe M.2 Internal Solid State Hard Drive, V-NAND Technology, Storage and Memory Expansion for Gaming, Graphics w/ Heat Control, Max Speed, MZ-V7S2T0B/AM ", pagedList.Items.ToList()[1].Name); - Assert.Equal(TestingValidWishlistId, pagedList.Items.ToList()[1].WishlistId); + Assert.Equal(TestingValidWishlistId2, pagedList.Items.ToList()[1].WishlistId); } [Fact]