Skip to content

Commit

Permalink
Tidy up old Resource search code
Browse files Browse the repository at this point in the history
  • Loading branch information
killij committed Jan 8, 2024
1 parent a8ab2cc commit 3865b18
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,42 @@ public async Task Index_Passes_Correctly_Tagged_Properties()
properties["From"].Should().Be("Virtual Hubs");
}

[TestCase("Topic", "Topic Text")]
[TestCase("From", "From Text")]
[TestCase("Estimated reading time", "15 mins")]
public async Task Index_Passes_Properties(string key, string value)
{
// arrange
var createdAt = DateTime.UtcNow.AddMinutes(-10);
var updatedAt = DateTime.UtcNow;
var content = new Content
{
EstimatedReadingTime = 15,
Sys = new()
{
CreatedAt = createdAt,
UpdatedAt = updatedAt,
}
};
var tags = CreateTagsResponse(new()
{
new() { Id = "topicTopicText", Name = "Topic: Topic Text" },
new() { Id = "resourceProviderFromText", Name = "Resource provider: From Text" },
new() { Id = "estimatedReadingTime15", Name = "Estimated reading time: 15 mins" },
});

_resourcesRepository.GetByIdAsync(Arg.Any<string>(), cancellationToken: Arg.Any<CancellationToken>())
.Returns(Task.FromResult(Tuple.Create(content, tags)));

// act
var result = await _resourcesController.Index("foo") as ViewResult;
var properties = result.ViewData["Properties"] as IDictionary<string, string>;

// assert
properties.Should().NotBeNull();
properties[key].Should().Be(value);
}

[Test]
public async Task Index_Ignores_Unrelated_Tags_For_Properties()
{
Expand All @@ -177,7 +213,7 @@ public async Task Index_Ignores_Unrelated_Tags_For_Properties()
UpdatedAt = updatedAt,
}
};
var tags = CreateTagsResponse(new() { new() { Id = "foo", Name = "Topic:Foo=foo" }, });
var tags = CreateTagsResponse(new() { new() { Id = "foo", Name = "Foo: Some value" }, });

_resourcesRepository.GetByIdAsync(Arg.Any<string>(), cancellationToken: Arg.Any<CancellationToken>())
.Returns(Task.FromResult(Tuple.Create(content, tags)));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Childrens_Social_Care_CPD.Configuration;
using Childrens_Social_Care_CPD.Contentful;
using Childrens_Social_Care_CPD.Contentful.Models;
using Childrens_Social_Care_CPD.Controllers;
using Childrens_Social_Care_CPD.Search;
using Childrens_Social_Care_CPD.GraphQL.Queries;
using Contentful.Core.Search;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using Azure.Search.Documents.Models;
using Childrens_Social_Care_CPD.Contentful.Models;
using Childrens_Social_Care_CPD.Search;
using System.Diagnostics.CodeAnalysis;

namespace Childrens_Social_Care_CPD.Models;

[ExcludeFromCodeCoverage]
public record ResourceSearchResultsViewModel(
Content PageContent,
string SearchTerm,
Expand Down
24 changes: 0 additions & 24 deletions Childrens-Social-Care-CPD/Models/ResourcesListViewModel.cs

This file was deleted.

2 changes: 2 additions & 0 deletions Childrens-Social-Care-CPD/Models/SearchRequestModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics.CodeAnalysis;

namespace Childrens_Social_Care_CPD.Models;

Expand All @@ -17,6 +18,7 @@ public static class SearchRequestPropertyNames
public const string SortOrder = "so";
}

[ExcludeFromCodeCoverage]
public record SearchRequestModel
{
[BindProperty(Name = SearchRequestPropertyNames.Term, SupportsGet = true)]
Expand Down
2 changes: 2 additions & 0 deletions Childrens-Social-Care-CPD/Models/SearchResultViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Azure.Search.Documents.Models;
using Childrens_Social_Care_CPD.Search;
using System.Diagnostics.CodeAnalysis;

namespace Childrens_Social_Care_CPD.Models;

[ExcludeFromCodeCoverage]
public record SearchResultViewModel(SearchResult<CpdDocument> SearchResult, IReadOnlyDictionary<string, TagInfo> TagMap);
13 changes: 0 additions & 13 deletions Childrens-Social-Care-CPD/Views/Shared/_SortSelection.cshtml

This file was deleted.

0 comments on commit 3865b18

Please sign in to comment.