<?php

namespace Tests\Feature\Accounts;

use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class CheckEmailControllerTest extends TestCase
{
    use DatabaseMigrations;

    public function testExistingUserEmail()
    {
        // create a user
        $response = $this->postJson(route('api.account.registration.register', [
            "company_name" => "",
            "name" => "user one",
            "email" => "user1@mail.com",
            "password" => "password",
            "password_confirmation" => "password",
            "phone" => "0123456789",
            "type" => 0
        ]));

        $response = $this->postJson(route('api.account.authentication.authenticate.email.check', [
            'email' => 'user1@mail.com',
        ]));

        $response->assertStatus(200)->assertJson([
            "title" => "User found Successful",
            "message" => "Account Already Exists",
            "payload" => []
        ]);
    }

    public function testNonExistingUserEmail()
    {
        $response = $this->postJson(route('api.account.authentication.authenticate.email.check', [
            'email' => 'user2@mail.com',
        ]));

        // dd($response);

        $response->assertStatus(404)->assertJson([
            "title" => "User found failed",
            "message" => "Unable to find any record based on the criteria provided",
            "payload" => []
        ]);
    }
}
