Created
January 2, 2022 10:53
-
-
Save abdullahnaseer/acfccd62b753af03b922b33292b5770c to your computer and use it in GitHub Desktop.
Customer Store Test - Evaluation of Laravel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Tests\Unit; | |
use App\Mail\WelcomeNewCustomer; | |
use Tests\TestCase; | |
use Illuminate\Support\Facades\Mail; | |
class CustomerStoreTest extends TestCase | |
{ | |
/** | |
* Test Validation rules. | |
* | |
* @return void | |
*/ | |
public function test_it_requires_name_and_email_on_store_request() | |
{ | |
$response = $this->postJson('/api/customer', [ | |
'name' => "", | |
'email' => "", | |
]); | |
$response->assertStatus(422) | |
->assertInvalid(['name', 'email']); | |
} | |
/** | |
* Test Customer Creation | |
* | |
* @return void | |
*/ | |
public function test_it_creates_a_new_customer_on_store_request() | |
{ | |
Mail::fake(); | |
$response = $this->postJson('/api/customer', [ | |
'name' => "Test", | |
'email' => "test@example.com", | |
]); | |
$response->assertStatus(200) | |
->assertJson([ | |
'saved' => true, | |
]); | |
Mail::assertSent(WelcomeNewCustomer::class); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment