mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-05 18:23:48 +00:00
added it_get_all_invoices_from_admin, it_get_single_user_invoice_page test
This commit is contained in:
@@ -5,9 +5,9 @@ namespace App\Http\Controllers\Admin;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\InvoiceAdminCollection;
|
||||
use App\Http\Resources\InvoiceResource;
|
||||
use App\Invoice;
|
||||
use App\Models\Invoice;
|
||||
use App\Services\StripeService;
|
||||
use App\Setting;
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class InvoiceController extends Controller
|
||||
@@ -37,7 +37,7 @@ class InvoiceController extends Controller
|
||||
*
|
||||
* @param $customer
|
||||
* @param $token
|
||||
* @return InvoiceResource
|
||||
* @return InvoiceResource|\Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function show($customer, $token)
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\User;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Laravel\Cashier\Cashier;
|
||||
|
||||
@@ -16,7 +16,8 @@ class InvoiceAdminResource extends JsonResource
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
$user = User::where('stripe_id', $this['customer'])->first();
|
||||
$user = User::where('stripe_id', $this['customer'])
|
||||
->first();
|
||||
|
||||
return [
|
||||
'data' => [
|
||||
@@ -29,7 +30,7 @@ class InvoiceAdminResource extends JsonResource
|
||||
'created_at_formatted' => format_date($this['created']),
|
||||
'created_at' => $this['created'],
|
||||
'order' => $this['number'],
|
||||
'user_id' => $user ? $user->id : null,
|
||||
'user_id' => $user->id ?? null,
|
||||
'client' => [
|
||||
'billing_address' => $this['customer_address'],
|
||||
'billing_name' => $this['customer_name'],
|
||||
@@ -42,24 +43,24 @@ class InvoiceAdminResource extends JsonResource
|
||||
'description' => $this['lines']['data'][0]['description'],
|
||||
],
|
||||
'seller' => null,
|
||||
]
|
||||
],
|
||||
$this->mergeWhen($user, function () use ($user) {
|
||||
return [
|
||||
'relationships' => [
|
||||
'user' => [
|
||||
'data' => [
|
||||
'id' => (string)$user->id,
|
||||
'type' => 'user',
|
||||
'attributes' => [
|
||||
'name' => $user->name,
|
||||
'avatar' => $user->avatar,
|
||||
],
|
||||
$this->mergeWhen($user, function () use ($user) {
|
||||
return [
|
||||
'relationships' => [
|
||||
'user' => [
|
||||
'data' => [
|
||||
'id' => $user->id,
|
||||
'type' => 'user',
|
||||
'attributes' => [
|
||||
'name' => $user->name,
|
||||
'avatar' => $user->avatar,
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
}),
|
||||
];
|
||||
}),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -333,7 +333,10 @@ class StripeService
|
||||
*/
|
||||
public function deletePlan($slug)
|
||||
{
|
||||
$this->stripe->plans()->delete($slug);
|
||||
$this
|
||||
->stripe
|
||||
->plans()
|
||||
->delete($slug);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -344,20 +347,22 @@ class StripeService
|
||||
*/
|
||||
public function getUserInvoices($user)
|
||||
{
|
||||
return $user->invoices();
|
||||
return $user
|
||||
->invoices();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user invoice by id
|
||||
*
|
||||
* @param $customer
|
||||
* @param $id
|
||||
* @return \Laravel\Cashier\Invoice|null
|
||||
*/
|
||||
public function getUserInvoice($customer, $id)
|
||||
{
|
||||
$user = User::where('stripe_id', $customer)->firstOrFail();
|
||||
|
||||
return $user->findInvoice($id);
|
||||
return User::whereStripeId($customer)
|
||||
->firstOrFail()
|
||||
->findInvoice($id);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -367,8 +372,11 @@ class StripeService
|
||||
*/
|
||||
public function getInvoices()
|
||||
{
|
||||
return $this->stripe->invoices()->all([
|
||||
'limit' => 20
|
||||
]);
|
||||
return $this
|
||||
->stripe
|
||||
->invoices()
|
||||
->all([
|
||||
'limit' => 20
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -46,11 +46,7 @@ Route::group(['prefix' => 'pages'], function () {
|
||||
});
|
||||
|
||||
// Invoices
|
||||
// TODO: testy
|
||||
Route::group(['prefix' => 'invoices'], function () {
|
||||
Route::get('/{token}', [InvoiceController::class, 'show']);
|
||||
Route::get('/', [InvoiceController::class, 'index']);
|
||||
});
|
||||
Route::get('/invoices', [InvoiceController::class, 'index']);
|
||||
|
||||
// Settings
|
||||
Route::group(['prefix' => 'settings'], function () {
|
||||
|
||||
@@ -29,7 +29,7 @@ Route::group(['middleware' => ['auth:api', 'auth.shared', 'auth.master', 'scope:
|
||||
});
|
||||
|
||||
// Get user invoice
|
||||
Route::group(['middleware' => ['auth:api', 'auth.master', 'scope:master']], function () {
|
||||
Route::group(['middleware' => ['auth:sanctum']], function () {
|
||||
Route::get('/invoice/{customer}/{token}', [InvoiceController::class, 'show']);
|
||||
});
|
||||
|
||||
|
||||
@@ -273,28 +273,6 @@ class SubscriptionTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function it_get_user_invoices_from_admin()
|
||||
{
|
||||
$user = User::factory(User::class)
|
||||
->create($this->user);
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$admin = User::factory(User::class)
|
||||
->create(['role' => 'admin']);
|
||||
|
||||
Sanctum::actingAs($admin);
|
||||
|
||||
$this->getJson("/api/admin/users/$user->id/invoices")
|
||||
->assertStatus(200)
|
||||
->assertJsonFragment([
|
||||
'customer' => $this->user['stripe_id']
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@@ -324,61 +302,6 @@ class SubscriptionTest extends TestCase
|
||||
])->assertStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function it_get_all_plans_from_admin()
|
||||
{
|
||||
$admin = User::factory(User::class)
|
||||
->create(['role' => 'admin']);
|
||||
|
||||
Sanctum::actingAs($admin);
|
||||
|
||||
$this->getJson('/api/admin/plans')
|
||||
->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function it_get_single_plan_from_admin()
|
||||
{
|
||||
$admin = User::factory(User::class)
|
||||
->create(['role' => 'admin']);
|
||||
|
||||
Sanctum::actingAs($admin);
|
||||
|
||||
$this->getJson('/api/admin/plans/' . $this->plan['data']['id'])
|
||||
->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function it_create_single_plan_from_admin()
|
||||
{
|
||||
$admin = User::factory(User::class)
|
||||
->create(['role' => 'admin']);
|
||||
|
||||
Sanctum::actingAs($admin);
|
||||
|
||||
$plan_name = 'test-plan-' . Str::random(16);
|
||||
|
||||
$this->postJson('/api/admin/plans', [
|
||||
'type' => 'plan',
|
||||
'attributes' => [
|
||||
'name' => $plan_name,
|
||||
'price' => (string)rand(1, 99),
|
||||
'description' => 'Some random description',
|
||||
'capacity' => rand(1, 999),
|
||||
],
|
||||
])
|
||||
->assertStatus(201)
|
||||
->assertJsonFragment([
|
||||
'name' => $plan_name
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@@ -470,4 +393,123 @@ class SubscriptionTest extends TestCase
|
||||
'id' => $user->id
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function it_get_all_invoices_from_admin()
|
||||
{
|
||||
$admin = User::factory(User::class)
|
||||
->create(['role' => 'admin']);
|
||||
|
||||
Sanctum::actingAs($admin);
|
||||
|
||||
$this->getJson("/api/admin/invoices")
|
||||
->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function it_get_single_user_invoice_page_from_admin()
|
||||
{
|
||||
$user = User::factory(User::class)
|
||||
->create($this->user);
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$invoices = $this->getJson('/api/user/invoices')
|
||||
->assertStatus(200)
|
||||
->assertJsonFragment([
|
||||
'customer' => $this->user['stripe_id']
|
||||
]);
|
||||
|
||||
$admin = User::factory(User::class)
|
||||
->create(['role' => 'admin']);
|
||||
|
||||
Sanctum::actingAs($admin);
|
||||
|
||||
$invoice_id = json_decode($invoices->content(), true)['data'][0]['data']['id'];
|
||||
|
||||
$this->get("/invoice/{$this->user['stripe_id']}/$invoice_id")
|
||||
->assertStatus(200)
|
||||
->assertSee('Invoice');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function it_get_user_invoices_from_admin()
|
||||
{
|
||||
$user = User::factory(User::class)
|
||||
->create($this->user);
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$admin = User::factory(User::class)
|
||||
->create(['role' => 'admin']);
|
||||
|
||||
Sanctum::actingAs($admin);
|
||||
|
||||
$this->getJson("/api/admin/users/$user->id/invoices")
|
||||
->assertStatus(200)
|
||||
->assertJsonFragment([
|
||||
'customer' => $this->user['stripe_id']
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function it_get_all_plans_from_admin()
|
||||
{
|
||||
$admin = User::factory(User::class)
|
||||
->create(['role' => 'admin']);
|
||||
|
||||
Sanctum::actingAs($admin);
|
||||
|
||||
$this->getJson('/api/admin/plans')
|
||||
->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function it_get_single_plan_from_admin()
|
||||
{
|
||||
$admin = User::factory(User::class)
|
||||
->create(['role' => 'admin']);
|
||||
|
||||
Sanctum::actingAs($admin);
|
||||
|
||||
$this->getJson('/api/admin/plans/' . $this->plan['data']['id'])
|
||||
->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function it_create_single_plan_from_admin()
|
||||
{
|
||||
$admin = User::factory(User::class)
|
||||
->create(['role' => 'admin']);
|
||||
|
||||
Sanctum::actingAs($admin);
|
||||
|
||||
$plan_name = 'test-plan-' . Str::random(16);
|
||||
|
||||
$this->postJson('/api/admin/plans', [
|
||||
'type' => 'plan',
|
||||
'attributes' => [
|
||||
'name' => $plan_name,
|
||||
'price' => (string)rand(1, 99),
|
||||
'description' => 'Some random description',
|
||||
'capacity' => rand(1, 999),
|
||||
],
|
||||
])
|
||||
->assertStatus(201)
|
||||
->assertJsonFragment([
|
||||
'name' => $plan_name
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user