From f33bba50eb4e435fd211a98c56fcb1006ef88e23 Mon Sep 17 00:00:00 2001 From: Sergey Novitsky Date: Thu, 1 Sep 2022 14:05:42 +0300 Subject: [PATCH] Add condition for select popular workshops (#834) * Add condition for select popular workshops * Change tests regarding CATOTTG Co-authored-by: Sergii Novytskyi --- .../Services/StatisticServiceTest.cs | 157 +++++++++++++++++- .../Services/StatisticService.cs | 3 +- 2 files changed, 152 insertions(+), 8 deletions(-) diff --git a/OutOfSchool/OutOfSchool.WebApi.Tests/Services/StatisticServiceTest.cs b/OutOfSchool/OutOfSchool.WebApi.Tests/Services/StatisticServiceTest.cs index 9163897423..504dba056a 100644 --- a/OutOfSchool/OutOfSchool.WebApi.Tests/Services/StatisticServiceTest.cs +++ b/OutOfSchool/OutOfSchool.WebApi.Tests/Services/StatisticServiceTest.cs @@ -79,16 +79,17 @@ public async Task GetPopularWorkshops_WhenCityNotQueried_ShouldReturnCertainWork public async Task GetPopularWorkshops_WithCityQueried_ShouldReturnCertainWorkshops() { // Arrange - List expectedWorkshopCards = ExpectedWorkshopCardsCityFilter(); + List expectedWorkshops = ExpectedWorkshopCardsCityFilter(); - SetupGetPopularWorkshops(); + SetupGetPopularWorkshopsIncludingCATOTTG(); + var expectedWorkshopCards = new List(); mapper.Setup(m => m.Map>(It.IsAny>())) .Returns(expectedWorkshopCards); // Act var result = await service - .GetPopularWorkshopsFromDatabase(2, 4970) + .GetPopularWorkshopsFromDatabase(2, 31737) .ConfigureAwait(false); // Assert @@ -172,6 +173,22 @@ private void SetupGetPopularWorkshops() .Verifiable(); } + private void SetupGetPopularWorkshopsIncludingCATOTTG() + { + var workshopsMock = WithWorkshopsIncludingCATOTTG().AsQueryable().BuildMock(); + + workshopRepository + .Setup(w => w.Get( + It.IsAny(), + It.IsAny(), + It.IsAny(), + It.IsAny>>(), + It.IsAny>, SortDirection>>(), + It.IsAny())) + .Returns(workshopsMock) + .Verifiable(); + } + private void SetupGetPopularDirections() { var workshopsMock = WithWorkshops().AsQueryable().BuildMock(); @@ -298,6 +315,106 @@ private IEnumerable WithWorkshops() }; } + private IEnumerable WithWorkshopsIncludingCATOTTG() + { + return new List + { + new Workshop + { + Id = new Guid("953708d7-8c35-4607-bd9b-f034e853bb89"), + Title = "w1", + InstitutionHierarchyId = new Guid("af475193-6a1e-4a75-9ba3-439c4300f771"), + InstitutionHierarchy = new InstitutionHierarchy + { + Id = new Guid("af475193-6a1e-4a75-9ba3-439c4300f771"), + Directions = new List + { + new Direction + { + Id = 1, + }, + }, + }, + Address = new Address + { + CATOTTGId = 31739, + CATOTTG = new CATOTTG + { + Category = "B", + ParentId = 31737, + }, + }, + Applications = new List + { + new Application { Id = new Guid("0083633f-4e5b-4c09-a89d-52d8a9b89cdb") }, + }, + }, + new Workshop + { + Id = new Guid("3a2fbb29-e097-4184-ad02-26ed1e5f5057"), + Title = "w2", + InstitutionHierarchyId = new Guid("01d08412-69d3-4620-8c54-7b997430e08d"), + InstitutionHierarchy = new InstitutionHierarchy + { + Id = new Guid("01d08412-69d3-4620-8c54-7b997430e08d"), + Directions = new List + { + new Direction + { + Id = 2, + }, + }, + }, + Address = new Address + { + CATOTTGId = 31737, + CATOTTG = new CATOTTG + { + Category = "K", + ParentId = null, + }, + }, + Applications = new List + { + new Application { Id = new Guid("7c5f8f7c-d850-44d0-8d4e-fd2de99453be") }, + new Application { Id = new Guid("1745d16a-6181-43d7-97d0-a1d6cc34a8bd") }, + }, + }, + new Workshop + { + Id = new Guid("6f8bf795-072d-4fca-ad89-e54a275eb674"), + Title = "w3", + InstitutionHierarchyId = new Guid("af628dd5-e9b6-4ad4-9d12-e87063d8707d"), + InstitutionHierarchy = new InstitutionHierarchy + { + Id = new Guid("af628dd5-e9b6-4ad4-9d12-e87063d8707d"), + Directions = new List + { + new Direction + { + Id = 3, + }, + }, + }, + Address = new Address + { + CATOTTGId = 5000, + CATOTTG = new CATOTTG + { + Category = "C", + ParentId = 4971, + }, + }, + Applications = new List + { + new Application { Id = new Guid("af628dd5-e9b6-4ad4-9d12-e87063d8707d") }, + new Application { Id = new Guid("01d08412-69d3-4620-8c54-7b997430e08d") }, + new Application { Id = new Guid("af475193-6a1e-4a75-9ba3-439c4300f771") }, + }, + }, + }; + } + private IEnumerable WithDirections() { return new List @@ -454,12 +571,38 @@ private List ExpectedWorkshopCardsNoCityFilter() }; } - private List ExpectedWorkshopCardsCityFilter() + private List ExpectedWorkshopCardsCityFilter() { - return new List + return new List { - new WorkshopCard {WorkshopId = new Guid("3a2fbb29-e097-4184-ad02-26ed1e5f5057"), Title = "w2", Address = new AddressDto {CATOTTGId = 4970}}, - new WorkshopCard {WorkshopId = new Guid("953708d7-8c35-4607-bd9b-f034e853bb89"), Title = "w1", Address = new AddressDto {CATOTTGId = 4970}}, + new Workshop + { + Id = new Guid("3a2fbb29-e097-4184-ad02-26ed1e5f5057"), + Title = "w2", + Address = new Address + { + CATOTTGId = 31737, + CATOTTG = new CATOTTG + { + Category = "K", + ParentId = null, + }, + }, + }, + new Workshop + { + Id = new Guid("953708d7-8c35-4607-bd9b-f034e853bb89"), + Title = "w1", + Address = new Address + { + CATOTTGId = 31739, + CATOTTG = new CATOTTG + { + Category = "B", + ParentId = 31737, + }, + }, + }, }; } diff --git a/OutOfSchool/OutOfSchool.WebApi/Services/StatisticService.cs b/OutOfSchool/OutOfSchool.WebApi/Services/StatisticService.cs index f5cc294080..afb8fa74b8 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Services/StatisticService.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Services/StatisticService.cs @@ -5,6 +5,7 @@ using AutoMapper; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; +using OutOfSchool.Common.Enums; using OutOfSchool.Redis; using OutOfSchool.Services.Enums; using OutOfSchool.Services.Models; @@ -168,7 +169,7 @@ public async Task> GetPopularWorkshopsFromDatabase(int if (catottgId > 0) { workshops = workshops - .Where(w => w.Address.CATOTTGId == catottgId); + .Where(w => w.Address.CATOTTGId == catottgId || (w.Address.CATOTTG.Category == CodeficatorCategory.CityDistrict.Name && w.Address.CATOTTG.ParentId == catottgId)); } var workshopsWithApplications = workshops.Select(w => new