Article controller was updated and tests updated
All checks were successful
continuous-integration/drone/pr Build is passing

This commit is contained in:
James Tombleson 2023-08-04 23:07:04 -07:00
parent 751bbd3a7b
commit a3085bb27f
2 changed files with 14 additions and 4 deletions

View File

@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Newsbot.Collector.Domain.Dto; using Newsbot.Collector.Domain.Dto;
using Newsbot.Collector.Domain.Entities;
using Newsbot.Collector.Domain.Interfaces; using Newsbot.Collector.Domain.Interfaces;
using Newsbot.Collector.Domain.Results; using Newsbot.Collector.Domain.Results;
@ -15,11 +16,13 @@ public class ArticlesController : ControllerBase
//private readonly ILogger<ArticlesController> _logger; //private readonly ILogger<ArticlesController> _logger;
private readonly IArticlesRepository _articles; private readonly IArticlesRepository _articles;
private readonly ISourcesRepository _sources; private readonly ISourcesRepository _sources;
private readonly IAuthorTable _author;
public ArticlesController(IArticlesRepository articles, ISourcesRepository sources) public ArticlesController(IArticlesRepository articles, ISourcesRepository sources, IAuthorTable author)
{ {
_articles = articles; _articles = articles;
_sources = sources; _sources = sources;
_author = author;
} }
[HttpGet(Name = "GetArticles")] [HttpGet(Name = "GetArticles")]
@ -59,11 +62,13 @@ public class ArticlesController : ControllerBase
{ {
var item = _articles.GetById(id); var item = _articles.GetById(id);
var sourceItem = _sources.GetById(item.SourceId); var sourceItem = _sources.GetById(item.SourceId);
var author = _author.GetBySourceIdAndNameAsync(sourceItem.Id, sourceItem.Name);
author.Wait();
return new OkObjectResult(new ArticleDetailsResult return new OkObjectResult(new ArticleDetailsResult
{ {
IsSuccessful = true, IsSuccessful = true,
Item = ArticleDetailsDto.Convert(item, sourceItem) Item = ArticleDetailsDto.Convert(item, sourceItem, author.Result)
}); });
} }

View File

@ -32,12 +32,15 @@ public class DiscordNotificationJobTest
PubDate = DateTime.Now, PubDate = DateTime.Now,
Thumbnail = "https://cdn.arstechnica.net/wp-content/uploads/2023/03/GettyImages-944827400-800x534.jpg", Thumbnail = "https://cdn.arstechnica.net/wp-content/uploads/2023/03/GettyImages-944827400-800x534.jpg",
Description = "Please work", Description = "Please work",
AuthorName = "No one knows"
}, },
new IconEntity() new IconEntity()
{ {
Id = Guid.NewGuid(), Id = Guid.NewGuid(),
FileName = "https://www.redditstatic.com/desktop2x/img/favicon/android-icon-192x192.png" FileName = "https://www.redditstatic.com/desktop2x/img/favicon/android-icon-192x192.png"
}, new AuthorEntity
{
Id = Guid.NewGuid(),
Name = "test"
}); });
webhookClient.SendMessage(msg); webhookClient.SendMessage(msg);
} }
@ -59,7 +62,6 @@ public class DiscordNotificationJobTest
Thumbnail = Thumbnail =
"https://cdn.arstechnica.net/wp-content/uploads/2023/03/GettyImages-944827400-800x534.jpg", "https://cdn.arstechnica.net/wp-content/uploads/2023/03/GettyImages-944827400-800x534.jpg",
Description = "Please work", Description = "Please work",
AuthorName = "No one knows",
CodeIsCommit = true CodeIsCommit = true
}, },
new SourceEntity new SourceEntity
@ -82,6 +84,9 @@ public class DiscordNotificationJobTest
{ {
CodeAllowCommits = false, CodeAllowCommits = false,
CodeAllowReleases = true CodeAllowReleases = true
}, new AuthorEntity
{
Name = "a"
}); });
Assert.Fail("Expected a error to come back."); Assert.Fail("Expected a error to come back.");
} }