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