From de78ea1506451693240f069b61a727111d39c06b Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 28 Jul 2020 22:05:17 +1000 Subject: [PATCH] Shop --- .../Controllers/Shop/ClientController.php | 3 +- tests/Feature/Shop/ShopInvoiceTest.php | 101 ++++++++++++++++++ 2 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 tests/Feature/Shop/ShopInvoiceTest.php diff --git a/app/Http/Controllers/Shop/ClientController.php b/app/Http/Controllers/Shop/ClientController.php index 7219e857e7..31002e57b4 100644 --- a/app/Http/Controllers/Shop/ClientController.php +++ b/app/Http/Controllers/Shop/ClientController.php @@ -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(); diff --git a/tests/Feature/Shop/ShopInvoiceTest.php b/tests/Feature/Shop/ShopInvoiceTest.php new file mode 100644 index 0000000000..26657dc6be --- /dev/null +++ b/tests/Feature/Shop/ShopInvoiceTest.php @@ -0,0 +1,101 @@ +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']); + + } +}