1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/tests/Feature/CompanyTest.php

132 lines
3.9 KiB
PHP
Raw Normal View History

2019-06-20 00:18:34 +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
*/
2019-06-20 00:18:34 +02:00
namespace Tests\Feature;
use App\DataMapper\CompanySettings;
2021-08-31 10:21:06 +02:00
use App\Http\Middleware\PasswordProtection;
2019-06-20 00:18:34 +02:00
use App\Models\Company;
2019-06-25 07:08:07 +02:00
use App\Models\CompanyToken;
2019-06-20 00:18:34 +02:00
use App\Utils\Traits\MakesHash;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Testing\DatabaseTransactions;
2019-06-26 05:25:14 +02:00
use Illuminate\Http\UploadedFile;
2019-06-20 00:18:34 +02:00
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Session;
use Tests\MockAccountData;
2019-06-20 00:18:34 +02:00
use Tests\TestCase;
/**
* @test
* @covers App\Http\Controllers\CompanyController
*/
class CompanyTest extends TestCase
{
use MakesHash;
use MockAccountData;
2019-06-20 00:18:34 +02:00
use DatabaseTransactions;
protected function setUp() :void
2019-06-20 00:18:34 +02:00
{
parent::setUp();
Session::start();
$this->faker = \Faker\Factory::create();
Model::reguard();
$this->makeTestData();
2019-06-20 00:18:34 +02:00
}
public function testCompanyList()
{
2021-08-31 10:21:06 +02:00
$this->withoutMiddleware(PasswordProtection::class);
2022-06-10 10:00:07 +02:00
// $cc = Company::first();
// $cc->delete();
2022-02-01 10:19:04 +01:00
2019-06-20 00:18:34 +02:00
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->get('/api/v1/companies');
2019-06-20 00:18:34 +02:00
$response->assertStatus(200);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post(
'/api/v1/companies?include=company',
2019-06-20 00:18:34 +02:00
[
2019-06-26 05:25:14 +02:00
'name' => 'A New Company',
'logo' => UploadedFile::fake()->image('avatar.jpg'),
2019-06-20 00:18:34 +02:00
]
)
2019-06-25 07:08:07 +02:00
->assertStatus(200)->decodeResponseJson();
$company = Company::find($this->decodePrimaryKey($response['data'][0]['company']['id']));
2019-06-26 05:25:14 +02:00
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post(
'/api/v1/companies/',
2019-06-26 05:25:14 +02:00
[
'name' => 'A New Company',
'company_logo' => UploadedFile::fake()->create('avatar.pdf', 100),
2019-06-26 05:25:14 +02:00
]
)
->assertStatus(302);
// Log::error($company);
2019-06-26 05:25:14 +02:00
$this->token = CompanyToken::whereCompanyId($company->id)->first()->token;
2019-06-20 00:18:34 +02:00
2019-06-20 08:20:14 +02:00
$company_update = [
2019-06-26 05:25:14 +02:00
'name' => 'CHANGE NAME',
// 'logo' => UploadedFile::fake()->image('avatar.jpg')
2019-06-20 00:18:34 +02:00
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
2022-06-24 03:55:41 +02:00
])->putJson('/api/v1/companies/'.$this->encodePrimaryKey($company->id), $company_update)
2019-06-20 00:18:34 +02:00
->assertStatus(200);
$settings = CompanySettings::defaults();
$settings->custom_value1 = 'test';
$settings->invoice_design_id = '2';
$settings->quote_design_id = '1';
$company->settings = $settings;
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
2022-06-24 03:55:41 +02:00
])->putJson('/api/v1/companies/'.$this->encodePrimaryKey($company->id), $company->toArray())
->assertStatus(200)->decodeResponseJson();
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->get('/api/v1/companies/'.$this->encodePrimaryKey($company->id))
->assertStatus(200)->decodeResponseJson();
2019-06-20 00:18:34 +02:00
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
2021-08-31 07:50:34 +02:00
'X-API-PASSWORD' => 'ALongAndBriliantPassword',
2019-06-20 08:20:14 +02:00
])->delete('/api/v1/companies/'.$this->encodePrimaryKey($company->id))
2019-06-20 00:18:34 +02:00
->assertStatus(200);
}
2019-06-20 00:18:34 +02:00
}