1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00
This commit is contained in:
David Bomba 2020-07-28 22:05:17 +10:00
parent caad3661d5
commit de78ea1506
2 changed files with 103 additions and 1 deletions

View File

@ -17,6 +17,7 @@ use App\Http\Controllers\BaseController;
use App\Http\Requests\Client\StoreClientRequest; use App\Http\Requests\Client\StoreClientRequest;
use App\Models\Client; use App\Models\Client;
use App\Models\ClientContact; use App\Models\ClientContact;
use App\Models\Company;
use App\Models\CompanyToken; use App\Models\CompanyToken;
use App\Repositories\ClientRepository; use App\Repositories\ClientRepository;
use App\Transformers\ClientTransformer; use App\Transformers\ClientTransformer;
@ -48,7 +49,7 @@ class ClientController extends BaseController
$this->client_repo = $client_repo; $this->client_repo = $client_repo;
} }
public function show(string $contact_key) public function show(Request $request, string $contact_key)
{ {
$company = Company::where('company_key', $request->header('X-API-COMPANY_KEY'))->first(); $company = Company::where('company_key', $request->header('X-API-COMPANY_KEY'))->first();

View File

@ -0,0 +1,101 @@
<?php
namespace Tests\Feature\Shop;
use App\Factory\CompanyUserFactory;
use App\Models\CompanyToken;
use App\Utils\Traits\MakesHash;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Tests\MockAccountData;
use Tests\TestCase;
/**
* @test
* @covers App\Http\Controllers\Shop\InvoiceController
*/
class ShopInvoiceTest extends TestCase
{
use MakesHash;
use MockAccountData;
public function setUp() :void
{
parent::setUp();
$this->withoutMiddleware(
ThrottleRequests::class
);
$this->faker = \Faker\Factory::create();
Model::reguard();
$this->makeTestData();
$this->withoutExceptionHandling();
}
public function testTokenFailure()
{
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-COMPANY_KEY' => $this->company->company_key
])->get('/api/v1/shop/products');
$response->assertStatus(200);
}
public function testTokenSuccess()
{
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-COMPANY_KEY' => $this->company->company_key
])->get('/api/v1/products');
$response->assertStatus(403);
$arr = $response->json();
}
public function testGetByProductKey()
{
$product = factory(\App\Models\Product::class)->create([
'user_id' => $this->user->id,
'company_id' => $this->company->id,
]);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-COMPANY_KEY' => $this->company->company_key
])->get('/api/v1/shop/product/'.$product->product_key);
$response->assertStatus(200);
$arr = $response->json();
$this->assertEquals($product->hashed_id, $arr['data']['id']);
}
public function testGetByClientByContactKey()
{
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-COMPANY_KEY' => $this->company->company_key
])->get('/api/v1/shop/client/'.$this->client->contacts->first()->contact_key);
$response->assertStatus(200);
$arr = $response->json();
$this->assertEquals($this->client->hashed_id, $arr['data']['id']);
}
}