diff --git a/Childrens-Social-Care-CPD-Tests/Core/Resources/ResourcesDynamicTagsSearchStategyTests.cs b/Childrens-Social-Care-CPD-Tests/Core/Resources/ResourcesDynamicTagsSearchStategyTests.cs index 5530c3bd..5e029f18 100644 --- a/Childrens-Social-Care-CPD-Tests/Core/Resources/ResourcesDynamicTagsSearchStategyTests.cs +++ b/Childrens-Social-Care-CPD-Tests/Core/Resources/ResourcesDynamicTagsSearchStategyTests.cs @@ -174,4 +174,45 @@ public async Task Invalid_Tags_Are_Sanitised(string value) //assert actual.SelectedTags.Should().NotContain(value); } + + [TestCase(ResourceSortOrder.UpdatedNewest)] + [TestCase(ResourceSortOrder.UpdatedOldest)] + public async Task SearchAsync_Paging_Should_Respect_SortOrder(ResourceSortOrder sortOrder) + { + // arrange + var results = new ResponseType() + { + ContentCollection = new ContentCollection() + { + Total = 11, + Items = new Collection() + { + new SearchResult(), + new SearchResult(), + new SearchResult(), + new SearchResult(), + new SearchResult(), + new SearchResult(), + new SearchResult(), + new SearchResult(), + new SearchResult(), + new SearchResult(), + new SearchResult(), + } + } + }; + SetSearchResults(results); + var query = new ResourcesQuery + { + Page = 2, + Tags = new string[] { "tag1" }, + SortOrder = sortOrder + }; + + // act + var actual = await _sut.SearchAsync(query); + + // assert + actual.PagingFormatString.Should().Contain($"sortOrder={(int)sortOrder}"); + } } diff --git a/Childrens-Social-Care-CPD-Tests/Core/Resources/ResourcesFixedTagsSearchStrategyTests.cs b/Childrens-Social-Care-CPD-Tests/Core/Resources/ResourcesFixedTagsSearchStrategyTests.cs index 80a62c27..4149bdbd 100644 --- a/Childrens-Social-Care-CPD-Tests/Core/Resources/ResourcesFixedTagsSearchStrategyTests.cs +++ b/Childrens-Social-Care-CPD-Tests/Core/Resources/ResourcesFixedTagsSearchStrategyTests.cs @@ -168,4 +168,44 @@ public async Task Invalid_Tags_Are_Sanitised(string value) //assert actual.SelectedTags.Should().NotContain(value); } + + [TestCase(ResourceSortOrder.UpdatedNewest)] + [TestCase(ResourceSortOrder.UpdatedOldest)] + public async Task SearchAsync_Paging_Should_Respect_SortOrder(ResourceSortOrder sortOrder) + { + // arrange + var results = new ResponseType() + { + ContentCollection = new ContentCollection() + { + Total = 11, + Items = new Collection() + { + new SearchResult(), + new SearchResult(), + new SearchResult(), + new SearchResult(), + new SearchResult(), + new SearchResult(), + new SearchResult(), + new SearchResult(), + new SearchResult(), + new SearchResult(), + new SearchResult(), + } + } + }; + SetSearchResults(results); + var query = new ResourcesQuery + { + Page = 2, + SortOrder = sortOrder + }; + + // act + var actual = await _sut.SearchAsync(query); + + // assert + actual.PagingFormatString.Should().Contain($"sortOrder={(int)sortOrder}"); + } } diff --git a/Childrens-Social-Care-CPD/Core/Resources/ResourcesDynamicTagsSearchStategy.cs b/Childrens-Social-Care-CPD/Core/Resources/ResourcesDynamicTagsSearchStategy.cs index 70bb49e3..6cf4a0c8 100644 --- a/Childrens-Social-Care-CPD/Core/Resources/ResourcesDynamicTagsSearchStategy.cs +++ b/Childrens-Social-Care-CPD/Core/Resources/ResourcesDynamicTagsSearchStategy.cs @@ -38,16 +38,18 @@ private static Tuple CalculatePageStats(SearchResourcesByTags.Res return Tuple.Create(totalResults, totalPages, Math.Min(page, totalPages)); } - private static string GetPagingFormatString(IEnumerable tags) + private static string GetPagingFormatString(IEnumerable tags, ResourceSortOrder sortOrder) { + var result = $"/resources-learning?page={{0}}&sortOrder={(int)sortOrder}"; + if (tags.Any()) { var tagStrings = tags.Select(x => $"tags={x}"); var allTags = string.Join("&", tagStrings); - return $"/resources-learning?page={{0}}&{allTags}"; + result += $"&{allTags}"; } - return $"/resources-learning?page={{0}}"; + return result; } public async Task SearchAsync(ResourcesQuery query, CancellationToken cancellationToken = default) @@ -82,7 +84,7 @@ public async Task SearchAsync(ResourcesQuery query, Canc currentPage, totalPages, totalResults, - GetPagingFormatString(query.Tags) + GetPagingFormatString(query.Tags, query.SortOrder) ); } } \ No newline at end of file diff --git a/Childrens-Social-Care-CPD/Core/Resources/ResourcesFixedTagsSearchStrategy.cs b/Childrens-Social-Care-CPD/Core/Resources/ResourcesFixedTagsSearchStrategy.cs index e6680f8b..c866fe44 100644 --- a/Childrens-Social-Care-CPD/Core/Resources/ResourcesFixedTagsSearchStrategy.cs +++ b/Childrens-Social-Care-CPD/Core/Resources/ResourcesFixedTagsSearchStrategy.cs @@ -51,16 +51,18 @@ private static Tuple CalculatePageStats(SearchResourcesByTags.Res return Tuple.Create(totalResults, totalPages, Math.Min(page, totalPages)); } - private static string GetPagingFormatString(int[] tags) + private static string GetPagingFormatString(int[] tags, ResourceSortOrder sortOrder) { + var result = $"/resources-learning?page={{0}}&sortOrder={(int)sortOrder}"; + if (tags.Any()) { var tagStrings = tags.Select(x => $"tags={x}"); var allTags = string.Join("&", tagStrings); - return $"/resources-learning?page={{0}}&{allTags}"; + result += $"&{allTags}"; } - return $"/resources-learning?page={{0}}"; + return result; } public async Task SearchAsync(ResourcesQuery query, CancellationToken cancellationToken = default) @@ -91,7 +93,7 @@ public async Task SearchAsync(ResourcesQuery query, Canc currentPage, totalPages, totalResults, - GetPagingFormatString(queryTags) + GetPagingFormatString(queryTags, query.SortOrder) ); } } \ No newline at end of file