Commit 13a3b6c4 authored by Jacob Priddy's avatar Jacob Priddy 👌
Browse files

Add status route

parent 666cf905
Pipeline #9244 passed with stages
in 2 minutes and 52 seconds
......@@ -60,4 +60,12 @@ class DoorController extends ApiController
return $this->respondStatus();
}
/**
* @return \Illuminate\Http\JsonResponse
*/
public function status(): JsonResponse
{
return $this->respondStatus();
}
}
......@@ -20,3 +20,5 @@ Route::get('ping', static function () {
});
Route::get('access/{doorcode}', [DoorController::class, 'access']);
Route::get('status', [DoorController::class, 'status']);
<?php
namespace Tests\Feature\Door;
use Carbon\Carbon;
use Source\Entities\Override;
use Illuminate\Testing\TestResponse;
use Source\Gateways\Overrides\OverridesRepository;
use Tests\Feature\AuthenticatesWithApplicationTestCase;
use Source\Gateways\Overrides\InMemoryOverridesRepository;
class DoorStatusTest extends AuthenticatesWithApplicationTestCase
{
/**
* @var \Source\Gateways\Overrides\InMemoryOverridesRepository
*/
protected InMemoryOverridesRepository $overrides;
protected TestResponse $response;
public function setUp(): void
{
parent::setUp();
$this->overrides = $this->app->make(OverridesRepository::class);
}
protected function handleTest(): void
{
$this->response = $this->getJson('/api/door/status', [
'Authorization' => 'Bearer ' . $this->doorToken
]);
}
/**
* @test
*/
public function it_denies_unauthenticated_doors(): void
{
$this->handleTest();
$this->response->assertStatus(401);
}
/**
* @test
* @throws \Source\Exceptions\EntityExistsException
*/
public function it_returns_nothing_if_there_are_no_statuses(): void
{
$this->authenticateAsDoor();
$this->handleTest();
$this->response->assertStatus(200);
$this->response->assertJson(['events' => []]);
}
/**
* @test
* @throws \Source\Exceptions\EntityExistsException
*/
public function it_gives_status_times(): void
{
$this->authenticateAsDoor();
$start = Carbon::now()->subMinute();
$end = Carbon::now()->addMinutes(10);
$this->overrides->addOverride(new Override(
0,
'',
1,
$this->authDoor->getId(),
Override::TYPE_OPEN,
$start,
$end
));
$this->handleTest();
$this->response->assertStatus(200);
$this->response->assertJson(['events' => [[
'begins_at' => $start->format('c'),
'ends_at' => $end->format('c'),
]]]);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment