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

127 lines
3.5 KiB
PHP
Raw Normal View History

2019-06-20 00:18:34 +02:00
<?php
namespace Tests\Feature;
use App\Models\Account;
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\Models\Product;
use App\Models\User;
use App\Utils\Traits\MakesHash;
use Faker\Factory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Http\Request;
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\TestCase;
/**
* @test
* @covers App\Http\Controllers\CompanyController
*/
class CompanyTest extends TestCase
{
use MakesHash;
use DatabaseTransactions;
public function setUp() :void
{
parent::setUp();
Session::start();
$this->faker = \Faker\Factory::create();
Model::reguard();
}
public function testCompanyList()
{
$data = [
'first_name' => $this->faker->firstName,
'last_name' => $this->faker->lastName,
2019-09-29 10:46:53 +02:00
'name' => $this->faker->company,
2019-06-20 00:18:34 +02:00
'email' => $this->faker->unique()->safeEmail,
'password' => 'ALongAndBrilliantPassword123',
'_token' => csrf_token(),
'privacy_policy' => 1,
'terms_of_service' => 1
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
])->post('/api/v1/signup', $data);
$response->assertStatus(200);
$acc = $response->json();
2019-09-16 23:42:08 +02:00
$account = Account::find($this->decodePrimaryKey($acc['data'][0]['account']['id']));
2019-06-20 00:18:34 +02:00
$token = $account->default_company->tokens->first()->token;
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $token,
2019-06-20 08:20:14 +02:00
])->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' => $token,
])->post('/api/v1/companies/',
[
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();
2019-09-17 07:42:10 +02:00
$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' => $token,
])->post('/api/v1/companies/',
[
'name' => 'A New Company',
'logo' => UploadedFile::fake()->create('avatar.pdf',100)
]
)
->assertStatus(302);
2019-09-12 04:32:46 +02:00
// Log::error($company);
2019-06-26 05:25:14 +02:00
2019-06-25 07:08:07 +02:00
$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' => $token,
2019-06-20 08:20:14 +02:00
])->put('/api/v1/companies/'.$this->encodePrimaryKey($company->id), $company_update)
2019-06-20 00:18:34 +02:00
->assertStatus(200);
2019-06-26 05:25:14 +02:00
2019-06-20 00:18:34 +02:00
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $token,
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);
}
}