first commit
This commit is contained in:
42
tests/Feature/Screenshots/CountTest.php
Normal file
42
tests/Feature/Screenshots/CountTest.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Screenshots;
|
||||
|
||||
use App\Models\Screenshot;
|
||||
use App\Models\User;
|
||||
use Tests\Facades\ScreenshotFactory;
|
||||
use Tests\Facades\UserFactory;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CountTest extends TestCase
|
||||
{
|
||||
private const URI = 'screenshots/count';
|
||||
|
||||
private const SCREENSHOTS_AMOUNT = 10;
|
||||
|
||||
private User $admin;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->admin = UserFactory::asAdmin()->withTokens()->create();
|
||||
|
||||
ScreenshotFactory::fake()->createMany(self::SCREENSHOTS_AMOUNT);
|
||||
}
|
||||
|
||||
public function test_count(): void
|
||||
{
|
||||
$response = $this->actingAs($this->admin)->getJson(self::URI);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['total' => Screenshot::count()]);
|
||||
}
|
||||
|
||||
public function test_unauthorized(): void
|
||||
{
|
||||
$response = $this->getJson(self::URI);
|
||||
|
||||
$response->assertUnauthorized();
|
||||
}
|
||||
}
|
||||
62
tests/Feature/Screenshots/CreateTest.php
Normal file
62
tests/Feature/Screenshots/CreateTest.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Screenshots;
|
||||
|
||||
use App\Models\TimeInterval;
|
||||
use App\Models\User;
|
||||
use Faker\Factory;
|
||||
use Illuminate\Http\Testing\File;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Storage;
|
||||
use Tests\Facades\IntervalFactory;
|
||||
use Tests\Facades\UserFactory;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CreateTest extends TestCase
|
||||
{
|
||||
private const URI = '/screenshots/create';
|
||||
|
||||
private User $admin;
|
||||
private File $screenshotFile;
|
||||
private TimeInterval $interval;
|
||||
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->admin = UserFactory::asAdmin()->withTokens()->create();
|
||||
|
||||
Storage::fake();
|
||||
|
||||
$screenshotName = Factory::create()->firstName . '.jpg';
|
||||
$this->screenshotFile = UploadedFile::fake()->image($screenshotName);
|
||||
|
||||
$this->interval = IntervalFactory::create();
|
||||
}
|
||||
|
||||
public function test_create(): void
|
||||
{
|
||||
$requestData = ['time_interval_id' => $this->interval->id, 'screenshot' => $this->screenshotFile];
|
||||
|
||||
$response = $this->actingAs($this->admin)->postJson(self::URI, $requestData);
|
||||
|
||||
$response->assertOk();
|
||||
$this->assertDatabaseHas('screenshots', $response->json('screenshot'));
|
||||
Storage::assertExists('uploads/screenshots/' . basename($response->json('screenshot.path')));
|
||||
}
|
||||
|
||||
public function test_unauthorized(): void
|
||||
{
|
||||
$response = $this->postJson(self::URI);
|
||||
|
||||
$response->assertUnauthorized();
|
||||
}
|
||||
|
||||
public function test_without_params(): void
|
||||
{
|
||||
$response = $this->actingAs($this->admin)->postJson(self::URI);
|
||||
|
||||
$response->assertValidationError();
|
||||
}
|
||||
}
|
||||
42
tests/Feature/Screenshots/ListTest.php
Normal file
42
tests/Feature/Screenshots/ListTest.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Screenshots;
|
||||
|
||||
use App\Models\Screenshot;
|
||||
use App\Models\User;
|
||||
use Tests\Facades\ScreenshotFactory;
|
||||
use Tests\Facades\UserFactory;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ListTest extends TestCase
|
||||
{
|
||||
private const URI = 'screenshots/list';
|
||||
|
||||
private const SCREENSHOTS_AMOUNT = 10;
|
||||
|
||||
private User $admin;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->admin = UserFactory::asAdmin()->withTokens()->create();
|
||||
|
||||
ScreenshotFactory::fake()->withRandomRelations()->createMany(self::SCREENSHOTS_AMOUNT);
|
||||
}
|
||||
|
||||
public function test_list(): void
|
||||
{
|
||||
$response = $this->actingAs($this->admin)->postJson(self::URI);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(Screenshot::all()->toArray());
|
||||
}
|
||||
|
||||
public function test_unauthorized(): void
|
||||
{
|
||||
$response = $this->getJson(self::URI);
|
||||
|
||||
$response->assertUnauthorized();
|
||||
}
|
||||
}
|
||||
51
tests/Feature/Screenshots/RemoveTest.php
Normal file
51
tests/Feature/Screenshots/RemoveTest.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Screenshots;
|
||||
|
||||
use App\Models\Screenshot;
|
||||
use App\Models\User;
|
||||
use Tests\Facades\ScreenshotFactory;
|
||||
use Tests\Facades\UserFactory;
|
||||
use Tests\TestCase;
|
||||
|
||||
class RemoveTest extends TestCase
|
||||
{
|
||||
private const URI = '/screenshots/remove';
|
||||
|
||||
private User $admin;
|
||||
|
||||
private Screenshot $screenshot;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->admin = UserFactory::asAdmin()->withTokens()->create();
|
||||
|
||||
$this->screenshot = ScreenshotFactory::fake()->create();
|
||||
}
|
||||
|
||||
public function test_remove(): void
|
||||
{
|
||||
$this->assertDatabaseHas('screenshots', $this->screenshot->toArray());
|
||||
|
||||
$response = $this->actingAs($this->admin)->postJson(self::URI, $this->screenshot->only('id'));
|
||||
|
||||
$response->assertOk();
|
||||
$this->assertSoftDeleted('screenshots', $this->screenshot->only('id'));
|
||||
}
|
||||
|
||||
public function test_unauthorized(): void
|
||||
{
|
||||
$response = $this->postJson(self::URI);
|
||||
|
||||
$response->assertUnauthorized();
|
||||
}
|
||||
|
||||
public function test_without_params(): void
|
||||
{
|
||||
$response = $this->actingAs($this->admin)->postJson(self::URI);
|
||||
|
||||
$response->assertValidationError();
|
||||
}
|
||||
}
|
||||
48
tests/Feature/Screenshots/ShowTest.php
Normal file
48
tests/Feature/Screenshots/ShowTest.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Screenshots;
|
||||
|
||||
use App\Models\Screenshot;
|
||||
use App\Models\User;
|
||||
use Tests\Facades\ScreenshotFactory;
|
||||
use Tests\Facades\UserFactory;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ShowTest extends TestCase
|
||||
{
|
||||
private const URI = '/screenshots/show';
|
||||
|
||||
private User $admin;
|
||||
private Screenshot $screenshot;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->admin = UserFactory::asAdmin()->withTokens()->create();
|
||||
|
||||
$this->screenshot = ScreenshotFactory::fake()->create();
|
||||
}
|
||||
|
||||
public function test_show(): void
|
||||
{
|
||||
$this->assertDatabaseHas('screenshots', $this->screenshot->toArray());
|
||||
|
||||
$response = $this->actingAs($this->admin)->postJson(self::URI, $this->screenshot->only('id'));
|
||||
$response->assertOk();
|
||||
}
|
||||
|
||||
public function test_unauthorized(): void
|
||||
{
|
||||
$response = $this->getJson(self::URI);
|
||||
|
||||
$response->assertUnauthorized();
|
||||
}
|
||||
|
||||
public function test_without_params(): void
|
||||
{
|
||||
$response = $this->actingAs($this->admin)->getJson(self::URI);
|
||||
|
||||
$response->assertValidationError();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user