Skip to content

Commit 8b9a7b4

Browse files
committed
feat: refine CategoryNotFoundException and update validation rules in Category requests
1 parent 10b7696 commit 8b9a7b4

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

contexts/CategoryManagement/Domain/Exceptions/CategoryNotFoundException.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44

55
namespace Contexts\CategoryManagement\Domain\Exceptions;
66

7-
use Contexts\Shared\Exceptions\DomainException;
87
use Contexts\Shared\Exceptions\NotFoundException;
98

10-
class CategoryNotFoundException extends DomainException implements NotFoundException
9+
class CategoryNotFoundException extends NotFoundException
1110
{
1211
public function __construct(int $id)
1312
{

contexts/CategoryManagement/Presentation/Requests/CategoryIdRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ class CategoryIdRequest extends BaseFormRequest
1010
{
1111
public function rules(): array
1212
{
13-
return $this->idRule('categories');
13+
return $this->idRule();
1414
}
1515
}

contexts/CategoryManagement/Presentation/Requests/UpdateCategoryRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class UpdateCategoryRequest extends BaseFormRequest
1111
public function rules(): array
1212
{
1313
return [
14-
'id' => ['required', 'integer', 'gt:0', 'exists:categories,id'],
14+
'id' => ['required', 'integer', 'gt:0'],
1515
'label' => ['string', 'max:255'],
1616
'status' => ['string', 'in:subspended,active'],
1717
'created_at' => ['date', 'date_format: Y-m-d H:i:s'],

contexts/CategoryManagement/Tests/Feature/CategoryPublishingTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
]);
3434
});
3535

36+
it('can not get a category that does not exist', function () {
37+
$response = $this->get('categories/1');
38+
39+
$response->assertStatus(404);
40+
});
41+
3642
it('can get a list of categories', function () {
3743
$response = $this->postJson('categories', [
3844
'label' => 'My Category',
@@ -101,5 +107,5 @@
101107

102108
$response = $this->get("categories/{$id}");
103109

104-
$response->assertStatus(422);
110+
$response->assertStatus(404);
105111
});

0 commit comments

Comments
 (0)