feat: add routes, lang, tests, stubs, docs, and docker configurations
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
use App\Http\Helpers\ApiResponse;
|
||||
|
||||
test('success returns 200 with status and message', function () {
|
||||
$r = ApiResponse::success(['x' => 1], 'OK');
|
||||
expect($r->getStatusCode())->toBe(200);
|
||||
$body = $r->getData(true);
|
||||
expect($body['status'])->toBe('success');
|
||||
expect($body['message'])->toBe('OK');
|
||||
expect($body['data'])->toBe(['x' => 1]);
|
||||
});
|
||||
|
||||
test('success omits data key when data is null', function () {
|
||||
$body = ApiResponse::success(null, 'no body')->getData(true);
|
||||
expect($body)->not->toHaveKey('data');
|
||||
});
|
||||
|
||||
test('error returns the given code and message', function () {
|
||||
$r = ApiResponse::error('Boom', 418);
|
||||
expect($r->getStatusCode())->toBe(418);
|
||||
$body = $r->getData(true);
|
||||
expect($body['status'])->toBe('error');
|
||||
expect($body['message'])->toBe('Boom');
|
||||
});
|
||||
|
||||
test('error includes errors array when provided', function () {
|
||||
$body = ApiResponse::error('Bad', 422, ['field' => 'is broken'])->getData(true);
|
||||
expect($body['errors'])->toBe(['field' => 'is broken']);
|
||||
});
|
||||
|
||||
test('created returns 201', function () {
|
||||
expect(ApiResponse::created(['id' => 5])->getStatusCode())->toBe(201);
|
||||
});
|
||||
|
||||
test('notFound returns 404 with default message', function () {
|
||||
$r = ApiResponse::notFound();
|
||||
expect($r->getStatusCode())->toBe(404);
|
||||
expect($r->getData(true)['message'])->toBe('Resource not found');
|
||||
});
|
||||
|
||||
test('unauthorized returns 401', function () {
|
||||
expect(ApiResponse::unauthorized()->getStatusCode())->toBe(401);
|
||||
});
|
||||
|
||||
test('forbidden returns 403', function () {
|
||||
expect(ApiResponse::forbidden()->getStatusCode())->toBe(403);
|
||||
});
|
||||
|
||||
test('validationError returns 422 with errors payload', function () {
|
||||
$r = ApiResponse::validationError(['email' => ['required']]);
|
||||
expect($r->getStatusCode())->toBe(422);
|
||||
expect($r->getData(true)['errors'])->toBe(['email' => ['required']]);
|
||||
});
|
||||
|
||||
test('serverError returns 500', function () {
|
||||
expect(ApiResponse::serverError()->getStatusCode())->toBe(500);
|
||||
});
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
use App\Helpers\PasswordRuleHelper;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
test('rules array includes required, string, min:12', function () {
|
||||
$rules = PasswordRuleHelper::rules();
|
||||
expect($rules)->toContain('required');
|
||||
expect($rules)->toContain('string');
|
||||
expect($rules)->toContain('min:12');
|
||||
});
|
||||
|
||||
test('rules array includes regex for each charset class', function () {
|
||||
$rules = PasswordRuleHelper::rules();
|
||||
expect(implode('|', $rules))
|
||||
->toContain('regex:/[a-z]/')
|
||||
->toContain('regex:/[A-Z]/')
|
||||
->toContain('regex:/[0-9]/');
|
||||
});
|
||||
|
||||
test('messages contain min and regex keys', function () {
|
||||
$msgs = PasswordRuleHelper::messages();
|
||||
expect($msgs)->toHaveKeys(['password.min', 'password.regex']);
|
||||
});
|
||||
|
||||
test('rules accept a strong password via Validator', function () {
|
||||
$v = Validator::make(
|
||||
['password' => 'Str0ng!Passw0rd2026'],
|
||||
['password' => PasswordRuleHelper::rules()],
|
||||
PasswordRuleHelper::messages(),
|
||||
);
|
||||
expect($v->fails())->toBeFalse();
|
||||
});
|
||||
|
||||
test('rules reject short passwords', function () {
|
||||
$v = Validator::make(
|
||||
['password' => 'Abc123!'],
|
||||
['password' => PasswordRuleHelper::rules()],
|
||||
);
|
||||
expect($v->fails())->toBeTrue();
|
||||
});
|
||||
|
||||
test('rules reject passwords missing uppercase', function () {
|
||||
$v = Validator::make(
|
||||
['password' => 'all_lower_123!'],
|
||||
['password' => PasswordRuleHelper::rules()],
|
||||
);
|
||||
expect($v->fails())->toBeTrue();
|
||||
});
|
||||
|
||||
test('rules reject passwords missing digit', function () {
|
||||
$v = Validator::make(
|
||||
['password' => 'NoDigitsHere!'],
|
||||
['password' => PasswordRuleHelper::rules()],
|
||||
);
|
||||
expect($v->fails())->toBeTrue();
|
||||
});
|
||||
|
||||
test('rules reject passwords missing symbol', function () {
|
||||
$v = Validator::make(
|
||||
['password' => 'NoSymbolsHere1'],
|
||||
['password' => PasswordRuleHelper::rules()],
|
||||
);
|
||||
expect($v->fails())->toBeTrue();
|
||||
});
|
||||
Reference in New Issue
Block a user