Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ng-backend into feature/faqsCrud
  • Loading branch information
CloudSalander committed Jun 6, 2023
2 parents 4540bf2 + 46b843e commit 0014c1a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
Binary file added .rnd
Binary file not shown.
59 changes: 35 additions & 24 deletions tests/Feature/RegisterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@

namespace Tests\Feature;

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

class RegisterTest extends TestCase
{
use DatabaseTransactions;
use RefreshDatabase;

/**
* Test basic store user
*/
public function testStoreWithValidData(): void
public function test_store_with_valid_data(): void
{
$userData = \App\Models\User::factory()->makeOne(['dni' => '35983746Q']);
$userData = User::factory()->makeOne(['dni' => '48042812K']);

$response = $this->post('/api/register', [
'name' => $userData['name'],
Expand All @@ -43,9 +42,9 @@ public function testStoreWithValidData(): void
/**
* Test store user without name
*/
public function testStoreWithValidDataAndWithoutName(): void
public function test_store_with_valid_data_and_without_name(): void
{
$userData = \App\Models\User::factory()->makeOne(['dni' => '35983746Q']);
$userData = User::factory()->makeOne(['dni' => '35983746Q']);

$response = $this->post('/api/register', [
'email' => $userData['email'],
Expand All @@ -70,9 +69,9 @@ public function testStoreWithValidDataAndWithoutName(): void
/**
* Test store user with invalid DNI
*/
public function testStoreWithInvalidDni(): void
public function test_store_with_invalid_dni(): void
{
$userData = \App\Models\User::factory()->makeOne(['dni' => '35983747Q']);
$userData = User::factory()->makeOne(['dni' => '35983747Q']);

$response = $this->post('/api/register', [
'name' => $userData['name'],
Expand All @@ -88,13 +87,13 @@ public function testStoreWithInvalidDni(): void
]);
}


/**
* Test store user with valid NIE
*/
public function testStoreWithValidNie(): void
public function test_store_with_valid_nie(): void
{
$userData = \App\Models\User::factory()->makeOne(['dni' => 'Z6383416R']);
$userData = User::factory()->makeOne(['dni' => 'Z6383416R']);

$response = $this->post('/api/register', [
'name' => $userData['name'],
Expand All @@ -113,9 +112,9 @@ public function testStoreWithValidNie(): void
/**
* Test store user with invalid NIE
*/
public function testStoreWithInvalidNie(): void
public function test_store_with_invalid_nie(): void
{
$userData = \App\Models\User::factory()->makeOne(['dni' => 'Z6383416Q']);
$userData = User::factory()->makeOne(['dni' => 'Z6383416Q']);

$response = $this->post('/api/register', [
'name' => $userData['name'],
Expand All @@ -134,9 +133,9 @@ public function testStoreWithInvalidNie(): void
/**
* Test store user without obligatory fields
*/
public function testStoreWithoutObligatoryFields(): void
public function test_store_with_obligatory_fields(): void
{
$userData = \App\Models\User::factory()->makeOne(['dni' => '36372839H']);
$userData = User::factory()->makeOne(['dni' => '36372839H']);

$response = $this->post('/api/register', [
'dni' => $userData['dni'],
Expand Down Expand Up @@ -176,9 +175,9 @@ public function testStoreWithoutObligatoryFields(): void
/**
* Test store user with short password
*/
public function testStoreWithShortPassword(): void
public function test_store_with_short_password(): void
{
$userData = \App\Models\User::factory()->makeOne(['dni' => '89137481S', 'password' => 'pas']);
$userData = User::factory()->makeOne(['dni' => '89137481S', 'password' => 'pas']);

$response = $this->post('/api/register', [
'name' => $userData['name'],
Expand All @@ -197,10 +196,16 @@ public function testStoreWithShortPassword(): void
/**
* Test store user with taken email
*/
public function testStoreWithTakenEmail(): void
public function test_store_with_taken_email(): void
{
$userData = \App\Models\User::factory()->makeOne(['dni' => '97491829G']);
\App\Models\User::create(array_merge($userData->toArray(), ['password' => $userData['password']]));
$userData = User::create([
'name' => 'name',
'email' => '[email protected]',
'dni' => '57591829J',
'password' => bcrypt('password'),
'status' => 'ACTIVE',
'role' => 'ADMIN',
]);

$response = $this->post('/api/register', [
'email' => $userData['email'],
Expand All @@ -218,10 +223,16 @@ public function testStoreWithTakenEmail(): void
/**
* Test store user with taken DNI
*/
public function testStoreWithTakenDNI(): void
public function test_store_with_taken_dni(): void
{
$userData = \App\Models\User::factory()->makeOne(['dni' => '57591829J']);
\App\Models\User::create(array_merge($userData->toArray(), ['password' => $userData['password']]));
$userData = User::create([
'name' => 'name',
'email' => '[email protected]',
'dni' => '57591829J',
'password' => bcrypt('password'),
'status' => 'ACTIVE',
'role' => 'ADMIN',
]);

$response = $this->post('/api/register', [
'email' => '[email protected]',
Expand Down

0 comments on commit 0014c1a

Please sign in to comment.