Files
shipping-portal/tests/Unit/EmailVerificationTest.php
T

102 lines
2.6 KiB
PHP

<?php
namespace Tests\Unit;
use App\Models\User;
use App\Providers\RouteServiceProvider;
use Illuminate\Auth\Events\Verified;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\URL;
use JWTAuth;
use Tests\TestCase;
class EmailVerificationTest extends TestCase
{
use RefreshDatabase;
public function test_check_existing_email()
{
$user = User::factory()->create();
$response = $this->post('api/v1/account/authentication/login/check_email', [
'email' => $user->email
]);
$response->assertStatus(200)
->assertSee("User found Successful")
->assertSee("Account Already Exists");
}
public function test_check_unknown_email()
{
$response = $this->post('api/v1/account/authentication/login/check_email', [
'email' => 'random_email@test.com'
]);
$response->assertStatus(404)
->assertSee("User found failed")
->assertSee("Unable to find any record based on the criteria provided");
}
//todo test post success email verification
public function test_email_verification()
{
$user = User::factory()->create();
//todo create a new email verification token, not post request method found
$response = $this->actingAs($user)->post('api/v1/account/email/verify', [
'token' => 'simple_string'
]);
//todo need to register notification services on IOC
$response->assertStatus(404);
}
public function test_resend_email()
{
$user = User::factory()->create();
//create a new email verification token, not post request method found
$response = $this->actingAs($user)->post('api/v1/account/email/verification/resend', [
'user_id' => $user->id
]);
$response->assertStatus(200)
->assertSee("Resend Verification Email Successful")
->assertSee("Successfully resent a new verification email");
}
public function test_change_email()
{
$user = User::factory()->create();
$token = JWTAuth::fromUser($user);
//create a new email verification token, not post request method found
$response = $this->withHeaders([
'Authorization' => 'Bearer ' . $token,
])->json('POST', 'api/v1/company/team/create', [
'email' => "newemail@test.abc"
]);
//todo add user payload to the response and assert json
$response->assertStatus(200)
->assertSee("Updated Email Successful")
->assertSee("Successfully updated email");
}
}