Hey Guys,
Im trying to write a test to check if a user gets successfully logged into our system
For some reason, its not seeing the token generated by the login endpoint.
I want to assert 3 things in my test.
- That the success flag is
true .. This is currently working
- The message is set .. This is currently working
- The token gets returned .. This is the bit that i cant seem to get going.
My test is as follows;
public function it_logs_a_user_in()
{
$user = factory(User::class)->create([ 'password' => Hash::make('foobar') ]);
$payload = [ 'email' => $user->email, 'password' => 'foobar' ];
$response = $this->json('POST', '/api/login', $payload);
$response->assertStatus(200)
->assertJsonFragment([
'success' => true,
'message' => 'Yehhh Boiiiii'
]);
}
Looking at the response in Postman, i get the following;
{
"success": true,
"message": "Yehhh Boiiiii",
"data": {
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9qb2JtYW5oZWxpb3MudGVzdFwvYXBpXC9hcGlcL2xvZ2luIiwiaWF0IjoxNTM5MzIyODcyLCJleHAiOjE1MzkzMjY0NzIsIm5iZiI6MTUzOTMyMjg3MiwianRpIjoiaXpQc2pvM0QxNm1SZ0VlayIsInN1YiI6MSwicHJ2IjoiMjNiZDVjODk0OWY2MDBhZGIzOWU3MDFjNDAwODcyZGI3YTU5NzZmNyJ9.ny4BKt0gcUCDiQ1a5bvsfwvcQfdV3nEPZAWVzBvziHo"
}
}
Whatever i do, i cant seem to get the token returned.
Any help would be grand :)