Skip to content

Commit d9f1cef

Browse files
committed
Don't show unpublished posts when searching for tag
1 parent 419bb6f commit d9f1cef

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/LinkDotNet.Blog.Web/Features/SearchByTag/SearchByTagPage.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
{
2323
Tag = Uri.UnescapeDataString(Tag);
2424
blogPosts = (await BlogPostRepository.GetAllAsync(
25-
b => b.Tags.Any(t => t.Content == Tag),
25+
b => b.IsPublished && b.Tags.Any(t => t.Content == Tag),
2626
b => b.UpdatedDate))
2727
.ToList();
2828
}

tests/LinkDotNet.Blog.IntegrationTests/Web/Features/SearchByTag/SearchByTagPageTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public async Task ShouldOnlyDisplayTagsGivenByParameter()
2020
using var ctx = new TestContext();
2121
await AddBlogPostWithTagAsync("Tag 1");
2222
await AddBlogPostWithTagAsync("Tag 1");
23+
await AddBlogPostWithTagAsync("Tag 1", isPublished: false);
2324
await AddBlogPostWithTagAsync("Tag 2");
2425
ctx.Services.AddScoped(_ => Repository);
2526
ctx.Services.AddScoped(_ => Mock.Of<IUserRecordService>());
@@ -61,9 +62,9 @@ public void ShouldSetTitleToTag()
6162
pageTitle.Markup.Should().Be("Search for tag: Tag");
6263
}
6364

64-
private async Task AddBlogPostWithTagAsync(string tag)
65+
private async Task AddBlogPostWithTagAsync(string tag, bool isPublished = true)
6566
{
66-
var blogPost = new BlogPostBuilder().WithTags(tag).Build();
67+
var blogPost = new BlogPostBuilder().WithTags(tag).IsPublished(isPublished).Build();
6768
await DbContext.AddAsync(blogPost);
6869
await DbContext.SaveChangesAsync();
6970
}

0 commit comments

Comments
 (0)