first commit

This commit is contained in:
Noor E Ilahi
2026-01-09 12:54:53 +05:30
commit 7ccf44f7da
1070 changed files with 113036 additions and 0 deletions

View 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();
}
}

View 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();
}
}

View 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();
}
}

View 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();
}
}

View 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();
}
}