From 95a8695e595425674b8e92411538885b2f017540 Mon Sep 17 00:00:00 2001 From: Roman Lytvynenko Date: Fri, 28 Jun 2024 08:20:34 +0300 Subject: [PATCH] added tests --- tests/ValidationRulesDocumentingTest.php | 28 ++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/ValidationRulesDocumentingTest.php b/tests/ValidationRulesDocumentingTest.php index c26b423b..6134761e 100644 --- a/tests/ValidationRulesDocumentingTest.php +++ b/tests/ValidationRulesDocumentingTest.php @@ -184,6 +184,34 @@ ->toHaveKey('maximum', 8); }); +it('converts min rule into "minLength" for string fields', function () { + $rules = [ + 'str' => ['string', 'min:8'], + ]; + + $params = app()->make(RulesToParameters::class, ['rules' => $rules])->handle(); + + expect($params = collect($params)->all()) + ->toHaveCount(1) + ->and($params[0]->schema->type) + ->toBeInstanceOf(\Dedoc\Scramble\Support\Generator\Types\StringType::class) + ->toHaveKey('minLength', 8); +}); + +it('converts max rule into "maxLength" for string fields', function () { + $rules = [ + 'str' => ['string', 'max:8'], + ]; + + $params = app()->make(RulesToParameters::class, ['rules' => $rules])->handle(); + + expect($params = collect($params)->all()) + ->toHaveCount(1) + ->and($params[0]->schema->type) + ->toBeInstanceOf(\Dedoc\Scramble\Support\Generator\Types\StringType::class) + ->toHaveKey('maxLength', 8); +}); + it('converts min rule into "minItems" for array fields', function () { $rules = [ 'num' => ['array', 'min:8'],