2019-06-20 08:18:34 +10:00
|
|
|
<?php
|
2020-09-14 21:11:46 +10:00
|
|
|
/**
|
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
|
*
|
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
|
*
|
2021-01-04 08:54:54 +11:00
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-09-14 21:11:46 +10:00
|
|
|
*
|
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
|
*/
|
2019-06-20 08:18:34 +10:00
|
|
|
namespace Tests\Feature;
|
|
|
|
|
|
2019-11-12 22:36:24 +11:00
|
|
|
use App\DataMapper\CompanySettings;
|
2019-06-20 08:18:34 +10:00
|
|
|
use App\Models\Company;
|
2019-06-25 15:08:07 +10:00
|
|
|
use App\Models\CompanyToken;
|
2019-06-20 08:18:34 +10:00
|
|
|
use App\Utils\Traits\MakesHash;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
2019-06-26 13:25:14 +10:00
|
|
|
use Illuminate\Http\UploadedFile;
|
2019-06-20 08:18:34 +10:00
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
use Illuminate\Support\Facades\Session;
|
2020-05-14 19:08:49 +10:00
|
|
|
use Tests\MockAccountData;
|
2019-06-20 08:18:34 +10:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @test
|
|
|
|
|
* @covers App\Http\Controllers\CompanyController
|
|
|
|
|
*/
|
|
|
|
|
class CompanyTest extends TestCase
|
|
|
|
|
{
|
|
|
|
|
use MakesHash;
|
2020-05-14 19:08:49 +10:00
|
|
|
use MockAccountData;
|
2019-06-20 08:18:34 +10:00
|
|
|
use DatabaseTransactions;
|
|
|
|
|
|
|
|
|
|
public function setUp() :void
|
|
|
|
|
{
|
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
|
|
Session::start();
|
|
|
|
|
|
|
|
|
|
$this->faker = \Faker\Factory::create();
|
|
|
|
|
|
|
|
|
|
Model::reguard();
|
2020-05-14 19:08:49 +10:00
|
|
|
|
|
|
|
|
$this->makeTestData();
|
2019-06-20 08:18:34 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testCompanyList()
|
|
|
|
|
{
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
2020-05-14 19:08:49 +10:00
|
|
|
'X-API-TOKEN' => $this->token,
|
2019-06-20 16:20:14 +10:00
|
|
|
])->get('/api/v1/companies');
|
2019-06-20 08:18:34 +10:00
|
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
2020-05-14 19:08:49 +10:00
|
|
|
'X-API-TOKEN' => $this->token,
|
2020-03-21 16:37:30 +11:00
|
|
|
])->post(
|
|
|
|
|
'/api/v1/companies?include=company',
|
2019-06-20 08:18:34 +10:00
|
|
|
[
|
2019-06-26 13:25:14 +10:00
|
|
|
'name' => 'A New Company',
|
2020-09-06 19:38:10 +10:00
|
|
|
'logo' => UploadedFile::fake()->image('avatar.jpg'),
|
2019-06-20 08:18:34 +10:00
|
|
|
]
|
|
|
|
|
)
|
2019-06-25 15:08:07 +10:00
|
|
|
->assertStatus(200)->decodeResponseJson();
|
2019-10-23 12:01:25 +11:00
|
|
|
|
2020-03-21 16:37:30 +11:00
|
|
|
$company = Company::find($this->decodePrimaryKey($response['data'][0]['company']['id']));
|
2019-06-26 13:25:14 +10:00
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
2020-05-14 19:08:49 +10:00
|
|
|
'X-API-TOKEN' => $this->token,
|
2020-03-21 16:37:30 +11:00
|
|
|
])->post(
|
|
|
|
|
'/api/v1/companies/',
|
2019-06-26 13:25:14 +10:00
|
|
|
[
|
|
|
|
|
'name' => 'A New Company',
|
2020-09-06 19:38:10 +10:00
|
|
|
'company_logo' => UploadedFile::fake()->create('avatar.pdf', 100),
|
2019-06-26 13:25:14 +10:00
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
->assertStatus(302);
|
|
|
|
|
|
2020-03-21 16:37:30 +11:00
|
|
|
// Log::error($company);
|
2019-06-26 13:25:14 +10:00
|
|
|
|
2020-05-14 19:08:49 +10:00
|
|
|
$this->token = CompanyToken::whereCompanyId($company->id)->first()->token;
|
2019-06-20 08:18:34 +10:00
|
|
|
|
2019-06-20 16:20:14 +10:00
|
|
|
$company_update = [
|
2019-06-26 13:25:14 +10:00
|
|
|
'name' => 'CHANGE NAME',
|
|
|
|
|
// 'logo' => UploadedFile::fake()->image('avatar.jpg')
|
2019-06-20 08:18:34 +10:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
2020-05-14 19:08:49 +10:00
|
|
|
'X-API-TOKEN' => $this->token,
|
2019-06-20 16:20:14 +10:00
|
|
|
])->put('/api/v1/companies/'.$this->encodePrimaryKey($company->id), $company_update)
|
2019-06-20 08:18:34 +10:00
|
|
|
->assertStatus(200);
|
|
|
|
|
|
2019-11-12 22:36:24 +11:00
|
|
|
$settings = CompanySettings::defaults();
|
2019-10-23 12:01:25 +11:00
|
|
|
$settings->custom_value1 = 'test';
|
2019-10-23 17:21:16 +11:00
|
|
|
$settings->invoice_design_id = '2';
|
2020-03-06 22:10:59 +11:00
|
|
|
$settings->quote_design_id = '1';
|
2019-10-23 12:01:25 +11:00
|
|
|
|
|
|
|
|
$company->settings = $settings;
|
|
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
2020-05-14 19:08:49 +10:00
|
|
|
'X-API-TOKEN' => $this->token,
|
2019-10-23 12:01:25 +11:00
|
|
|
])->put('/api/v1/companies/'.$this->encodePrimaryKey($company->id), $company->toArray())
|
|
|
|
|
->assertStatus(200)->decodeResponseJson();
|
2019-10-23 17:21:16 +11:00
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
2020-05-14 19:08:49 +10:00
|
|
|
'X-API-TOKEN' => $this->token,
|
2019-10-23 17:21:16 +11:00
|
|
|
])->get('/api/v1/companies/'.$this->encodePrimaryKey($company->id))
|
|
|
|
|
->assertStatus(200)->decodeResponseJson();
|
|
|
|
|
|
2019-06-20 08:18:34 +10:00
|
|
|
$response = $this->withHeaders([
|
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
2020-05-14 19:08:49 +10:00
|
|
|
'X-API-TOKEN' => $this->token,
|
2019-06-20 16:20:14 +10:00
|
|
|
])->delete('/api/v1/companies/'.$this->encodePrimaryKey($company->id))
|
2019-06-20 08:18:34 +10:00
|
|
|
->assertStatus(200);
|
2020-03-21 16:37:30 +11:00
|
|
|
}
|
2019-06-20 08:18:34 +10:00
|
|
|
}
|