Commit 50c304da authored by cygnet's avatar cygnet

changes done for pages test and correcting a logic at one place from repository

parent af02a4a4
...@@ -57,14 +57,15 @@ class PagesController extends APIController ...@@ -57,14 +57,15 @@ class PagesController extends APIController
*/ */
public function store(Request $request) public function store(Request $request)
{ {
$validation = $this->validatePages($request); $validation = $this->validatePages($request);
if ($validation->fails()) { if ($validation->fails()) {
return $this->throwValidation($validation->messages()->first()); return $this->throwValidation($validation->messages()->first());
} }
$this->repository->create($request->all()); $page = $this->repository->create($request->all());
return new PagesResource(Page::orderBy('created_at', 'desc')->first()); return new PagesResource($page);
} }
/** /**
......
...@@ -57,11 +57,14 @@ class PagesRepository extends BaseRepository ...@@ -57,11 +57,14 @@ class PagesRepository extends BaseRepository
if ($page = Page::create($input)) { if ($page = Page::create($input)) {
event(new PageCreated($page)); event(new PageCreated($page));
return true; return $page;
} }
throw new GeneralException(trans('exceptions.backend.pages.create_error')); throw new GeneralException(trans('exceptions.backend.pages.create_error'));
} }
/** /**
......
...@@ -10,7 +10,6 @@ $factory->define(Page::class, function (Faker $faker) { ...@@ -10,7 +10,6 @@ $factory->define(Page::class, function (Faker $faker) {
$newestPage = Page::orderBy('id', 'desc')->first(); $newestPage = Page::orderBy('id', 'desc')->first();
return [ return [
"id" => $newestPage->id+1,
'title' => $title, 'title' => $title,
'page_slug' => str_slug($title), 'page_slug' => str_slug($title),
'description' => $faker->paragraph, 'description' => $faker->paragraph,
......
...@@ -90,12 +90,15 @@ class PageTest extends TestCase ...@@ -90,12 +90,15 @@ class PageTest extends TestCase
} }
/** /**
* A basic test to create a page from api * Author: Indra Shastri
* Date:03-03-2018
* A basic test to update a page from api
*
* *
* @return void * @return void
*/ */
/** @test */ /** @test */
public function create_a_new_page_in_db_and_get_response() public function update_a_page_in_db_and_get_response()
{ {
$page = make(Page::class); $page = make(Page::class);
$payload = [ $payload = [
...@@ -107,12 +110,12 @@ class PageTest extends TestCase ...@@ -107,12 +110,12 @@ class PageTest extends TestCase
"seo_description" => "<p>&nbsp;</p>↵<h1>SEO Description</h1>↵<p>some seco desctription</p>↵<p>askdsaj;ldsjfd</p>", "seo_description" => "<p>&nbsp;</p>↵<h1>SEO Description</h1>↵<p>some seco desctription</p>↵<p>askdsaj;ldsjfd</p>",
"status" => "1", "status" => "1",
]; ];
$response = $this->json('POST', '/api/v1/pages', $payload, $this->headers); $response = "";
$response $response = $this->json('PUT', '/api/v1/pages/1', $payload, $this->headers);
->assertStatus(200)
->assertJson([ $response->assertStatus(200);
$response->assertJson([
"data"=>[ "data"=>[
"id" => $page->id,
"title" => $page->title, "title" => $page->title,
"status_label" => $page->status_label, "status_label" => $page->status_label,
"status" => ($page->isActive()) ? 'Active' :'InActive', "status" => ($page->isActive()) ? 'Active' :'InActive',
...@@ -121,5 +124,55 @@ class PageTest extends TestCase ...@@ -121,5 +124,55 @@ class PageTest extends TestCase
]); ]);
} }
/**
* Author: Indra Shastri
* Date:03-03-2018
* A basic test to create a page from api
*
* @return void
*/
/** @test */
public function create_a_new_page_in_db_and_get_response()
{
$page = make(Page::class);
$payload = [
"title" => $page->title,
"description" => $page->description,
"cannonical_link" => $page->cannonical_link,
"seo_title" => "some tittle",
"seo_keyword" => "some keywords",
"seo_description" => "<p>&nbsp;</p>↵<h1>SEO Description</h1>↵<p>some seco desctription</p>↵<p>askdsaj;ldsjfd</p>",
"status" => "1",
];
$response = "";
$response = $this->json('POST', '/api/v1/pages', $payload, $this->headers);
$response->assertStatus(201);
$response->assertJson([
"data" => [
"title" => $page->title,
"status_label" => $page->status_label,
"status" => ($page->isActive()) ? 'Active' : 'InActive',
"created_by" => $this->user->first_name,
"created_at" => (\Carbon\Carbon::now())->toDateString()
],
]);
}
/**
* Author: Indra Shastri
* Date:03-03-2018
* A basic test to create a page from api
*
* @return void
*/
/** @test */
public function delete_page_in_db_and_get_response(){
$page = create(Page::class);
$payload=[];
$response = $this->json('DELETE', '/api/v1/pages/'.$page->id, $payload, $this->headers);
$response->assertStatus(200)
->assertJson([
"message"=> "The Page was successfully deleted."
]);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment