Skip to content

Commit 74d7c77

Browse files
committed
properties index test case
1 parent ea80804 commit 74d7c77

File tree

5 files changed

+77
-19
lines changed

5 files changed

+77
-19
lines changed

app/Http/Controllers/Api/v1/PropertyController.php

+2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ public function index(GenericListingRequest $request)
8585

8686
/**
8787
* Store a new property
88+
*
89+
* `slug` field is set automatically using the `name` field when the status is set to <b>active</b> (value 1). Once set it can't be changed.
8890
*/
8991
public function store(StorePropertyRequest $request)
9092
{

composer.lock

+16-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpunit.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
<env name="APP_MAINTENANCE_DRIVER" value="file"/>
2323
<env name="BCRYPT_ROUNDS" value="4"/>
2424
<env name="CACHE_STORE" value="array"/>
25-
<env name="DB_DATABASE" value="testing"/>
25+
<env name="DB_CONNECTION" value="sqlite"/>
26+
<env name="DB_DATABASE" value=":memory:"/>
2627
<env name="MAIL_MAILER" value="array"/>
2728
<env name="PULSE_ENABLED" value="false"/>
2829
<env name="QUEUE_CONNECTION" value="sync"/>

routes/api.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
return $request->user();
99
})->middleware('auth:sanctum');
1010

11-
Route::prefix('v1')->group(function () {
11+
Route::prefix('v1')->name('api.v1.')->group(function () {
1212
Route::apiResource('properties', PropertyController::class);
13-
});
13+
})->name('v1');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
use Illuminate\Foundation\Testing\RefreshDatabase;
4+
use App\Http\Controllers\Api\v1\PropertyController;
5+
use Illuminate\Http\Response;
6+
use Illuminate\Testing\Fluent\AssertableJson;
7+
use App\Models\Property;
8+
use App\Models\User;
9+
10+
uses(RefreshDatabase::class);
11+
12+
it('index properties right json for no data', function (): void {
13+
$response = $this->getJson(
14+
uri: route('api.v1.properties.index'),
15+
);
16+
17+
$response
18+
->assertStatus(Response::HTTP_OK)
19+
->assertJson(
20+
[
21+
'data'=> [],
22+
'links'=> [
23+
'first'=> route('api.v1.properties.index').'?page=1',
24+
'last'=> route('api.v1.properties.index').'?page=1',
25+
'prev'=> null,
26+
'next'=> null
27+
],
28+
'meta'=> [
29+
'current_page'=> 1,
30+
'from'=> null,
31+
'last_page'=> 1,
32+
'links'=> [
33+
[
34+
'url'=> null,
35+
'label'=> '&laquo; Previous',
36+
'active'=> false
37+
],
38+
[
39+
'url'=> route('api.v1.properties.index').'?page=1',
40+
'label'=> '1',
41+
'active'=> true
42+
],
43+
[
44+
'url'=> null,
45+
'label'=> 'Next &raquo;',
46+
'active'=> false
47+
]
48+
],
49+
'path'=> route('api.v1.properties.index'),
50+
'per_page'=> 15,
51+
'to'=> null,
52+
'total'=> 0
53+
]
54+
]);
55+
});

0 commit comments

Comments
 (0)