manshu
1 week ago
249
20
Laravel

Creating User for API giving error

Posted 1 week ago by manshu

Here's my User Registration Test. I am using default UserFactory.php to create user. I am getting the following error.

Illuminate\Validation\ValidationException: The given data was invalid.

<?php

namespace Tests\Feature\API\Users;

use Tests\TestCase;
use WebApp\Domain\Users\User;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;

class UsersFeatureTest extends TestCase
{
    
    use RefreshDatabase;

    /** @test */
    public function it_registers_new_user_using_api()
    {
        $this->withoutExceptionHandling();
        //Given
        $user = factory(User::class)->create()->toArray();
        //When
        $response = $this->post('/api/register', $user);
        //Then
        $response->assertStatus(201);
    }

}

Please sign in or create an account to participate in this conversation.