mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
Shop
This commit is contained in:
parent
caad3661d5
commit
de78ea1506
@ -17,6 +17,7 @@ use App\Http\Controllers\BaseController;
|
||||
use App\Http\Requests\Client\StoreClientRequest;
|
||||
use App\Models\Client;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\Company;
|
||||
use App\Models\CompanyToken;
|
||||
use App\Repositories\ClientRepository;
|
||||
use App\Transformers\ClientTransformer;
|
||||
@ -48,7 +49,7 @@ class ClientController extends BaseController
|
||||
$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();
|
||||
|
||||
|
101
tests/Feature/Shop/ShopInvoiceTest.php
Normal file
101
tests/Feature/Shop/ShopInvoiceTest.php
Normal 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']);
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user