1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/tests/Integration/DownloadHistoricalInvoiceTest.php

105 lines
2.5 KiB
PHP
Raw Normal View History

2020-08-12 02:01:27 +02:00
<?php
2020-09-14 13:11:46 +02:00
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
2020-09-14 13:11:46 +02:00
*
* @license https://www.elastic.co/licensing/elastic-license
2020-09-14 13:11:46 +02:00
*/
2020-08-12 02:01:27 +02:00
namespace Tests\Integration;
use App\Repositories\ActivityRepository;
use App\Utils\Ninja;
use App\Utils\Traits\MakesHash;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\MockAccountData;
use Tests\TestCase;
/**
* @test
* @covers App\Http\Controllers\ActivityController
2023-11-16 01:36:14 +01:00
*/
2020-08-12 02:01:27 +02:00
class DownloadHistoricalInvoiceTest extends TestCase
{
use MockAccountData;
use DatabaseTransactions;
use MakesHash;
protected function setUp() :void
2020-08-12 02:01:27 +02:00
{
parent::setUp();
$this->makeTestData();
2021-10-24 11:47:38 +02:00
if (config('ninja.testvars.travis') !== false) {
$this->markTestSkipped('Skip test for Travis');
}
2020-08-12 02:01:27 +02:00
}
2023-11-16 01:36:14 +01:00
public function testDownloadInvoiceRoute()
{
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->get("/api/v1/invoices/{$this->invoice->hashed_id}/download");
$response->assertStatus(200);
$response->assertDownload();
}
public function testDownloadDeliveryRoute()
{
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->get("/api/v1/invoices/{$this->invoice->hashed_id}/delivery_note");
$response->assertStatus(200);
$response->assertDownload();
}
public function testDownloadInvoiceBulkActionRoute()
{
$data = [
'action' => 'download',
'ids' => [$this->invoice->hashed_id],
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post("/api/v1/invoices/bulk", $data);
$response->assertStatus(200);
$response->assertDownload();
}
2020-08-12 02:01:27 +02:00
private function mockActivity()
{
$activity_repo = new ActivityRepository();
$obj = new \stdClass;
$obj->invoice_id = $this->invoice->id;
$obj->user_id = $this->invoice->user_id;
$obj->company_id = $this->company->id;
$activity_repo->save($obj, $this->invoice, Ninja::eventVars());
}
2020-08-12 02:01:27 +02:00
public function testActivityAccessible()
{
$this->mockActivity();
$this->assertNotNull($this->invoice->activities);
}
}