Add download route for quote pdf

This commit is contained in:
David Bomba 2023-02-01 19:52:38 +11:00
parent 4c12e023e4
commit be03714aa4
3 changed files with 20 additions and 0 deletions

View File

@ -782,6 +782,11 @@ class QuoteController extends BaseController
public function downloadPdf($invitation_key)
{
$invitation = $this->quote_repo->getInvitationByKey($invitation_key);
if (! $invitation) {
return response()->json(['message' => 'no record found'], 400);
}
$contact = $invitation->contact;
$quote = $invitation->quote;

View File

@ -245,6 +245,7 @@ Route::group(['middleware' => ['throttle:300,1', 'api_db', 'token_auth', 'locale
Route::get('quotes/{quote}/{action}', [QuoteController::class, 'action'])->name('quotes.action');
Route::post('quotes/bulk', [QuoteController::class, 'bulk'])->name('quotes.bulk');
Route::put('quotes/{quote}/upload', [QuoteController::class, 'upload']);
Route::get('quote/{invitation_key}/download', [QuoteController::class, 'downloadPdf'])->name('quotes.downloadPdf');
Route::resource('recurring_expenses', RecurringExpenseController::class);
Route::post('recurring_expenses/bulk', [RecurringExpenseController::class, 'bulk'])->name('recurring_expenses.bulk');

View File

@ -50,6 +50,20 @@ class QuoteTest extends TestCase
);
}
public function testQuoteDownloadPDF()
{
$i = $this->quote->invitations->first();
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->get("/api/v1/quote/{$i->key}/download");
$response->assertStatus(200);
$this->assertTrue($response->headers->get('content-type') == 'application/pdf');
}
public function testQuoteListApproved()
{
$response = $this->withHeaders([