Skip to content

Instantly share code, notes, and snippets.

@kofoworola
Created January 17, 2019 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kofoworola/14fd5031f9e2733ebe4d3de5f1ae0490 to your computer and use it in GitHub Desktop.
Save kofoworola/14fd5031f9e2733ebe4d3de5f1ae0490 to your computer and use it in GitHub Desktop.
<?php
...
class RecipeTest extends TestCase
{
use RefreshDatabase;
...
//Create user and authenticate the user
protected function authenticate(){
$user = User::create([
'name' => 'test',
'email' => 'test@gmail.com',
'password' => Hash::make('secret1234'),
]);
$token = JWTAuth::fromUser($user);
return $token;
}
public function testCreate()
{
//Get token
$token = $this->authenticate();
$response = $this->withHeaders([
'Authorization' => 'Bearer '. $token,
])->json('POST',route('recipe.create'),[
'title' => 'Jollof Rice',
'procedure' => 'Parboil rice, get pepper and mix, and some spice and serve!'
]);
$response->assertStatus(200);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment