mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-09-02 13:21:02 +00:00
* refactor: stabilize model identities for domain migration * refactor: extract module platform context * refactor: assign models to domain contexts * refactor: extract ai platform context * refactor: extract storage platform context * refactor: extract mail platform context * refactor: extract pdf platform context * refactor: extract operations platform context * refactor: move installation into operations platform * refactor: extract money domain context * refactor: extract taxation domain context * refactor: extract catalog domain context * refactor: extract metadata domain context * refactor: extract reporting domain context * refactor: extract purchases domain context * refactor: extract receivables domain context * refactor: extract accounts domain context * refactor: complete reporting statement boundary * refactor: extract contacts domain context * refactor: extract sales domain context * refactor: remove legacy application layers * fix: migrate legacy bouncer role identities
66 lines
2.1 KiB
PHP
66 lines
2.1 KiB
PHP
<?php
|
|
|
|
use App\Domains\Accounts\Models\User;
|
|
use App\Platform\Pdf\Rules\PdfTemplateExists;
|
|
use Illuminate\Support\Facades\Artisan;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Laravel\Sanctum\Sanctum;
|
|
|
|
use function Pest\Laravel\postJson;
|
|
|
|
/**
|
|
* template_name was validated only as `required`, so any string was stored and
|
|
* the failure surfaced much later as a raw "view not found" 500 when someone
|
|
* tried to generate the PDF.
|
|
*/
|
|
beforeEach(function () {
|
|
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
|
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
|
|
|
$user = User::find(1);
|
|
$this->company = $user->companies()->first();
|
|
$this->withHeaders(['company' => $this->company->id]);
|
|
Sanctum::actingAs($user, ['*']);
|
|
});
|
|
|
|
test('the rule accepts a template the picker offers', function () {
|
|
$validator = Validator::make(
|
|
['template_name' => 'invoice1'],
|
|
['template_name' => [new PdfTemplateExists('invoice')]]
|
|
);
|
|
|
|
expect($validator->fails())->toBeFalse();
|
|
});
|
|
|
|
test('the rule rejects a template that does not exist', function () {
|
|
$validator = Validator::make(
|
|
['template_name' => 'no-such-template'],
|
|
['template_name' => [new PdfTemplateExists('invoice')]]
|
|
);
|
|
|
|
expect($validator->fails())->toBeTrue();
|
|
});
|
|
|
|
/**
|
|
* The types are separate directories, so an estimate template is not a valid
|
|
* invoice template even though both exist.
|
|
*/
|
|
test('the rule is scoped to the document type', function () {
|
|
$validator = Validator::make(
|
|
['template_name' => 'estimate1'],
|
|
['template_name' => [new PdfTemplateExists('invoice')]]
|
|
);
|
|
|
|
expect($validator->fails())->toBeTrue();
|
|
});
|
|
|
|
test('creating an invoice with an unknown template fails validation, not at render time', function () {
|
|
postJson('/api/v1/invoices', [
|
|
'invoice_date' => '2026-01-01',
|
|
'due_date' => '2026-01-31',
|
|
'customer_id' => 1,
|
|
'template_name' => 'definitely-not-a-template',
|
|
'items' => [],
|
|
])->assertStatus(422)->assertJsonValidationErrors('template_name');
|
|
});
|