diff --git a/tests/Feature/ApiTokenPermissionsTest.php b/tests/Feature/ApiTokenPermissionsTest.php deleted file mode 100644 index bcb5a82..0000000 --- a/tests/Feature/ApiTokenPermissionsTest.php +++ /dev/null @@ -1,45 +0,0 @@ -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')); - } -} diff --git a/tests/Feature/AuthenticationTest.php b/tests/Feature/AuthenticationTest.php deleted file mode 100644 index db371d2..0000000 --- a/tests/Feature/AuthenticationTest.php +++ /dev/null @@ -1,44 +0,0 @@ -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(); - } -} diff --git a/tests/Feature/BrowserSessionsTest.php b/tests/Feature/BrowserSessionsTest.php deleted file mode 100644 index c5f7755..0000000 --- a/tests/Feature/BrowserSessionsTest.php +++ /dev/null @@ -1,24 +0,0 @@ -actingAs(User::factory()->create()); - - Livewire::test(LogoutOtherBrowserSessionsForm::class) - ->set('password', 'password') - ->call('logoutOtherBrowserSessions') - ->assertSuccessful(); - } -} diff --git a/tests/Feature/CreateApiTokenTest.php b/tests/Feature/CreateApiTokenTest.php deleted file mode 100644 index cc1ef61..0000000 --- a/tests/Feature/CreateApiTokenTest.php +++ /dev/null @@ -1,39 +0,0 @@ -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')); - } -} diff --git a/tests/Feature/DeleteAccountTest.php b/tests/Feature/DeleteAccountTest.php deleted file mode 100644 index e2f55f6..0000000 --- a/tests/Feature/DeleteAccountTest.php +++ /dev/null @@ -1,46 +0,0 @@ -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()); - } -} diff --git a/tests/Feature/DeleteApiTokenTest.php b/tests/Feature/DeleteApiTokenTest.php deleted file mode 100644 index cedc01b..0000000 --- a/tests/Feature/DeleteApiTokenTest.php +++ /dev/null @@ -1,37 +0,0 @@ -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); - } -} diff --git a/tests/Feature/EmailVerificationTest.php b/tests/Feature/EmailVerificationTest.php deleted file mode 100644 index 2fa8eeb..0000000 --- a/tests/Feature/EmailVerificationTest.php +++ /dev/null @@ -1,72 +0,0 @@ -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()); - } -} diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php deleted file mode 100644 index 8364a84..0000000 --- a/tests/Feature/ExampleTest.php +++ /dev/null @@ -1,19 +0,0 @@ -get('/'); - - $response->assertStatus(200); - } -} diff --git a/tests/Feature/ItemMaster/ItemMasterApiTest.php b/tests/Feature/ItemMaster/ItemMasterApiTest.php index 882eb0e..149c0ab 100644 --- a/tests/Feature/ItemMaster/ItemMasterApiTest.php +++ b/tests/Feature/ItemMaster/ItemMasterApiTest.php @@ -5,10 +5,8 @@ use App\Models\ItemMaster\CustomTab; use App\Models\ItemMaster\ItemBomItem; use App\Models\ItemMaster\ItemField; -use App\Models\ItemMaster\ItemMasterField; use App\Models\ItemMaster\ItemPage; use App\Models\ItemMaster\ItemSection; -use App\Models\ItemMaster\SectionTemplate; use App\Models\ItemMaster\UnitOption; use App\Models\Members\User; use App\Models\Members\UserTenant; @@ -116,8 +114,8 @@ public function test_can_fetch_init_data(): void 'message', 'data' => [ 'pages', - 'sectionTemplates', - 'masterFields', + 'sections', + 'fields', 'customTabs', '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, - ]); - } } diff --git a/tests/Feature/PasswordConfirmationTest.php b/tests/Feature/PasswordConfirmationTest.php deleted file mode 100644 index abb4f95..0000000 --- a/tests/Feature/PasswordConfirmationTest.php +++ /dev/null @@ -1,44 +0,0 @@ -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(); - } -} diff --git a/tests/Feature/PasswordResetTest.php b/tests/Feature/PasswordResetTest.php deleted file mode 100644 index 90aac0f..0000000 --- a/tests/Feature/PasswordResetTest.php +++ /dev/null @@ -1,94 +0,0 @@ -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; - }); - } -} diff --git a/tests/Feature/ProfileInformationTest.php b/tests/Feature/ProfileInformationTest.php deleted file mode 100644 index 15656c2..0000000 --- a/tests/Feature/ProfileInformationTest.php +++ /dev/null @@ -1,36 +0,0 @@ -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); - } -} diff --git a/tests/Feature/RegistrationTest.php b/tests/Feature/RegistrationTest.php deleted file mode 100644 index e850635..0000000 --- a/tests/Feature/RegistrationTest.php +++ /dev/null @@ -1,53 +0,0 @@ -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)); - } -} diff --git a/tests/Feature/TwoFactorAuthenticationSettingsTest.php b/tests/Feature/TwoFactorAuthenticationSettingsTest.php deleted file mode 100644 index 3775ba7..0000000 --- a/tests/Feature/TwoFactorAuthenticationSettingsTest.php +++ /dev/null @@ -1,76 +0,0 @@ -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); - } -} diff --git a/tests/Feature/UpdatePasswordTest.php b/tests/Feature/UpdatePasswordTest.php deleted file mode 100644 index 4fda1b2..0000000 --- a/tests/Feature/UpdatePasswordTest.php +++ /dev/null @@ -1,62 +0,0 @@ -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)); - } -}