incr/tests/Feature/TrackerTest.php

61 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature;
use App\Models\Tracker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class TrackerTest extends TestCase
{
use RefreshDatabase;
public function test_show_reports_no_tracker_on_a_fresh_install(): void
{
$this->getJson('/tracker')
->assertOk()
->assertJson(['exists' => false]);
}
public function test_show_returns_the_tracker_once_created(): void
{
Tracker::factory()->create(['count' => 9]);
$this->getJson('/tracker')
->assertOk()
->assertJson([
'exists' => true,
'tracker' => ['count' => 9],
]);
}
public function test_a_tracker_can_be_created_without_a_label_or_unit(): void
{
$this->postJson('/tracker', [])->assertCreated();
$tracker = Tracker::first();
$this->assertSame('Counter', $tracker->label);
$this->assertSame('units', $tracker->unit);
$this->assertSame(0, $tracker->count);
}
public function test_a_new_counter_starts_at_zero(): void
{
$this->postJson('/tracker', []);
$this->getJson('/tracker')
->assertOk()
->assertJson(['tracker' => ['count' => 0]]);
}
public function test_creating_a_second_tracker_conflicts(): void
{
$this->postJson('/tracker', [])->assertCreated();
$this->postJson('/tracker', [])->assertStatus(409);
$this->assertSame(1, Tracker::count());
}
}