mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Company Logo upload test
This commit is contained in:
parent
db40a4ab71
commit
4e51256b51
@ -12,6 +12,7 @@
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Auth\Access\AuthorizationException;
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException as ModelNotFoundException;
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
@ -78,6 +79,10 @@ class Handler extends ExceptionHandler
|
||||
{
|
||||
return response()->json(['message'=>'Fatal error', 500]);
|
||||
}
|
||||
else if($exception instanceof AuthorizationException)
|
||||
{
|
||||
return response()->json(['message'=>'You are not authorized to view or perform this action',401]);
|
||||
}
|
||||
else if ($exception instanceof \Illuminate\Session\TokenMismatchException)
|
||||
{
|
||||
return redirect()
|
||||
|
@ -106,6 +106,7 @@ class CompanyController extends BaseController
|
||||
|
||||
if($request->file('logo'))
|
||||
{
|
||||
\Log::error('logo exists');
|
||||
$path = UploadAvatar::dispatchNow($request->file('logo'), $company->company_key);
|
||||
|
||||
if($path){
|
||||
@ -185,6 +186,7 @@ class CompanyController extends BaseController
|
||||
|
||||
if($request->file('logo'))
|
||||
{
|
||||
\Log::error('logo exists');
|
||||
$path = UploadAvatar::dispatchNow($request->file('logo'), $company->company_key);
|
||||
|
||||
if($path){
|
||||
|
@ -62,7 +62,7 @@ class CompanyPolicy extends EntityPolicy
|
||||
*/
|
||||
public function edit(User $user, $entity) : bool
|
||||
{
|
||||
|
||||
|
||||
return ($user->isAdmin() && $entity->id == $user->companyId())
|
||||
|| ($user->hasPermission('edit_' . strtolower(class_basename($entity))) && $entity->id == $user->companyId())
|
||||
|| $user->owns($entity);
|
||||
|
@ -58,8 +58,8 @@ class PaymentTransformer extends EntityTransformer
|
||||
'amount' => (float) $payment->amount,
|
||||
'transaction_reference' => $payment->transaction_reference ?: '',
|
||||
'payment_date' => $payment->payment_date ?: '',
|
||||
'updated_at' => $this->getTimestamp($payment->updated_at),
|
||||
'archived_at' => $this->getTimestamp($payment->deleted_at),
|
||||
'updated_at' => $payment->updated_at,
|
||||
'archived_at' => $payment->deleted_at,
|
||||
'is_deleted' => (bool) $payment->is_deleted,
|
||||
'payment_type_id' => (string) $payment->payment_type_id ?: '',
|
||||
'invitation_id' => (string) $payment->invitation_id ?: '',
|
||||
|
69
tests/Integration/UploadLogoTest.php
Normal file
69
tests/Integration/UploadLogoTest.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Integration;
|
||||
|
||||
use App\Events\Invoice\InvoiceWasCreated;
|
||||
use App\Events\Invoice\InvoiceWasUpdated;
|
||||
use App\Events\Payment\PaymentWasCreated;
|
||||
use App\Jobs\Invoice\MarkInvoicePaid;
|
||||
use App\Jobs\Util\UploadFile;
|
||||
use App\Models\Account;
|
||||
use App\Models\Activity;
|
||||
use App\Models\Company;
|
||||
use App\Models\CompanyLedger;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Models\User;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Foundation\Testing\Concerns\InteractsWithDatabase;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Tests\MockAccountData;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
class UploadLogoTest extends TestCase
|
||||
{
|
||||
use MockAccountData;
|
||||
use DatabaseTransactions;
|
||||
use MakesHash;
|
||||
|
||||
public function setUp() :void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->makeTestData();
|
||||
}
|
||||
|
||||
|
||||
public function testLogoUploadWorks()
|
||||
{
|
||||
|
||||
Storage::fake('avatars');
|
||||
|
||||
$data = [
|
||||
'logo' => UploadedFile::fake()->image('avatar.jpg'),
|
||||
'name' => 'TestCompany'
|
||||
];
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->put('/api/v1/companies/'.$this->encodePrimaryKey($this->company->id), $data);
|
||||
|
||||
$response->assertStatus(200);
|
||||
$acc = $response->json();
|
||||
$logo = $acc['data']['logo'];
|
||||
|
||||
$logo_file = Storage::url($logo);
|
||||
|
||||
$this->assertNotNull($logo_file);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user