You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
111 lines
3.0 KiB
111 lines
3.0 KiB
<?php
|
|
|
|
namespace Tests\Feature\Api;
|
|
|
|
use fullMstr;
|
|
use Tests\BrowserKitTest as TestCase;
|
|
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
|
|
|
class ManageMastersTest extends TestCase
|
|
{
|
|
use DatabaseMigrations;
|
|
|
|
/** @test */
|
|
public function user_can_see_master_list_in_master_index_page()
|
|
{
|
|
$user = $this->createUser();
|
|
$singleMstr = factory(Master::class)->create();
|
|
|
|
$this->getJson(route('api.masters.index'), [
|
|
'Authorization' => 'Bearer '.$user->api_token
|
|
]);
|
|
|
|
$this->seeJson(['name' => $singleMstr->name]);
|
|
}
|
|
|
|
/** @test */
|
|
public function user_can_create_a_master()
|
|
{
|
|
$user = $this->createUser();
|
|
|
|
$this->postJson(route('api.masters.store'), [
|
|
'name' => 'Master 1 name',
|
|
'description' => 'Master 1 description',
|
|
], [
|
|
'Authorization' => 'Bearer '.$user->api_token
|
|
]);
|
|
|
|
$this->seeInDatabase('masters', [
|
|
'name' => 'Master 1 name',
|
|
'description' => 'Master 1 description',
|
|
]);
|
|
|
|
$this->seeStatusCode(201);
|
|
$this->seeJson([
|
|
'message' => __('master.created'),
|
|
'name' => 'Master 1 name',
|
|
'description' => 'Master 1 description',
|
|
]);
|
|
}
|
|
|
|
/** @test */
|
|
public function user_can_get_a_master_detail()
|
|
{
|
|
$user = $this->createUser();
|
|
$singleMstr = factory(Master::class)->create(['name' => 'Testing 123']);
|
|
|
|
$this->getJson(route('api.masters.show', $singleMstr), [
|
|
'Authorization' => 'Bearer '.$user->api_token
|
|
]);
|
|
|
|
$this->seeJson(['name' => 'Testing 123']);
|
|
}
|
|
|
|
/** @test */
|
|
public function user_can_update_a_master()
|
|
{
|
|
$user = $this->createUser();
|
|
$singleMstr = factory(Master::class)->create(['name' => 'Testing 123']);
|
|
|
|
$this->patchJson(route('api.masters.update', $singleMstr), [
|
|
'name' => 'Master 1 name',
|
|
'description' => 'Master 1 description',
|
|
], [
|
|
'Authorization' => 'Bearer '.$user->api_token
|
|
]);
|
|
|
|
$this->seeInDatabase('masters', [
|
|
'name' => 'Master 1 name',
|
|
'description' => 'Master 1 description',
|
|
]);
|
|
|
|
$this->seeStatusCode(200);
|
|
$this->seeJson([
|
|
'message' => __('master.updated'),
|
|
'name' => 'Master 1 name',
|
|
'description' => 'Master 1 description',
|
|
]);
|
|
}
|
|
|
|
/** @test */
|
|
public function user_can_delete_a_master()
|
|
{
|
|
$user = $this->createUser();
|
|
$singleMstr = factory(Master::class)->create();
|
|
|
|
$this->deleteJson(route('api.masters.destroy', $singleMstr), [
|
|
'master_id' => $singleMstr->id,
|
|
], [
|
|
'Authorization' => 'Bearer '.$user->api_token
|
|
]);
|
|
|
|
$this->dontSeeInDatabase('masters', [
|
|
'id' => $singleMstr->id,
|
|
]);
|
|
|
|
$this->seeStatusCode(200);
|
|
$this->seeJson([
|
|
'message' => __('master.deleted'),
|
|
]);
|
|
}
|
|
}
|