Allow custom designs to be passed into the live designer

This commit is contained in:
David Bomba 2023-03-24 12:41:02 +11:00
parent 19e2e98665
commit da92505de1
4 changed files with 42 additions and 7 deletions

View File

@ -47,6 +47,7 @@ class DesignPreviewRequest extends Request
'settings' => 'sometimes', 'settings' => 'sometimes',
'group_id' => 'sometimes', 'group_id' => 'sometimes',
'client_id' => 'sometimes', 'client_id' => 'sometimes',
'design' => 'bail|sometimes|array'
]; ];
return $rules; return $rules;

View File

@ -47,6 +47,15 @@ class PdfDesigner
return $this; return $this;
} }
public function buildFromPartials(array $partials): self
{
$this->template = $this->composeFromPartials($partials);
return $this;
}
/** /**
* If the user has implemented a custom design, then we need to rebuild the design at this point * If the user has implemented a custom design, then we need to rebuild the design at this point
*/ */
@ -54,10 +63,8 @@ class PdfDesigner
/** /**
* Returns the custom HTML design as * Returns the custom HTML design as
* a string * a string
* * @param array $partials
* @param array
* @return string * @return string
*
*/ */
private function composeFromPartials(array $partials) :string private function composeFromPartials(array $partials) :string
{ {

View File

@ -69,7 +69,11 @@ class PdfMock
$pdf_service->config = $pdf_config; $pdf_service->config = $pdf_config;
$pdf_designer = (new PdfDesigner($pdf_service))->build(); if(isset($this->request['design']))
$pdf_designer = (new PdfDesigner($pdf_service))->buildFromPartials($this->request['design']);
else
$pdf_designer = (new PdfDesigner($pdf_service))->build();
$pdf_service->designer = $pdf_designer; $pdf_service->designer = $pdf_designer;
$pdf_service->html_variables = $document_type == 'purchase_order' ? $this->getVendorStubVariables() : $this->getStubVariables(); $pdf_service->html_variables = $document_type == 'purchase_order' ? $this->getVendorStubVariables() : $this->getStubVariables();

View File

@ -11,10 +11,11 @@
namespace Tests\Feature; namespace Tests\Feature;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Tests\MockAccountData;
use Tests\TestCase; use Tests\TestCase;
use App\Models\Design;
use Tests\MockAccountData;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Illuminate\Foundation\Testing\DatabaseTransactions;
/** /**
* @test * @test
@ -55,4 +56,26 @@ class LiveDesignTest extends TestCase
$response->assertStatus(200); $response->assertStatus(200);
} }
public function testDesignWithCustomDesign()
{
$d = Design::find(1);
$data = [
'entity_type' => 'invoice',
'settings_type' => 'company',
'settings' => (array)$this->company->settings,
'design' => (array)$d->design,
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/live_design/', $data);
$response->assertStatus(200);
}
} }