@tykus Thanks for replay.
Here is my code
Json Issue:
/** @test */
function authenticated_users_can_fetch_thier_user_data()
{
$this->signIn($this->user);
$response = $this->getJson('api/auth/user')->json();
$this->assertEquals($this->user->email, $response['email']);
}
public function user()
{
return response()->json(request()->user()->load('company'));
}
My Route don't trigger the user() method at all if I dd() there. Error happens before that, maybe in middleware.
POST Issue: The Route ist registered as POST.
Route::group([
'prefix' => 'auth',
'namespace' => 'Auth'
], function(){
Route::post('/register', 'AuthController@register');
Route::group([
'middleware' => 'auth:api'
], function(){
Route::get('/user', 'AuthController@user');
});
});
/** @test */
function an_user_can_register_an_account()
{
$this->registerAccount()->json();
$this->assertCount(1, User::all());
tap(User::first(), function($user){
$this->assertEquals('John Doe', $user->name);
$this->assertEquals('[email protected]', $user->email);
$this->assertTrue(Hash::check('secret', $user->password));
});
}
protected function registerAccount($overrides = [])
{
return $this->post('/api/auth/register', array_merge([
'name' => 'John Doe',
'email' => '[email protected]',
'password' =>'secret',
],$overrides));
}
The Problem seems to be somewhere in my configurations or middleware settings, but I'm not sure.
Weird thing is, everythings still works in the bowser.