Skip to content

Commit 50c304d

Browse files
committed
changes done for pages test and correcting a logic at one place from repository
1 parent af02a4a commit 50c304d

File tree

4 files changed

+70
-14
lines changed

4 files changed

+70
-14
lines changed

app/Http/Controllers/Api/V1/PagesController.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,15 @@ public function show(Page $page)
5757
*/
5858
public function store(Request $request)
5959
{
60+
6061
$validation = $this->validatePages($request);
6162
if ($validation->fails()) {
6263
return $this->throwValidation($validation->messages()->first());
6364
}
6465

65-
$this->repository->create($request->all());
66-
67-
return new PagesResource(Page::orderBy('created_at', 'desc')->first());
66+
$page = $this->repository->create($request->all());
67+
68+
return new PagesResource($page);
6869
}
6970

7071
/**

app/Repositories/Backend/Pages/PagesRepository.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,14 @@ public function create(array $input)
5757

5858
if ($page = Page::create($input)) {
5959
event(new PageCreated($page));
60-
61-
return true;
60+
61+
return $page;
6262
}
6363

6464
throw new GeneralException(trans('exceptions.backend.pages.create_error'));
65+
66+
67+
6568
}
6669

6770
/**

database/factories/PageFactory.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
$newestPage = Page::orderBy('id', 'desc')->first();
1111

1212
return [
13-
"id" => $newestPage->id+1,
1413
'title' => $title,
1514
'page_slug' => str_slug($title),
1615
'description' => $faker->paragraph,

tests/Feature/Api/V1/PageTest.php

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,15 @@ public function get_one_created_page_from_db()
9090

9191
}
9292
/**
93-
* A basic test to create a page from api
93+
* Author: Indra Shastri
94+
* Date:03-03-2018
95+
* A basic test to update a page from api
96+
*
9497
*
9598
* @return void
9699
*/
97100
/** @test */
98-
public function create_a_new_page_in_db_and_get_response()
101+
public function update_a_page_in_db_and_get_response()
99102
{
100103
$page = make(Page::class);
101104
$payload = [
@@ -107,12 +110,12 @@ public function create_a_new_page_in_db_and_get_response()
107110
"seo_description" => "<p>&nbsp;</p>↵<h1>SEO Description</h1>↵<p>some seco desctription</p>↵<p>askdsaj;ldsjfd</p>",
108111
"status" => "1",
109112
];
110-
$response = $this->json('POST', '/api/v1/pages', $payload, $this->headers);
111-
$response
112-
->assertStatus(200)
113-
->assertJson([
113+
$response = "";
114+
$response = $this->json('PUT', '/api/v1/pages/1', $payload, $this->headers);
115+
116+
$response->assertStatus(200);
117+
$response->assertJson([
114118
"data"=>[
115-
"id" => $page->id,
116119
"title" => $page->title,
117120
"status_label" => $page->status_label,
118121
"status" => ($page->isActive()) ? 'Active' :'InActive',
@@ -121,5 +124,55 @@ public function create_a_new_page_in_db_and_get_response()
121124
]);
122125

123126
}
124-
127+
/**
128+
* Author: Indra Shastri
129+
* Date:03-03-2018
130+
* A basic test to create a page from api
131+
*
132+
* @return void
133+
*/
134+
/** @test */
135+
public function create_a_new_page_in_db_and_get_response()
136+
{
137+
$page = make(Page::class);
138+
$payload = [
139+
"title" => $page->title,
140+
"description" => $page->description,
141+
"cannonical_link" => $page->cannonical_link,
142+
"seo_title" => "some tittle",
143+
"seo_keyword" => "some keywords",
144+
"seo_description" => "<p>&nbsp;</p>↵<h1>SEO Description</h1>↵<p>some seco desctription</p>↵<p>askdsaj;ldsjfd</p>",
145+
"status" => "1",
146+
];
147+
$response = "";
148+
$response = $this->json('POST', '/api/v1/pages', $payload, $this->headers);
149+
$response->assertStatus(201);
150+
$response->assertJson([
151+
"data" => [
152+
"title" => $page->title,
153+
"status_label" => $page->status_label,
154+
"status" => ($page->isActive()) ? 'Active' : 'InActive',
155+
"created_by" => $this->user->first_name,
156+
"created_at" => (\Carbon\Carbon::now())->toDateString()
157+
],
158+
]);
159+
160+
}
161+
/**
162+
* Author: Indra Shastri
163+
* Date:03-03-2018
164+
* A basic test to create a page from api
165+
*
166+
* @return void
167+
*/
168+
/** @test */
169+
public function delete_page_in_db_and_get_response(){
170+
$page = create(Page::class);
171+
$payload=[];
172+
$response = $this->json('DELETE', '/api/v1/pages/'.$page->id, $payload, $this->headers);
173+
$response->assertStatus(200)
174+
->assertJson([
175+
"message"=> "The Page was successfully deleted."
176+
]);
177+
}
125178
}

0 commit comments

Comments
 (0)