Creating Participation refunds
This commit is contained in:
@@ -212,4 +212,110 @@ class DocumentTemplateAdminTest extends TestCase
|
||||
|
||||
$this->assertNull(DocumentAsset::where('name', 'altbestand')->first());
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Mehrere Dokumentarten
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public function test_the_default_document_type_is_the_invoice(): void
|
||||
{
|
||||
$this->actingAs($this->makeUser(UserRole::USER_ROLE_ADMIN));
|
||||
|
||||
$this->getJson('/api/v1/admin/document-templates')
|
||||
->assertOk()
|
||||
->assertJsonPath('documentType', DocumentTemplate::TYPE_PARTICIPANT_INVOICE)
|
||||
->assertJsonPath('documentTypes.0.value', DocumentTemplate::TYPE_PARTICIPANT_INVOICE)
|
||||
->assertJsonPath('documentTypes.1.value', DocumentTemplate::TYPE_PARTICIPANT_REFUND);
|
||||
}
|
||||
|
||||
public function test_the_refund_type_returns_its_own_blocks_and_tokens(): void
|
||||
{
|
||||
$this->actingAs($this->makeUser(UserRole::USER_ROLE_ADMIN));
|
||||
|
||||
DocumentTemplate::create([
|
||||
'document_type' => DocumentTemplate::TYPE_PARTICIPANT_REFUND,
|
||||
'block' => 'subject',
|
||||
'content' => 'Rückerstattung {document_number}',
|
||||
'sort_order' => 10,
|
||||
]);
|
||||
|
||||
$response = $this->getJson('/api/v1/admin/document-templates?type=participant_refund');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonPath('documentType', DocumentTemplate::TYPE_PARTICIPANT_REFUND);
|
||||
$response->assertJsonCount(1, 'blocks');
|
||||
$response->assertJsonPath('blocks.0.block', 'subject');
|
||||
// Die Platzhalter sind die des Belegs, nicht die der Rechnung.
|
||||
$response->assertJsonPath('tokenGroups.refund.tokens.refund_amount.description', 'Erstattungsbetrag');
|
||||
$response->assertJsonMissingPath('tokenGroups.body.tokens.positions_table');
|
||||
}
|
||||
|
||||
public function test_saving_writes_only_into_the_selected_type(): void
|
||||
{
|
||||
$this->actingAs($this->makeUser(UserRole::USER_ROLE_ADMIN));
|
||||
|
||||
DocumentTemplate::create([
|
||||
'document_type' => DocumentTemplate::TYPE_PARTICIPANT_REFUND,
|
||||
'block' => 'footer',
|
||||
'content' => 'Beleg-Fuß',
|
||||
'sort_order' => 20,
|
||||
]);
|
||||
|
||||
$this->postJson('/api/v1/admin/document-templates', [
|
||||
'type' => DocumentTemplate::TYPE_PARTICIPANT_REFUND,
|
||||
'blocks' => ['footer' => 'neuer Beleg-Fuß'],
|
||||
])->assertOk()->assertJsonPath('status', 'success');
|
||||
|
||||
$this->assertSame('neuer Beleg-Fuß', DocumentTemplate::where('document_type', DocumentTemplate::TYPE_PARTICIPANT_REFUND)
|
||||
->where('block', 'footer')->first()->content);
|
||||
|
||||
// Der gleichnamige Block der Rechnung bleibt unberührt.
|
||||
$this->assertSame('alt', DocumentTemplate::where('document_type', DocumentTemplate::TYPE_PARTICIPANT_INVOICE)
|
||||
->where('block', 'footer')->first()->content);
|
||||
}
|
||||
|
||||
public function test_an_unknown_document_type_is_refused(): void
|
||||
{
|
||||
$this->actingAs($this->makeUser(UserRole::USER_ROLE_ADMIN));
|
||||
|
||||
$this->getJson('/api/v1/admin/document-templates?type=erfunden')->assertStatus(422);
|
||||
|
||||
$this->postJson('/api/v1/admin/document-templates', [
|
||||
'type' => 'erfunden',
|
||||
'blocks' => ['footer' => 'egal'],
|
||||
])->assertStatus(422);
|
||||
|
||||
$this->post('/api/v1/admin/document-templates/preview', [
|
||||
'type' => 'erfunden',
|
||||
'blocks' => [],
|
||||
])->assertStatus(422);
|
||||
|
||||
// Die Rechnungsvorlage darf davon nichts abbekommen haben.
|
||||
$this->assertSame('alt', DocumentTemplate::where('document_type', DocumentTemplate::TYPE_PARTICIPANT_INVOICE)
|
||||
->where('block', 'footer')->first()->content);
|
||||
}
|
||||
|
||||
public function test_preview_renders_the_refund_with_its_sample_data(): void
|
||||
{
|
||||
$this->actingAs($this->makeUser(UserRole::USER_ROLE_ADMIN));
|
||||
|
||||
DocumentTemplate::create([
|
||||
'document_type' => DocumentTemplate::TYPE_PARTICIPANT_REFUND,
|
||||
'block' => DocumentTemplate::BLOCK_LAYOUT,
|
||||
'content' => '<div>{document_number}</div>',
|
||||
'sort_order' => 10,
|
||||
]);
|
||||
|
||||
$response = $this->post('/api/v1/admin/document-templates/preview', [
|
||||
'type' => DocumentTemplate::TYPE_PARTICIPANT_REFUND,
|
||||
'blocks' => [],
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertHeader('Content-Type', 'application/pdf');
|
||||
$this->assertStringStartsWith('%PDF', $response->getContent());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user