diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml index 95c0139..ccf58a1 100644 --- a/.github/workflows/laravel.yml +++ b/.github/workflows/laravel.yml @@ -1,15 +1,34 @@ -name: Laravel +name: Laravel Tests on: push: - branches: [ "master" ] + branches: [ "master", "main" ] pull_request: - branches: [ "master" ] + +env: + DB_CONNECTION: mysql + DB_DATABASE: db_absensi_karyawan_test + DB_PASSWORD: null jobs: laravel-tests: - runs-on: ubuntu-latest + services: + mysql: + image: mysql:8.0 + env: + # The MySQL docker container requires these environment variables to be set + # so we can create and migrate the test database. + # See: https://hub.docker.com/_/mysql + MYSQL_ALLOW_EMPTY_PASSWORD: 1 + MYSQL_DATABASE: $DB_DATABASE + MYSQL_ROOT_PASSWORD: $DB_PASSWORD + ports: + # Opens port 3306 on service container and host + # https://docs.github.com/en/actions/using-containerized-services/about-service-containers + - 3306:3306 + # Before continuing, verify the mysql container is reachable from the ubuntu host + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 steps: - uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e @@ -24,12 +43,8 @@ jobs: run: php artisan key:generate - name: Directory Permissions run: chmod -R 777 storage bootstrap/cache - - name: Create Database - run: | - mkdir -p database - touch database/database.sqlite - name: Execute tests (Unit and Feature tests) via PHPUnit/Pest env: - DB_CONNECTION: sqlite - DB_DATABASE: database/database.sqlite + DB_CONNECTION: $DB_CONNECTION + DB_DATABASE: $DB_DATABASE run: php artisan test diff --git a/tests/Feature/AuthenticationTest.php b/tests/Feature/AuthenticationTest.php index 9244fff..e62cf1b 100644 --- a/tests/Feature/AuthenticationTest.php +++ b/tests/Feature/AuthenticationTest.php @@ -17,7 +17,19 @@ ]); $this->assertAuthenticated(); - $response->assertRedirect(route('dashboard', absolute: false)); + $response->assertRedirect('/'); +}); + +test('admin users can authenticate using the login screen', function () { + $user = User::factory()->admin()->create(); + + $response = $this->post('/login', [ + 'email' => $user->email, + 'password' => 'password', + ]); + + $this->assertAuthenticated(); + $response->assertRedirect('/admin'); }); test('users cannot authenticate with invalid password', function () { diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php index 8b5843f..bc81358 100644 --- a/tests/Feature/ExampleTest.php +++ b/tests/Feature/ExampleTest.php @@ -1,7 +1,7 @@ get('/'); + $response = $this->get('/login'); $response->assertStatus(200); }); diff --git a/tests/Feature/RegistrationTest.php b/tests/Feature/RegistrationTest.php index c102863..1559581 100644 --- a/tests/Feature/RegistrationTest.php +++ b/tests/Feature/RegistrationTest.php @@ -36,7 +36,7 @@ ]); $this->assertAuthenticated(); - $response->assertRedirect(route('dashboard', absolute: false)); + $response->assertRedirect('/dashboard'); })->skip(function () { return !Features::enabled(Features::registration()); }, 'Registration support is not enabled.');