Initial commit
This commit is contained in:
34
api/tests/Feature/AuthTest.php
Normal file
34
api/tests/Feature/AuthTest.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
test('login fails with invalid credentials', function () {
|
||||
$response = test()->postJson('/api/auth/login', [
|
||||
'email' => 'wrong@example.com',
|
||||
'password' => 'wrong',
|
||||
]);
|
||||
|
||||
$response->assertStatus(422);
|
||||
});
|
||||
|
||||
test('login succeeds with valid credentials', function () {
|
||||
User::factory()->create([
|
||||
'email' => 'admin@test.com',
|
||||
'password' => Hash::make('secret'),
|
||||
]);
|
||||
|
||||
$response = test()->postJson('/api/auth/login', [
|
||||
'email' => 'admin@test.com',
|
||||
'password' => 'secret',
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonPath('user.email', 'admin@test.com');
|
||||
});
|
||||
|
||||
test('auth user returns 401 when unauthenticated', function () {
|
||||
$response = test()->getJson('/api/auth/user');
|
||||
|
||||
$response->assertStatus(401);
|
||||
});
|
||||
19
api/tests/Feature/ExampleTest.php
Normal file
19
api/tests/Feature/ExampleTest.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
// use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ExampleTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* A basic test example.
|
||||
*/
|
||||
public function test_the_application_returns_a_successful_response(): void
|
||||
{
|
||||
$response = $this->get('/');
|
||||
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
}
|
||||
41
api/tests/Feature/PublicEventTest.php
Normal file
41
api/tests/Feature/PublicEventTest.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Event;
|
||||
use App\Models\User;
|
||||
|
||||
test('public event show returns event info without password', function () {
|
||||
$user = User::factory()->create();
|
||||
Event::create([
|
||||
'user_id' => $user->id,
|
||||
'name' => 'Test Event',
|
||||
'slug' => 'test-event',
|
||||
'is_active' => true,
|
||||
'max_file_size_mb' => 500,
|
||||
'allowed_extensions' => ['mp4', 'mov'],
|
||||
'require_password' => true,
|
||||
'upload_password' => 'secret',
|
||||
]);
|
||||
|
||||
$response = test()->getJson('/api/events/test-event');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonPath('name', 'Test Event');
|
||||
$response->assertJsonPath('slug', 'test-event');
|
||||
$response->assertJsonPath('require_password', true);
|
||||
$response->assertJsonPath('has_password', true);
|
||||
$response->assertJsonMissing(['upload_password']);
|
||||
});
|
||||
|
||||
test('public event show returns 404 for inactive event', function () {
|
||||
$user = User::factory()->create();
|
||||
Event::create([
|
||||
'user_id' => $user->id,
|
||||
'name' => 'Inactive',
|
||||
'slug' => 'inactive-event',
|
||||
'is_active' => false,
|
||||
]);
|
||||
|
||||
$response = test()->getJson('/api/events/inactive-event');
|
||||
|
||||
$response->assertStatus(404);
|
||||
});
|
||||
6
api/tests/Pest.php
Normal file
6
api/tests/Pest.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
uses(TestCase::class, RefreshDatabase::class)->in('Feature');
|
||||
10
api/tests/TestCase.php
Normal file
10
api/tests/TestCase.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
||||
|
||||
abstract class TestCase extends BaseTestCase
|
||||
{
|
||||
//
|
||||
}
|
||||
16
api/tests/Unit/ExampleTest.php
Normal file
16
api/tests/Unit/ExampleTest.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ExampleTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* A basic test example.
|
||||
*/
|
||||
public function test_that_true_is_true(): void
|
||||
{
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user