Fix blog comment endpoint path and add regression test
This commit is contained in:
parent
0d3fbf22c3
commit
0fd9e40d67
4 changed files with 41 additions and 5 deletions
|
|
@ -183,6 +183,42 @@ public sealed class BlogApiTests : IClassFixture<BlogsWebServerFixture>
|
|||
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<BlogPost>();
|
||||
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()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<script src="~/js/comment.js" asp-append-version="true"></script>
|
||||
<script>
|
||||
$.psc.blogcomment.prototype.options.lang = '@System.Globalization.CultureInfo.CurrentUICulture.Name';
|
||||
$.psc.blogcomment.prototype.options.apictrlr = '/api/blogcomments';
|
||||
$.psc.blogcomment.prototype.options.apictrlr = '/api/v1/blogcomments';
|
||||
$.psc.blogcomment.prototype.options.authorId = '@User.GetUserId()';
|
||||
$.psc.blogcomment.prototype.options.authorName = '@User.GetUserName()';
|
||||
$(document).ready(function() {
|
||||
|
|
@ -23,7 +23,7 @@
|
|||
ReceiverId: @Model.Id
|
||||
}),
|
||||
error: function(xhr,data) {
|
||||
if (xhr.status=400)
|
||||
if (xhr.status === 400)
|
||||
{
|
||||
if (xhr.responseJSON)
|
||||
{
|
||||
|
|
@ -45,7 +45,7 @@ $('#commentValidation').html(
|
|||
var nnode = '<div data-type="blogcomment" data-id="'+data.id+'" data-allow-edit="True" data-allow-moderate="@ViewBag.moderatoFlag" data-date="'+data.dateCreated+'" data-username="@User.GetUserName()">'+comment+'</div>';
|
||||
$('#comments').append($(nnode).blogcomment())
|
||||
},
|
||||
url:'/api/blogcomments'
|
||||
url:'/api/v1/blogcomments'
|
||||
});
|
||||
});
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue