1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

base api testS

This commit is contained in:
David Bomba 2023-01-21 08:09:39 +11:00
parent 883c8f2289
commit ca225846c2
2 changed files with 34 additions and 2 deletions

View File

@ -52,7 +52,6 @@ class AppServiceProvider extends ServiceProvider
// );
// });
Relation::morphMap([
'invoices' => Invoice::class,
'proposals' => Proposal::class,

View File

@ -14,6 +14,7 @@ namespace Tests\Feature;
use App\Factory\CompanyUserFactory;
use App\Models\CompanyToken;
use App\Models\CompanyUser;
use App\Models\Product;
use App\Models\User;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Illuminate\Support\Str;
@ -106,8 +107,40 @@ class BaseApiTest extends TestCase
// }
public function testOwnerRoutes()
{
public function testRestrictedRoute()
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->get('/api/v1/users/');
$response->assertStatus(200)
->assertJson(fn (AssertableJson $json) => $json->has('data',2)->etc());
/*does not test the number of records however*/
collect($this->list_routes)->each(function($route){
nlog($route);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->low_token,
])->get("/api/v1/{$route}/")
->assertJson(fn (AssertableJson $json) =>
$json->has('meta')
->has('data')
);
});
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->low_token,
])->get('/api/v1/companies/'.$this->company->hashed_id)
->assertStatus(401);
}
public function testRestrictedUserRoute()
{
// $permissions = ["view_invoice","view_client","edit_client","edit_invoice","create_invoice","create_client"];