Shifts feed: Added URL to shift and shifttype name & description

This commit is contained in:
Igor Scheller 2023-10-17 19:41:08 +02:00
parent 24204b1f3c
commit a31534d9b7
2 changed files with 22 additions and 9 deletions

View File

@ -8,6 +8,7 @@ use Carbon\CarbonTimeZone;
use Engelsystem\Helpers\Authenticator; use Engelsystem\Helpers\Authenticator;
use Engelsystem\Http\Request; use Engelsystem\Http\Request;
use Engelsystem\Http\Response; use Engelsystem\Http\Response;
use Engelsystem\Http\UrlGenerator;
use Engelsystem\Models\News; use Engelsystem\Models\News;
use Engelsystem\Models\Shifts\ShiftEntry; use Engelsystem\Models\Shifts\ShiftEntry;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
@ -26,6 +27,7 @@ class FeedController extends BaseController
protected Authenticator $auth, protected Authenticator $auth,
protected Request $request, protected Request $request,
protected Response $response, protected Response $response,
protected UrlGenerator $url,
) { ) {
} }
@ -74,16 +76,22 @@ class FeedController extends BaseController
'name' => $shift->shiftType->name, 'name' => $shift->shiftType->name,
// Shift / Talk title // Shift / Talk title
'title' => $shift->title, 'title' => $shift->title,
// Shift description // Shift description, should be shown after shifttype_description, markdown formatted
'description' => $shift->description, 'description' => $shift->description,
'link' => $this->url->to('/shifts', ['action' => 'view', 'shift_id' => $shift->id]),
// Users comment // Users comment
'Comment' => $entry->user_comment, 'Comment' => $entry->user_comment,
// Shift id // Shift id
'SID' => $shift->id, 'SID' => $shift->id,
// Shift type id
// Shift type
'shifttype_id' => $shift->shiftType->id, 'shifttype_id' => $shift->shiftType->id,
'shifttype_name' => $shift->shiftType->name, // General type of the task
'shifttype_description' => $shift->shiftType->description, // General description, markdown formatted
// Talk URL // Talk URL
'URL' => $shift->url, 'URL' => $shift->url,

View File

@ -7,6 +7,7 @@ namespace Engelsystem\Test\Unit\Controllers;
use Engelsystem\Controllers\FeedController; use Engelsystem\Controllers\FeedController;
use Engelsystem\Helpers\Authenticator; use Engelsystem\Helpers\Authenticator;
use Engelsystem\Helpers\Carbon; use Engelsystem\Helpers\Carbon;
use Engelsystem\Http\UrlGenerator;
use Engelsystem\Models\News; use Engelsystem\Models\News;
use Engelsystem\Models\Shifts\ShiftEntry; use Engelsystem\Models\Shifts\ShiftEntry;
use Engelsystem\Models\User\User; use Engelsystem\Models\User\User;
@ -18,6 +19,7 @@ use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
class FeedControllerTest extends ControllerTest class FeedControllerTest extends ControllerTest
{ {
protected Authenticator|MockObject $auth; protected Authenticator|MockObject $auth;
protected UrlGenerator|MockObject $url;
/** /**
* @covers \Engelsystem\Controllers\FeedController::__construct * @covers \Engelsystem\Controllers\FeedController::__construct
@ -26,7 +28,7 @@ class FeedControllerTest extends ControllerTest
*/ */
public function testAtom(): void public function testAtom(): void
{ {
$controller = new FeedController($this->auth, $this->request, $this->response); $controller = new FeedController($this->auth, $this->request, $this->response, $this->url);
$this->setExpects( $this->setExpects(
$this->response, $this->response,
@ -57,7 +59,7 @@ class FeedControllerTest extends ControllerTest
*/ */
public function testRss(): void public function testRss(): void
{ {
$controller = new FeedController($this->auth, $this->request, $this->response); $controller = new FeedController($this->auth, $this->request, $this->response, $this->url);
$this->setExpects( $this->setExpects(
$this->response, $this->response,
@ -90,7 +92,7 @@ class FeedControllerTest extends ControllerTest
new Session(new MockArraySessionStorage()), new Session(new MockArraySessionStorage()),
new User(), new User(),
); );
$controller = new FeedController($this->auth, $this->request, $this->response); $controller = new FeedController($this->auth, $this->request, $this->response, $this->url);
/** @var User $user */ /** @var User $user */
$user = User::factory()->create(['api_key' => 'fo0']); $user = User::factory()->create(['api_key' => 'fo0']);
@ -136,7 +138,8 @@ class FeedControllerTest extends ControllerTest
new Session(new MockArraySessionStorage()), new Session(new MockArraySessionStorage()),
new User(), new User(),
); );
$controller = new FeedController($this->auth, $this->request, $this->response); $controller = new FeedController($this->auth, $this->request, $this->response, $this->url);
$this->setExpects($this->url, 'to', null, 'https://host/shift/1337', $this->atLeastOnce());
/** @var User $user */ /** @var User $user */
$user = User::factory()->create(['api_key' => 'fo0']); $user = User::factory()->create(['api_key' => 'fo0']);
@ -165,7 +168,8 @@ class FeedControllerTest extends ControllerTest
[ [
'name', 'title', 'description', 'name', 'title', 'description',
'Comment', 'Comment',
'SID', 'shifttype_id', 'URL', 'SID', 'shifttype_id', 'URL', 'link',
'shifttype_name', 'shifttype_description',
'RID', 'Name', 'map_url', 'RID', 'Name', 'map_url',
'start', 'start_date', 'end', 'end_date', 'start', 'start_date', 'end', 'end_date',
'timezone', 'event_timezone', 'timezone', 'event_timezone',
@ -195,7 +199,7 @@ class FeedControllerTest extends ControllerTest
*/ */
public function testGetNewsMeetings(bool $isMeeting): void public function testGetNewsMeetings(bool $isMeeting): void
{ {
$controller = new FeedController($this->auth, $this->request, $this->response); $controller = new FeedController($this->auth, $this->request, $this->response, $this->url);
$this->request->attributes->set('meetings', $isMeeting); $this->request->attributes->set('meetings', $isMeeting);
$this->setExpects($this->response, 'withHeader', null, $this->response); $this->setExpects($this->response, 'withHeader', null, $this->response);
@ -223,7 +227,7 @@ class FeedControllerTest extends ControllerTest
public function testGetNewsLimit(): void public function testGetNewsLimit(): void
{ {
News::query()->where('id', '<>', 1)->update(['updated_at' => Carbon::now()->subHour()]); News::query()->where('id', '<>', 1)->update(['updated_at' => Carbon::now()->subHour()]);
$controller = new FeedController($this->auth, $this->request, $this->response); $controller = new FeedController($this->auth, $this->request, $this->response, $this->url);
$this->setExpects($this->response, 'withHeader', null, $this->response); $this->setExpects($this->response, 'withHeader', null, $this->response);
$this->setExpects($this->response, 'setEtag', null, $this->response); $this->setExpects($this->response, 'setEtag', null, $this->response);
@ -250,6 +254,7 @@ class FeedControllerTest extends ControllerTest
$this->config->set('display_news', 10); $this->config->set('display_news', 10);
$this->auth = $this->createMock(Authenticator::class); $this->auth = $this->createMock(Authenticator::class);
$this->url = $this->createMock(UrlGenerator::class);
News::factory(7)->create(['is_meeting' => false]); News::factory(7)->create(['is_meeting' => false]);
News::factory(5)->create(['is_meeting' => true]); News::factory(5)->create(['is_meeting' => true]);