chore: 불필요한 테스트 정리

- Jetstream/Fortify 테스트 14개 삭제 (API-only 프로젝트)
- ItemMasterApiTest 수정:
  - 존재하지 않는 모델 테스트 제거 (ItemMasterField, SectionTemplate)
  - 응답 키 수정 (sectionTemplates→sections, masterFields→fields)
This commit is contained in:
2025-12-22 18:58:53 +09:00
parent b26fced069
commit c2e632548e
15 changed files with 2 additions and 881 deletions

View File

@@ -1,45 +0,0 @@
<?php
namespace Tests\Feature;
use App\Models\Members\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Str;
use Laravel\Jetstream\Features;
use Laravel\Jetstream\Http\Livewire\ApiTokenManager;
use Livewire\Livewire;
use Tests\TestCase;
class ApiTokenPermissionsTest extends TestCase
{
use RefreshDatabase;
public function test_api_token_permissions_can_be_updated(): void
{
if (! Features::hasApiFeatures()) {
$this->markTestSkipped('API support is not enabled.');
}
$this->actingAs($user = User::factory()->withPersonalTeam()->create());
$token = $user->tokens()->create([
'name' => 'Test Token',
'token' => Str::random(40),
'abilities' => ['create', 'read'],
]);
Livewire::test(ApiTokenManager::class)
->set(['managingPermissionsFor' => $token])
->set(['updateApiTokenForm' => [
'permissions' => [
'delete',
'missing-permission',
],
]])
->call('updateApiToken');
$this->assertTrue($user->fresh()->tokens->first()->can('delete'));
$this->assertFalse($user->fresh()->tokens->first()->can('read'));
$this->assertFalse($user->fresh()->tokens->first()->can('missing-permission'));
}
}

View File

@@ -1,44 +0,0 @@
<?php
namespace Tests\Feature;
use App\Models\Members\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AuthenticationTest extends TestCase
{
use RefreshDatabase;
public function test_login_screen_can_be_rendered(): void
{
$response = $this->get('/login');
$response->assertStatus(200);
}
public function test_users_can_authenticate_using_the_login_screen(): void
{
$user = User::factory()->create();
$response = $this->post('/login', [
'email' => $user->email,
'password' => 'password',
]);
$this->assertAuthenticated();
$response->assertRedirect(route('dashboard', absolute: false));
}
public function test_users_can_not_authenticate_with_invalid_password(): void
{
$user = User::factory()->create();
$this->post('/login', [
'email' => $user->email,
'password' => 'wrong-password',
]);
$this->assertGuest();
}
}

View File

@@ -1,24 +0,0 @@
<?php
namespace Tests\Feature;
use App\Models\Members\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laravel\Jetstream\Http\Livewire\LogoutOtherBrowserSessionsForm;
use Livewire\Livewire;
use Tests\TestCase;
class BrowserSessionsTest extends TestCase
{
use RefreshDatabase;
public function test_other_browser_sessions_can_be_logged_out(): void
{
$this->actingAs(User::factory()->create());
Livewire::test(LogoutOtherBrowserSessionsForm::class)
->set('password', 'password')
->call('logoutOtherBrowserSessions')
->assertSuccessful();
}
}

View File

@@ -1,39 +0,0 @@
<?php
namespace Tests\Feature;
use App\Models\Members\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laravel\Jetstream\Features;
use Laravel\Jetstream\Http\Livewire\ApiTokenManager;
use Livewire\Livewire;
use Tests\TestCase;
class CreateApiTokenTest extends TestCase
{
use RefreshDatabase;
public function test_api_tokens_can_be_created(): void
{
if (! Features::hasApiFeatures()) {
$this->markTestSkipped('API support is not enabled.');
}
$this->actingAs($user = User::factory()->withPersonalTeam()->create());
Livewire::test(ApiTokenManager::class)
->set(['createApiTokenForm' => [
'name' => 'Test Token',
'permissions' => [
'read',
'update',
],
]])
->call('createApiToken');
$this->assertCount(1, $user->fresh()->tokens);
$this->assertEquals('Test Token', $user->fresh()->tokens->first()->name);
$this->assertTrue($user->fresh()->tokens->first()->can('read'));
$this->assertFalse($user->fresh()->tokens->first()->can('delete'));
}
}

View File

@@ -1,46 +0,0 @@
<?php
namespace Tests\Feature;
use App\Models\Members\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laravel\Jetstream\Features;
use Laravel\Jetstream\Http\Livewire\DeleteUserForm;
use Livewire\Livewire;
use Tests\TestCase;
class DeleteAccountTest extends TestCase
{
use RefreshDatabase;
public function test_user_accounts_can_be_deleted(): void
{
if (! Features::hasAccountDeletionFeatures()) {
$this->markTestSkipped('Account deletion is not enabled.');
}
$this->actingAs($user = User::factory()->create());
$component = Livewire::test(DeleteUserForm::class)
->set('password', 'password')
->call('deleteUser');
$this->assertNull($user->fresh());
}
public function test_correct_password_must_be_provided_before_account_can_be_deleted(): void
{
if (! Features::hasAccountDeletionFeatures()) {
$this->markTestSkipped('Account deletion is not enabled.');
}
$this->actingAs($user = User::factory()->create());
Livewire::test(DeleteUserForm::class)
->set('password', 'wrong-password')
->call('deleteUser')
->assertHasErrors(['password']);
$this->assertNotNull($user->fresh());
}
}

View File

@@ -1,37 +0,0 @@
<?php
namespace Tests\Feature;
use App\Models\Members\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Str;
use Laravel\Jetstream\Features;
use Laravel\Jetstream\Http\Livewire\ApiTokenManager;
use Livewire\Livewire;
use Tests\TestCase;
class DeleteApiTokenTest extends TestCase
{
use RefreshDatabase;
public function test_api_tokens_can_be_deleted(): void
{
if (! Features::hasApiFeatures()) {
$this->markTestSkipped('API support is not enabled.');
}
$this->actingAs($user = User::factory()->withPersonalTeam()->create());
$token = $user->tokens()->create([
'name' => 'Test Token',
'token' => Str::random(40),
'abilities' => ['create', 'read'],
]);
Livewire::test(ApiTokenManager::class)
->set(['apiTokenIdBeingDeleted' => $token->id])
->call('deleteApiToken');
$this->assertCount(0, $user->fresh()->tokens);
}
}

View File

@@ -1,72 +0,0 @@
<?php
namespace Tests\Feature;
use App\Models\Members\User;
use Illuminate\Auth\Events\Verified;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\URL;
use Laravel\Fortify\Features;
use Tests\TestCase;
class EmailVerificationTest extends TestCase
{
use RefreshDatabase;
public function test_email_verification_screen_can_be_rendered(): void
{
if (! Features::enabled(Features::emailVerification())) {
$this->markTestSkipped('Email verification not enabled.');
}
$user = User::factory()->withPersonalTeam()->unverified()->create();
$response = $this->actingAs($user)->get('/email/verify');
$response->assertStatus(200);
}
public function test_email_can_be_verified(): void
{
if (! Features::enabled(Features::emailVerification())) {
$this->markTestSkipped('Email verification not enabled.');
}
Event::fake();
$user = User::factory()->unverified()->create();
$verificationUrl = URL::temporarySignedRoute(
'verification.verify',
now()->addMinutes(60),
['id' => $user->id, 'hash' => sha1($user->email)]
);
$response = $this->actingAs($user)->get($verificationUrl);
Event::assertDispatched(Verified::class);
$this->assertTrue($user->fresh()->hasVerifiedEmail());
$response->assertRedirect(route('dashboard', absolute: false).'?verified=1');
}
public function test_email_can_not_verified_with_invalid_hash(): void
{
if (! Features::enabled(Features::emailVerification())) {
$this->markTestSkipped('Email verification not enabled.');
}
$user = User::factory()->unverified()->create();
$verificationUrl = URL::temporarySignedRoute(
'verification.verify',
now()->addMinutes(60),
['id' => $user->id, 'hash' => sha1('wrong-email')]
);
$this->actingAs($user)->get($verificationUrl);
$this->assertFalse($user->fresh()->hasVerifiedEmail());
}
}

View File

@@ -1,19 +0,0 @@
<?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);
}
}

View File

@@ -5,10 +5,8 @@
use App\Models\ItemMaster\CustomTab; use App\Models\ItemMaster\CustomTab;
use App\Models\ItemMaster\ItemBomItem; use App\Models\ItemMaster\ItemBomItem;
use App\Models\ItemMaster\ItemField; use App\Models\ItemMaster\ItemField;
use App\Models\ItemMaster\ItemMasterField;
use App\Models\ItemMaster\ItemPage; use App\Models\ItemMaster\ItemPage;
use App\Models\ItemMaster\ItemSection; use App\Models\ItemMaster\ItemSection;
use App\Models\ItemMaster\SectionTemplate;
use App\Models\ItemMaster\UnitOption; use App\Models\ItemMaster\UnitOption;
use App\Models\Members\User; use App\Models\Members\User;
use App\Models\Members\UserTenant; use App\Models\Members\UserTenant;
@@ -116,8 +114,8 @@ public function test_can_fetch_init_data(): void
'message', 'message',
'data' => [ 'data' => [
'pages', 'pages',
'sectionTemplates', 'sections',
'masterFields', 'fields',
'customTabs', 'customTabs',
'unitOptions', 'unitOptions',
], ],
@@ -927,190 +925,4 @@ public function test_can_delete_item_bom_item(): void
]); ]);
} }
// ==================== SectionTemplate Tests ====================
public function test_can_list_section_templates(): void
{
SectionTemplate::create([
'title' => 'Test Template 1', 'type' => 'fields',
'description' => 'Test Description',
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$response = $this->authenticatedRequest('get', '/api/v1/item-master/section-templates');
$response->assertStatus(200)
->assertJsonStructure([
'success',
'message',
'data' => [
'*' => [
'id',
'title',
'description',
],
],
]);
}
public function test_can_create_section_template(): void
{
$response = $this->authenticatedRequest('post', '/api/v1/item-master/section-templates', [
'title' => 'New Template', 'type' => 'fields',
'description' => 'New Template Description',
]);
$response->assertStatus(200)
->assertJsonStructure([
'success',
'message',
'data' => [
'id',
'title',
'description',
],
]);
$this->assertDatabaseHas('section_templates', [
'title' => 'New Template', 'type' => 'fields',
'tenant_id' => $this->tenant->id,
]);
}
public function test_can_update_section_template(): void
{
$template = SectionTemplate::create([
'title' => 'Original Template', 'type' => 'fields',
'description' => 'Original Description',
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$response = $this->authenticatedRequest('put', "/api/v1/item-master/section-templates/{$template->id}", [
'title' => 'Updated Template',
'description' => 'Updated Description',
]);
$response->assertStatus(200);
$this->assertDatabaseHas('section_templates', [
'id' => $template->id,
'title' => 'Updated Template',
]);
}
public function test_can_delete_section_template(): void
{
$template = SectionTemplate::create([
'title' => 'Template to Delete', 'type' => 'fields',
'description' => 'Description',
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$response = $this->authenticatedRequest('delete', "/api/v1/item-master/section-templates/{$template->id}");
$response->assertStatus(200);
$this->assertSoftDeleted('section_templates', [
'id' => $template->id,
]);
}
// ==================== ItemMasterField Tests ====================
public function test_can_list_item_master_fields(): void
{
ItemMasterField::create([
'field_name' => 'test_field',
'field_type' => 'textbox',
'category' => 'general',
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$response = $this->authenticatedRequest('get', '/api/v1/item-master/master-fields');
$response->assertStatus(200)
->assertJsonStructure([
'success',
'message',
'data' => [
'*' => [
'id',
'field_name',
'field_type',
],
],
]);
}
public function test_can_create_item_master_field(): void
{
$response = $this->authenticatedRequest('post', '/api/v1/item-master/master-fields', [
'field_name' => 'new_field',
'field_type' => 'textbox',
]);
$response->assertStatus(200)
->assertJsonStructure([
'success',
'message',
'data' => [
'id',
'field_name',
'field_type',
],
]);
$this->assertDatabaseHas('item_master_fields', [
'field_name' => 'new_field',
'field_type' => 'textbox',
'tenant_id' => $this->tenant->id,
]);
}
public function test_can_update_item_master_field(): void
{
$field = ItemMasterField::create([
'field_name' => 'original_field',
'field_type' => 'textbox',
'category' => 'general',
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$response = $this->authenticatedRequest('put', "/api/v1/item-master/master-fields/{$field->id}", [
'field_name' => 'Updated Field',
'field_type' => 'number',
]);
$response->assertStatus(200);
$this->assertDatabaseHas('item_master_fields', [
'id' => $field->id,
'field_name' => 'Updated Field',
'field_type' => 'number',
]);
}
public function test_can_delete_item_master_field(): void
{
$field = ItemMasterField::create([
'field_name' => 'field_to_delete',
'field_type' => 'textbox',
'category' => 'general',
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$response = $this->authenticatedRequest('delete', "/api/v1/item-master/master-fields/{$field->id}");
$response->assertStatus(200);
$this->assertSoftDeleted('item_master_fields', [
'id' => $field->id,
]);
}
} }

View File

@@ -1,44 +0,0 @@
<?php
namespace Tests\Feature;
use App\Models\Members\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class PasswordConfirmationTest extends TestCase
{
use RefreshDatabase;
public function test_confirm_password_screen_can_be_rendered(): void
{
$user = User::factory()->withPersonalTeam()->create();
$response = $this->actingAs($user)->get('/user/confirm-password');
$response->assertStatus(200);
}
public function test_password_can_be_confirmed(): void
{
$user = User::factory()->create();
$response = $this->actingAs($user)->post('/user/confirm-password', [
'password' => 'password',
]);
$response->assertRedirect();
$response->assertSessionHasNoErrors();
}
public function test_password_is_not_confirmed_with_invalid_password(): void
{
$user = User::factory()->create();
$response = $this->actingAs($user)->post('/user/confirm-password', [
'password' => 'wrong-password',
]);
$response->assertSessionHasErrors();
}
}

View File

@@ -1,94 +0,0 @@
<?php
namespace Tests\Feature;
use App\Models\Members\User;
use Illuminate\Auth\Notifications\ResetPassword;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
use Laravel\Fortify\Features;
use Tests\TestCase;
class PasswordResetTest extends TestCase
{
use RefreshDatabase;
public function test_reset_password_link_screen_can_be_rendered(): void
{
if (! Features::enabled(Features::resetPasswords())) {
$this->markTestSkipped('Password updates are not enabled.');
}
$response = $this->get('/forgot-password');
$response->assertStatus(200);
}
public function test_reset_password_link_can_be_requested(): void
{
if (! Features::enabled(Features::resetPasswords())) {
$this->markTestSkipped('Password updates are not enabled.');
}
Notification::fake();
$user = User::factory()->create();
$this->post('/forgot-password', [
'email' => $user->email,
]);
Notification::assertSentTo($user, ResetPassword::class);
}
public function test_reset_password_screen_can_be_rendered(): void
{
if (! Features::enabled(Features::resetPasswords())) {
$this->markTestSkipped('Password updates are not enabled.');
}
Notification::fake();
$user = User::factory()->create();
$this->post('/forgot-password', [
'email' => $user->email,
]);
Notification::assertSentTo($user, ResetPassword::class, function (object $notification) {
$response = $this->get('/reset-password/'.$notification->token);
$response->assertStatus(200);
return true;
});
}
public function test_password_can_be_reset_with_valid_token(): void
{
if (! Features::enabled(Features::resetPasswords())) {
$this->markTestSkipped('Password updates are not enabled.');
}
Notification::fake();
$user = User::factory()->create();
$this->post('/forgot-password', [
'email' => $user->email,
]);
Notification::assertSentTo($user, ResetPassword::class, function (object $notification) use ($user) {
$response = $this->post('/reset-password', [
'token' => $notification->token,
'email' => $user->email,
'password' => 'password',
'password_confirmation' => 'password',
]);
$response->assertSessionHasNoErrors();
return true;
});
}
}

View File

@@ -1,36 +0,0 @@
<?php
namespace Tests\Feature;
use App\Models\Members\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laravel\Jetstream\Http\Livewire\UpdateProfileInformationForm;
use Livewire\Livewire;
use Tests\TestCase;
class ProfileInformationTest extends TestCase
{
use RefreshDatabase;
public function test_current_profile_information_is_available(): void
{
$this->actingAs($user = User::factory()->create());
$component = Livewire::test(UpdateProfileInformationForm::class);
$this->assertEquals($user->name, $component->state['name']);
$this->assertEquals($user->email, $component->state['email']);
}
public function test_profile_information_can_be_updated(): void
{
$this->actingAs($user = User::factory()->create());
Livewire::test(UpdateProfileInformationForm::class)
->set('state', ['name' => 'Test Name', 'email' => 'test@example.com'])
->call('updateProfileInformation');
$this->assertEquals('Test Name', $user->fresh()->name);
$this->assertEquals('test@example.com', $user->fresh()->email);
}
}

View File

@@ -1,53 +0,0 @@
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laravel\Fortify\Features;
use Laravel\Jetstream\Jetstream;
use Tests\TestCase;
class RegistrationTest extends TestCase
{
use RefreshDatabase;
public function test_registration_screen_can_be_rendered(): void
{
if (! Features::enabled(Features::registration())) {
$this->markTestSkipped('Registration support is not enabled.');
}
$response = $this->get('/register');
$response->assertStatus(200);
}
public function test_registration_screen_cannot_be_rendered_if_support_is_disabled(): void
{
if (Features::enabled(Features::registration())) {
$this->markTestSkipped('Registration support is enabled.');
}
$response = $this->get('/register');
$response->assertStatus(404);
}
public function test_new_users_can_register(): void
{
if (! Features::enabled(Features::registration())) {
$this->markTestSkipped('Registration support is not enabled.');
}
$response = $this->post('/register', [
'name' => 'Test User',
'email' => 'test@example.com',
'password' => 'password',
'password_confirmation' => 'password',
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature(),
]);
$this->assertAuthenticated();
$response->assertRedirect(route('dashboard', absolute: false));
}
}

View File

@@ -1,76 +0,0 @@
<?php
namespace Tests\Feature;
use App\Models\Members\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laravel\Fortify\Features;
use Laravel\Jetstream\Http\Livewire\TwoFactorAuthenticationForm;
use Livewire\Livewire;
use Tests\TestCase;
class TwoFactorAuthenticationSettingsTest extends TestCase
{
use RefreshDatabase;
public function test_two_factor_authentication_can_be_enabled(): void
{
if (! Features::canManageTwoFactorAuthentication()) {
$this->markTestSkipped('Two factor authentication is not enabled.');
}
$this->actingAs($user = User::factory()->create());
$this->withSession(['auth.password_confirmed_at' => time()]);
Livewire::test(TwoFactorAuthenticationForm::class)
->call('enableTwoFactorAuthentication');
$user = $user->fresh();
$this->assertNotNull($user->two_factor_secret);
$this->assertCount(8, $user->recoveryCodes());
}
public function test_recovery_codes_can_be_regenerated(): void
{
if (! Features::canManageTwoFactorAuthentication()) {
$this->markTestSkipped('Two factor authentication is not enabled.');
}
$this->actingAs($user = User::factory()->create());
$this->withSession(['auth.password_confirmed_at' => time()]);
$component = Livewire::test(TwoFactorAuthenticationForm::class)
->call('enableTwoFactorAuthentication')
->call('regenerateRecoveryCodes');
$user = $user->fresh();
$component->call('regenerateRecoveryCodes');
$this->assertCount(8, $user->recoveryCodes());
$this->assertCount(8, array_diff($user->recoveryCodes(), $user->fresh()->recoveryCodes()));
}
public function test_two_factor_authentication_can_be_disabled(): void
{
if (! Features::canManageTwoFactorAuthentication()) {
$this->markTestSkipped('Two factor authentication is not enabled.');
}
$this->actingAs($user = User::factory()->create());
$this->withSession(['auth.password_confirmed_at' => time()]);
$component = Livewire::test(TwoFactorAuthenticationForm::class)
->call('enableTwoFactorAuthentication');
$this->assertNotNull($user->fresh()->two_factor_secret);
$component->call('disableTwoFactorAuthentication');
$this->assertNull($user->fresh()->two_factor_secret);
}
}

View File

@@ -1,62 +0,0 @@
<?php
namespace Tests\Feature;
use App\Models\Members\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Hash;
use Laravel\Jetstream\Http\Livewire\UpdatePasswordForm;
use Livewire\Livewire;
use Tests\TestCase;
class UpdatePasswordTest extends TestCase
{
use RefreshDatabase;
public function test_password_can_be_updated(): void
{
$this->actingAs($user = User::factory()->create());
Livewire::test(UpdatePasswordForm::class)
->set('state', [
'current_password' => 'password',
'password' => 'new-password',
'password_confirmation' => 'new-password',
])
->call('updatePassword');
$this->assertTrue(Hash::check('new-password', $user->fresh()->password));
}
public function test_current_password_must_be_correct(): void
{
$this->actingAs($user = User::factory()->create());
Livewire::test(UpdatePasswordForm::class)
->set('state', [
'current_password' => 'wrong-password',
'password' => 'new-password',
'password_confirmation' => 'new-password',
])
->call('updatePassword')
->assertHasErrors(['current_password']);
$this->assertTrue(Hash::check('password', $user->fresh()->password));
}
public function test_new_passwords_must_match(): void
{
$this->actingAs($user = User::factory()->create());
Livewire::test(UpdatePasswordForm::class)
->set('state', [
'current_password' => 'password',
'password' => 'new-password',
'password_confirmation' => 'wrong-password',
])
->call('updatePassword')
->assertHasErrors(['password']);
$this->assertTrue(Hash::check('password', $user->fresh()->password));
}
}