<?php

namespace Tests\Feature;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use App\Models\Worker;
use Illuminate\Support\Facades\Hash;
use Tests\TestCase;

class LoginCompanyTest extends TestCase
{
    use RefreshDatabase;

    public function test_login_company(): void
    {
        $companyUser = Worker::join('company_users','company_users.worker_id','=', 'workers.id')->where('role_id',1)->first();
        $this->assertTrue($companyUser==true, 'Fetch company admin');

        $user = Worker::where('email_address', $companyUser->email_address)->first();
        $password = '123456789';

        $this->assertTrue($user==true, 'User is existing with the provided email');

        if(Hash::check($password, $user->password)){
            $isLogin = true;
        }
        $this->assertTrue($isLogin, 'User is login');
    }
}
