Skip to content

Commit

Permalink
updated for laravel 9
Browse files Browse the repository at this point in the history
  • Loading branch information
sarthaksavvy committed Feb 9, 2022
1 parent 5742d64 commit 9a1e730
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 115 deletions.
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@
"prefer-stable": true,
"require": {
"intervention/image": "^2.6",
"laravel/sanctum": "^2.11",
"laravel/socialite": "^5.2",
"laravel/ui": "^3.3",
"laravel/sanctum": "^2.14",
"laravel/socialite": "^5.5",
"laravel/ui": "^3.4",
"tymon/jwt-auth": "1.0.2|dev-develop"
},
"require-dev": {
"phpunit/phpunit": "^9",
"phpunit/phpunit": "^8",
"mockery/mockery": "^1.3.1",
"orchestra/testbench": "^6",
"orchestra/database": "^6",
"illuminate/support": "^8.0",
"orchestra/testbench": "^6|^7",
"orchestra/database": "^6|^7",
"illuminate/support": "^8.0|^9",
"fzaninotto/faker": "^1.9",
"laravel/legacy-factories": "^1.0@dev"
},
Expand Down
216 changes: 108 additions & 108 deletions tests/Feature/RegisterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,118 +4,118 @@

use Bitfumes\ApiAuth\Tests\User;
use Bitfumes\ApiAuth\Tests\TestCase;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Notification;
use Bitfumes\ApiAuth\Notifications\VerifyEmail;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Support\Facades\Mail;

class RegisterTest extends TestCase
{
use DatabaseMigrations;

/** @test */
public function a_user_can_register_and_get_email_confirmation()
{
Notification::fake();
$res = $this->postJson(route('user.register'), [
'name' => 'sarthak',
'email' => '[email protected]',
'password' => 'secret123',
'password_confirmation' => 'secret123',
]);

$user = User::first();
Notification::assertSentTo($user, VerifyEmail::class);
// $this->assertNotNull(json_decode($res->getContent())->access_token);
$this->assertDatabaseHas('users', ['email'=>'[email protected]', 'email_verified_at'=>null]);
}

/** @test */
public function a_user_get_404_if_user_not_found_via_id_while_verifying_email()
{
$this->postJson(route('verification.verify', $notInDBUserId = 4000), ['signature'=>'random'])->assertStatus(404);
}

/** @test */
public function user_can_resend_verify_email()
{
Notification::fake();
$user = factory(User::class)->create();
$this->postJson(route('verification.resend', $user->toArray()));
Notification::assertSentTo($user, VerifyEmail::class);
}

/** @test */
public function user_can_Verify_its_email()
{
Mail::fake();
$user = factory(User::class)->create();
$this->postJson(route('verification.verify', $user->id));
$this->assertNotNull($user->fresh()->email_verified_at);
}

/** @test */
public function for_registration_email_password_and_name_is_required()
{
$this->withExceptionHandling();
$res = $this->post(route('user.register'));
$res->assertSessionHasErrors(['email', 'password', 'name']);
}

/** @test */
public function for_registration_email_must_be_real_email()
{
$this->withExceptionHandling();
$res = $this->post(route('user.register'), ['email'=>'sarthak.com']);
$this->assertEquals(session('errors')->get('email')[0], 'The email must be a valid email address.');
}

/** @test */
public function for_registration_password_must_be_min_of_8_chars()
{
$this->withExceptionHandling();
$res = $this->post(route('user.register'), ['password'=>'abcd', 'password_confirmation'=>'abcd']);
$this->assertEquals(session('errors')->get('password')[0], 'The password must be at least 8 characters.');
}

/** @test */
public function for_registration_name_must_be_max_of_25_chars()
{
$this->withExceptionHandling();
$res = $this->post(route('user.register'), ['name'=>'ankur sarthak shrivastava savvy']);
$this->assertEquals(session('errors')->get('name')[0], 'The name must not be greater than 25 characters.');
}

/** @test */
public function a_user_can_login_with_email_and_password()
{
$user = factory(User::class)->create();
$res = $this->postJson(route('user.login'), ['email'=>$user->email, 'password'=>'secret123'])->json();
$this->assertEquals($user->email, auth()->user()->email);
$this->assertNotNull($res['access_token']);
}

/** @test */
public function for_login_email_password_required()
{
$this->withExceptionHandling();
$res = $this->post(route('user.login'));
$res->assertSessionHasErrors(['email', 'password']);
}

/** @test */
public function for_login_email_must_be_real_email()
{
$this->withExceptionHandling();
$res = $this->post(route('user.login'), ['email'=>'sarthak.com']);
$this->assertEquals(session('errors')->get('email')[0], 'The email must be a valid email address.');
}

/** @test */
public function for_login_password_must_be_min_of_8_chars()
{
$this->withExceptionHandling();
$res = $this->post(route('user.login'), ['password'=>'abcd', 'password_confirmation'=>'abcd']);
$this->assertEquals(session('errors')->get('password')[0], 'The password must be at least 8 characters.');
}
use DatabaseMigrations;

/** @test */
public function a_user_can_register_and_get_email_confirmation()
{
Notification::fake();
$res = $this->postJson(route('user.register'), [
'name' => 'sarthak',
'email' => '[email protected]',
'password' => 'secret123',
'password_confirmation' => 'secret123',
]);

$user = User::first();
Notification::assertSentTo($user, VerifyEmail::class);
// $this->assertNotNull(json_decode($res->getContent())->access_token);
$this->assertDatabaseHas('users', ['email' => '[email protected]', 'email_verified_at' => null]);
}

/** @test */
public function a_user_get_404_if_user_not_found_via_id_while_verifying_email()
{
$this->postJson(route('verification.verify', $notInDBUserId = 4000), ['signature' => 'random'])->assertStatus(404);
}

/** @test */
public function user_can_resend_verify_email()
{
Notification::fake();
$user = factory(User::class)->create();
$this->postJson(route('verification.resend', $user->toArray()));
Notification::assertSentTo($user, VerifyEmail::class);
}

/** @test */
public function user_can_Verify_its_email()
{
Mail::fake();
$user = factory(User::class)->create();
$this->postJson(route('verification.verify', $user->id));
$this->assertNotNull($user->fresh()->email_verified_at);
}

/** @test */
public function for_registration_email_password_and_name_is_required()
{
$this->withExceptionHandling();
$res = $this->post(route('user.register'));
$res->assertSessionHasErrors(['email', 'password', 'name']);
}

/** @test */
public function for_registration_email_must_be_real_email()
{
$this->withExceptionHandling();
$res = $this->post(route('user.register'), ['email' => 'sarthak.com']);
$this->assertEquals(session('errors')->get('email')[0], 'The email must be a valid email address.');
}

/** @test */
public function for_registration_password_must_be_min_of_8_chars()
{
$this->withExceptionHandling();
$res = $this->post(route('user.register'), ['password' => 'abcd', 'password_confirmation' => 'abcd']);
$this->assertEquals(session('errors')->get('password')[0], 'The password must be at least 8 characters.');
}

/** @test */
public function for_registration_name_must_be_max_of_25_chars()
{
$this->withExceptionHandling();
$res = $this->post(route('user.register'), ['name' => 'ankur sarthak shrivastava savvy']);
$this->assertEquals(session('errors')->get('name')[0], 'The name may not be greater than 25 characters.');
}

/** @test */
public function a_user_can_login_with_email_and_password()
{
$user = factory(User::class)->create();
$res = $this->postJson(route('user.login'), ['email' => $user->email, 'password' => 'secret123'])->json();
$this->assertEquals($user->email, auth()->user()->email);
$this->assertNotNull($res['access_token']);
}

/** @test */
public function for_login_email_password_required()
{
$this->withExceptionHandling();
$res = $this->post(route('user.login'));
$res->assertSessionHasErrors(['email', 'password']);
}

/** @test */
public function for_login_email_must_be_real_email()
{
$this->withExceptionHandling();
$res = $this->post(route('user.login'), ['email' => 'sarthak.com']);
$this->assertEquals(session('errors')->get('email')[0], 'The email must be a valid email address.');
}

/** @test */
public function for_login_password_must_be_min_of_8_chars()
{
$this->withExceptionHandling();
$res = $this->post(route('user.login'), ['password' => 'abcd', 'password_confirmation' => 'abcd']);
$this->assertEquals(session('errors')->get('password')[0], 'The password must be at least 8 characters.');
}
}

0 comments on commit 9a1e730

Please sign in to comment.