From 0fd9e40d67db41055f16c192e930aafa0bad2fe5 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Mon, 10 Aug 2026 21:48:03 +0100 Subject: [PATCH] Fix blog comment endpoint path and add regression test --- src/Yavsc.Blogs.Tests/BlogApiTests.cs | 36 +++++++++++++++++++ .../Communicating/BlogspotController.cs | 2 +- .../ViewComponents/CommentViewComponent.cs | 2 +- src/Yavsc.Org/Views/Blogspot/Details.cshtml | 6 ++-- 4 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/Yavsc.Blogs.Tests/BlogApiTests.cs b/src/Yavsc.Blogs.Tests/BlogApiTests.cs index 7e725e4f..cc7aaec8 100644 --- a/src/Yavsc.Blogs.Tests/BlogApiTests.cs +++ b/src/Yavsc.Blogs.Tests/BlogApiTests.cs @@ -183,6 +183,42 @@ public sealed class BlogApiTests : IClassFixture Assert.Equal("tester", doc.RootElement[0].GetProperty("authorId").GetString()); } + [Fact] + public async Task PostBlogComment_returns_201_for_existing_post() + { + ResetDatabase(); + using var http = NewClient(subject: "tester"); + + var draft = new BlogPost + { + Id = 0, + Title = "Billet commentable", + AuthorId = "payload-attacker", + Article = "Contenu de test.", + DateCreated = DateTime.UtcNow, + DateModified = DateTime.UtcNow + }; + + var postResponse = await http.PostAsJsonAsync("/api/v1/blog", draft); + Assert.Equal(HttpStatusCode.Created, postResponse.StatusCode); + + var createdPost = await postResponse.Content.ReadFromJsonAsync(); + Assert.NotNull(createdPost); + + var commentResponse = await http.PostAsJsonAsync("/api/v1/blogcomments", new + { + Article = "Premier commentaire", + ReceiverId = createdPost!.Id + }); + + Assert.Equal(HttpStatusCode.Created, commentResponse.StatusCode); + + using var doc = JsonDocument.Parse(await commentResponse.Content.ReadAsStringAsync()); + Assert.True(doc.RootElement.TryGetProperty("id", out var id)); + Assert.True(id.GetInt64() > 0); + Assert.True(doc.RootElement.TryGetProperty("dateCreated", out _)); + } + [Fact] public void GetUserId_reads_NameIdentifier_when_sub_was_mapped() { diff --git a/src/Yavsc.Org/Controllers/Communicating/BlogspotController.cs b/src/Yavsc.Org/Controllers/Communicating/BlogspotController.cs index de0c3c2d..8e2c9e5b 100644 --- a/src/Yavsc.Org/Controllers/Communicating/BlogspotController.cs +++ b/src/Yavsc.Org/Controllers/Communicating/BlogspotController.cs @@ -71,7 +71,7 @@ namespace Yavsc.Org.Controllers try { var blog = await blogSpotService.Details(User, id.Value); - ViewBag.apicmtctlr = "/api/blogcomments"; + ViewBag.apicmtctlr = "/api/v1/blogcomments"; ViewBag.moderatoFlag = User.IsInMsRole(YavscConstants.BlogModeratorGroupName); return View(blog); diff --git a/src/Yavsc.Org/ViewComponents/CommentViewComponent.cs b/src/Yavsc.Org/ViewComponents/CommentViewComponent.cs index 6752de94..62d3bb7a 100644 --- a/src/Yavsc.Org/ViewComponents/CommentViewComponent.cs +++ b/src/Yavsc.Org/ViewComponents/CommentViewComponent.cs @@ -23,7 +23,7 @@ namespace Yavsc.ViewComponents var comment = await context.Comment.Include(c=>c.Children).FirstOrDefaultAsync(c => c.Id==id); if (comment == null) throw new InvalidOperationException(); - ViewBag.apictlr = "/api/blogcomments"; + ViewBag.apictlr = "/api/v1/blogcomments"; return View("Default", comment); } diff --git a/src/Yavsc.Org/Views/Blogspot/Details.cshtml b/src/Yavsc.Org/Views/Blogspot/Details.cshtml index d7d5a791..dc0bea8a 100644 --- a/src/Yavsc.Org/Views/Blogspot/Details.cshtml +++ b/src/Yavsc.Org/Views/Blogspot/Details.cshtml @@ -7,7 +7,7 @@