Fixes for download routes

This commit is contained in:
David Bomba 2023-11-16 11:47:57 +11:00
parent 86015c66e0
commit adfff8e090
4 changed files with 37 additions and 17 deletions

View File

@ -701,12 +701,9 @@ class InvoiceController extends BaseController
break;
case 'download':
$file = $invoice->service()->getInvoicePdf();
$filename = $invoice->getFileName();
return response()->streamDownload(function () use ($file) {
echo $file;
}, $filename, ['Content-Type' => 'application/pdf']);
return response()->streamDownload(function () use ($invoice) {
echo $invoice->service()->getInvoicePdf();
}, $invoice->getFileName(), ['Content-Type' => 'application/pdf']);
case 'restore':
$this->invoice_repo->restore($invoice);

View File

@ -720,11 +720,9 @@ class QuoteController extends BaseController
break;
case 'download':
$file = $quote->service()->getQuotePdf();
return response()->streamDownload(function () use ($file) {
echo $file;
}, $quote->numberFormatter().".pdf", ['Content-Type' => 'application/pdf']);
return response()->streamDownload(function () use ($quote) {
echo $quote->service()->getQuotePdf();
}, $quote->getFileName(), ['Content-Type' => 'application/pdf']);
case 'restore':
$this->quote_repo->restore($quote);
@ -833,11 +831,9 @@ class QuoteController extends BaseController
$headers = array_merge($headers, ['Content-Disposition' => 'inline']);
}
$file = $quote->service()->getQuotePdf($contact);
return response()->streamDownload(function () use ($file) {
echo $file;
}, $quote->numberFormatter().".pdf", $headers);
return response()->streamDownload(function () use ($quote,$contact) {
echo $quote->service()->getQuotePdf($contact);
}, $quote->getFileName(), $headers);
}

View File

@ -249,7 +249,6 @@ class BaseModel extends Model
return \Illuminate\Support\Str::ascii($formatted_number);
}
/**

View File

@ -82,6 +82,34 @@ class DownloadHistoricalInvoiceTest extends TestCase
}
public function testDownloadQuoteRoute()
{
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->get("/api/v1/quotes/{$this->quote->hashed_id}/download");
$response->assertStatus(200);
$response->assertDownload();
}
public function testDownloadQuoteBulkActionRoute()
{
$data = [
'action' => 'download',
'ids' => [$this->quote->hashed_id],
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post("/api/v1/quotes/bulk", $data);
$response->assertStatus(200);
}
private function mockActivity()
{