feat: move pelelong berlesen functions to operasi and update login and reports (#4)

Co-authored-by: nurafrinaalimi16 <nurafrinaalimi16@gmail.com>
Reviewed-on: #4
This commit was merged in pull request #4.
This commit is contained in:
2026-10-06 11:26:49 +08:00
parent 56ebb153b5
commit b1d393b1a1
37 changed files with 837 additions and 1318 deletions
+69
View File
@@ -0,0 +1,69 @@
<?php
namespace Tests\Feature;
use App\Models\User;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Route;
use Tests\TestCase;
class InactiveAccountTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
config(['database.default' => 'sqlite', 'database.connections.sqlite.database' => ':memory:',
'session.driver' => 'array', 'cache.default' => 'array']);
DB::purge('sqlite');
DB::statement('CREATE TABLE users (id INTEGER PRIMARY KEY, username TEXT, password TEXT, status TEXT, remember_token TEXT, created_at TEXT, updated_at TEXT)');
Route::middleware('web')->get('/account-status-test', function () {
return response('allowed');
});
}
private function account($status)
{
return User::create(['username' => 'status-test', 'password' => Hash::make('test-password'), 'status' => $status]);
}
public function test_inactive_and_banned_accounts_cannot_log_in()
{
foreach (['inactive', 'banned'] as $status) {
DB::table('users')->delete();
$this->account($status);
$this->post('/login', ['username' => 'status-test', 'password' => 'test-password'])
->assertSessionHasErrors('username');
$this->assertGuest('web');
}
}
public function test_active_account_can_log_in()
{
$user = $this->account('active');
$this->post('/login', ['username' => 'status-test', 'password' => 'test-password'])
->assertRedirect('/home');
$this->assertAuthenticatedAs($user, 'web');
}
public function test_inactive_session_is_logged_out_and_cleared()
{
$user = $this->account('inactive');
$this->actingAs($user, 'web')->withSession(['private-data' => 'remove'])
->get('/account-status-test')->assertRedirect('/login')->assertSessionMissing('private-data');
$this->assertGuest('web');
}
public function test_inactive_json_session_is_denied()
{
$this->actingAs($this->account('inactive'), 'web')
->getJson('/account-status-test')->assertStatus(403);
$this->assertGuest('web');
}
public function test_active_session_and_guest_can_continue()
{
$this->get('/account-status-test')->assertOk();
$this->actingAs($this->account('active'), 'web')->get('/account-status-test')->assertOk();
}
}