mercredi 23 septembre 2020

Laravel Write Update Test

I'm using Laravel 8 starting with cloned pingcrm and I'm tryng to write a test to update a contact, but seems it doesn't work. Note that I made a change to the preset structure, now a contact is directly associated to the user that created it (not to the account)

    public function test_an_authorized_user_can_update_a_contact()
    {
        $this->user->contacts()->saveMany(
            factory(Contact::class, 5)->make()
        );

        $this->actingAs($this->user)
            ->put('/contacts/' . Contact::first()->id, ['first_name' => 'bablo']);
        // TRIED PATCH TOO
        // TRIED '/contacts' AS WELL


        dd(Contact::first());
    }

The extracted contact was not updated. Suggestions?

EDIT

I get the following error from the request

 +response: null
  +status: 422
  +errorBag: "default"
  +redirectTo: null
  #message: "The given data was invalid."
  #code: 0
  #file: "C:\xampp\htdocs\myhobbies\vendor\laravel\framework\src\Illuminate\Validation\Validator.php"
  #line: 452
  trace: {
    C:\xampp\htdocs\myhobbies\vendor\laravel\framework\src\Illuminate\Validation\Validator.php:452 { …}
    C:\xampp\htdocs\myhobbies\vendor\laravel\framework\src\Illuminate\Validation\Factory.php:136 { …}
    C:\xampp\htdocs\myhobbies\vendor\laravel\framework\src\Illuminate\Foundation\Providers\FoundationServiceProvider.php:58 { …}
    Illuminate\Http\Request->Illuminate\Foundation\Providers\{closure}() {}
    C:\xampp\htdocs\myhobbies\vendor\laravel\framework\src\Illuminate\Macroable\Traits\Macroable.php:111 { …}
    C:\xampp\htdocs\myhobbies\app\Http\Controllers\ContactsController.php:128 {
      App\Http\Controllers\ContactsController->validateData()
      › return request()->validate([\r
      ›     'first_name' => ['required', 'max:50'],\r
      ›     'last_name' => ['required', 'max:50'],\r
      arguments: {
        $method: "validate"
        $parameters: array:1 [ …1]
      }
    }
    C:\xampp\htdocs\myhobbies\app\Http\Controllers\ContactsController.php:103 { …}
    App\Http\Controllers\ContactsController->update() {}

Aucun commentaire:

Enregistrer un commentaire