diff --git a/src/stubs/controller.api.stub b/src/stubs/controller.api.stub index 621ace2..c532bae 100644 --- a/src/stubs/controller.api.stub +++ b/src/stubs/controller.api.stub @@ -43,7 +43,10 @@ class MastersController extends Controller $singleMstr = Master::create($newMaster); - return $singleMstr; + return response()->json([ + 'message' => __('master.created'), + 'data' => $singleMstr, + ], 201); } /** @@ -77,7 +80,10 @@ class MastersController extends Controller $singleMstr->update($request->only('name', 'description')); - return $singleMstr; + return response()->json([ + 'message' => __('master.updated'), + 'data' => $singleMstr, + ]); } /** @@ -96,7 +102,7 @@ class MastersController extends Controller ]); if (request('master_id') == $singleMstr->id && $singleMstr->delete()) { - return response()->json('master deleted.', 204); + return response()->json(['message' => __('master.deleted')]); } return response()->json('Unprocessable Entity.', 422); diff --git a/src/stubs/test-feature-api.stub b/src/stubs/test-feature-api.stub index fe45749..c7ba1ac 100644 --- a/src/stubs/test-feature-api.stub +++ b/src/stubs/test-feature-api.stub @@ -40,7 +40,12 @@ class ManageMastersTest extends TestCase 'description' => 'Master 1 description', ]); - $this->seeJson(['name' => 'Master 1 name']); + $this->seeStatusCode(201); + $this->seeJson([ + 'message' => __('master.created'), + 'name' => 'Master 1 name', + 'description' => 'Master 1 description', + ]); } /** @test */ @@ -74,7 +79,12 @@ class ManageMastersTest extends TestCase 'description' => 'Master 1 description', ]); - $this->seeJson(['name' => 'Master 1 name']); + $this->seeStatusCode(200); + $this->seeJson([ + 'message' => __('master.updated'), + 'name' => 'Master 1 name', + 'description' => 'Master 1 description', + ]); } /** @test */ @@ -92,5 +102,10 @@ class ManageMastersTest extends TestCase $this->dontSeeInDatabase('masters', [ 'id' => $singleMstr->id, ]); + + $this->seeStatusCode(200); + $this->seeJson([ + 'message' => __('master.deleted'), + ]); } } diff --git a/tests/Generators/Api/ApiControllerGeneratorTest.php b/tests/Generators/Api/ApiControllerGeneratorTest.php index 0075ea3..ccd87a9 100644 --- a/tests/Generators/Api/ApiControllerGeneratorTest.php +++ b/tests/Generators/Api/ApiControllerGeneratorTest.php @@ -57,7 +57,10 @@ class {$this->plural_model_name}Controller extends Controller \${$this->single_model_var_name} = {$this->model_name}::create(\$new{$this->model_name}); - return \${$this->single_model_var_name}; + return response()->json([ + 'message' => __('{$this->lang_name}.created'), + 'data' => \${$this->single_model_var_name}, + ], 201); } /** @@ -91,7 +94,10 @@ class {$this->plural_model_name}Controller extends Controller \${$this->single_model_var_name}->update(\$request->only('name', 'description')); - return \${$this->single_model_var_name}; + return response()->json([ + 'message' => __('{$this->lang_name}.updated'), + 'data' => \${$this->single_model_var_name}, + ]); } /** @@ -110,7 +116,7 @@ class {$this->plural_model_name}Controller extends Controller ]); if (request('{$this->lang_name}_id') == \${$this->single_model_var_name}->id && \${$this->single_model_var_name}->delete()) { - return response()->json('{$this->lang_name} deleted.', 204); + return response()->json(['message' => __('{$this->lang_name}.deleted')]); } return response()->json('Unprocessable Entity.', 422); diff --git a/tests/Generators/Api/ApiFeatureTestGeneratorTest.php b/tests/Generators/Api/ApiFeatureTestGeneratorTest.php index 6167412..0ae5739 100644 --- a/tests/Generators/Api/ApiFeatureTestGeneratorTest.php +++ b/tests/Generators/Api/ApiFeatureTestGeneratorTest.php @@ -54,7 +54,12 @@ class Manage{$this->plural_model_name}Test extends TestCase 'description' => '{$this->model_name} 1 description', ]); - \$this->seeJson(['name' => '{$this->model_name} 1 name']); + \$this->seeStatusCode(201); + \$this->seeJson([ + 'message' => __('{$this->lang_name}.created'), + 'name' => '{$this->model_name} 1 name', + 'description' => '{$this->model_name} 1 description', + ]); } /** @test */ @@ -88,7 +93,12 @@ class Manage{$this->plural_model_name}Test extends TestCase 'description' => '{$this->model_name} 1 description', ]); - \$this->seeJson(['name' => '{$this->model_name} 1 name']); + \$this->seeStatusCode(200); + \$this->seeJson([ + 'message' => __('{$this->lang_name}.updated'), + 'name' => '{$this->model_name} 1 name', + 'description' => '{$this->model_name} 1 description', + ]); } /** @test */ @@ -106,6 +116,11 @@ class Manage{$this->plural_model_name}Test extends TestCase \$this->dontSeeInDatabase('{$this->table_name}', [ 'id' => \${$this->single_model_var_name}->id, ]); + + \$this->seeStatusCode(200); + \$this->seeJson([ + 'message' => __('{$this->lang_name}.deleted'), + ]); } } "; @@ -163,7 +178,12 @@ class Manage{$this->plural_model_name}Test extends TestCase 'description' => '{$this->model_name} 1 description', ]); - \$this->seeJson(['name' => '{$this->model_name} 1 name']); + \$this->seeStatusCode(201); + \$this->seeJson([ + 'message' => __('{$this->lang_name}.created'), + 'name' => '{$this->model_name} 1 name', + 'description' => '{$this->model_name} 1 description', + ]); } /** @test */ @@ -197,7 +217,12 @@ class Manage{$this->plural_model_name}Test extends TestCase 'description' => '{$this->model_name} 1 description', ]); - \$this->seeJson(['name' => '{$this->model_name} 1 name']); + \$this->seeStatusCode(200); + \$this->seeJson([ + 'message' => __('{$this->lang_name}.updated'), + 'name' => '{$this->model_name} 1 name', + 'description' => '{$this->model_name} 1 description', + ]); } /** @test */ @@ -215,6 +240,11 @@ class Manage{$this->plural_model_name}Test extends TestCase \$this->dontSeeInDatabase('{$this->table_name}', [ 'id' => \${$this->single_model_var_name}->id, ]); + + \$this->seeStatusCode(200); + \$this->seeJson([ + 'message' => __('{$this->lang_name}.deleted'), + ]); } } ";