diff --git a/app/Http/Controllers/Admin/PlanController.php b/app/Http/Controllers/Admin/PlanController.php
index 9240207f..78cee169 100644
--- a/app/Http/Controllers/Admin/PlanController.php
+++ b/app/Http/Controllers/Admin/PlanController.php
@@ -29,7 +29,7 @@ class PlanController extends Controller
/**
* Get all plans
*
- * @return PlanCollection
+ * @return PlanCollection|\Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response
*/
public function index()
{
@@ -42,14 +42,14 @@ class PlanController extends Controller
});
}
- return new PlanCollection($plans);
+ return response(new PlanCollection($plans), 200);
}
/**
* Get plan record
*
* @param $id
- * @return PlanResource
+ * @return PlanResource|\Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response
*/
public function show($id)
{
@@ -62,7 +62,7 @@ class PlanController extends Controller
});
}
- return new PlanResource($plan);
+ return response(new PlanResource($plan), 200);
}
/**
@@ -73,6 +73,7 @@ class PlanController extends Controller
*/
public function store(Request $request)
{
+ // TODO: inline request
if (env('APP_DEMO')) {
if (Cache::has('plan-starter-pack')) {
@@ -115,7 +116,7 @@ class PlanController extends Controller
// Clear cached plans
cache_forget_many(['plans', 'pricing', 'plan-' . $id]);
- return response('Saved!', 204);
+ return response('Saved!', 201);
}
/**
diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php
index 9759bc76..3aa6dba5 100644
--- a/app/Providers/RouteServiceProvider.php
+++ b/app/Providers/RouteServiceProvider.php
@@ -92,7 +92,7 @@ class RouteServiceProvider extends ServiceProvider
protected function mapAdminApiRoutes()
{
Route::prefix('api/admin')
- ->middleware('api')
+ ->middleware(['api', 'auth:sanctum'])
->namespace($this->namespace)
->group(base_path('routes/admin.php'));
}
diff --git a/resources/js/views/Admin/Plans.vue b/resources/js/views/Admin/Plans.vue
index a9fe3fc8..73cf13f9 100644
--- a/resources/js/views/Admin/Plans.vue
+++ b/resources/js/views/Admin/Plans.vue
@@ -177,7 +177,7 @@
},
methods: {
changeStatus(val, id) {
- this.$updateText('/plans/' + id + '/update', 'is_active', val)
+ this.$updateText('/plans/' + id, 'is_active', val)
}
},
created() {
diff --git a/resources/js/views/Admin/Plans/PlanCreate.vue b/resources/js/views/Admin/Plans/PlanCreate.vue
index d93bc277..6493e8bd 100644
--- a/resources/js/views/Admin/Plans/PlanCreate.vue
+++ b/resources/js/views/Admin/Plans/PlanCreate.vue
@@ -132,7 +132,7 @@
// Send request to get user token
axios
- .post('/api/plans/store', {
+ .post('/api/plans', {
attributes: this.plan
})
.then(response => {
diff --git a/resources/js/views/Admin/Plans/PlanTabs/PlanSettings.vue b/resources/js/views/Admin/Plans/PlanTabs/PlanSettings.vue
index 99e104d9..c4af2350 100644
--- a/resources/js/views/Admin/Plans/PlanTabs/PlanSettings.vue
+++ b/resources/js/views/Admin/Plans/PlanTabs/PlanSettings.vue
@@ -23,7 +23,7 @@
-
+
{{ errors[0] }}
@@ -32,7 +32,7 @@
-
+
{{ errors[0] }}
@@ -41,7 +41,7 @@
-
+
{{ errors[0] }}
@@ -97,7 +97,7 @@
},
methods: {
changeStatus(val) {
- this.$updateText('/plans/' + this.$route.params.id + '/update', 'is_active', val)
+ this.$updateText('/plans/' + this.$route.params.id, 'is_active', val)
}
}
}
diff --git a/routes/admin.php b/routes/admin.php
index 2e8e8c63..93683be1 100644
--- a/routes/admin.php
+++ b/routes/admin.php
@@ -29,13 +29,12 @@ Route::group(['prefix' => 'users'], function () {
});
// Plans
-// TODO: testy
Route::group(['prefix' => 'plans'], function () {
Route::get('/{id}/subscribers', [PlanController::class, 'subscribers']);
- Route::patch('/{id}/update', [PlanController::class, 'update']);
Route::delete('/{id}', [PlanController::class, 'delete']);
- Route::post('/store', [PlanController::class, 'store']);
+ Route::patch('/{id}', [PlanController::class, 'update']);
Route::get('/{id}', [PlanController::class, 'show']);
+ Route::post('/', [PlanController::class, 'store']);
Route::get('/', [PlanController::class, 'index']);
});
diff --git a/tests/Feature/SubscriptionTest.php b/tests/Feature/SubscriptionTest.php
index 30e8b13c..43de2dcf 100644
--- a/tests/Feature/SubscriptionTest.php
+++ b/tests/Feature/SubscriptionTest.php
@@ -61,7 +61,7 @@ class SubscriptionTest extends TestCase
}
/**
- *
+ *
*/
public function it_get_setup_intent()
{
@@ -82,7 +82,7 @@ class SubscriptionTest extends TestCase
}
/**
- *
+ *
*/
public function it_upgrade_plan()
{
@@ -109,7 +109,7 @@ class SubscriptionTest extends TestCase
}
/**
- *
+ *
*/
public function it_cancel_subscription()
{
@@ -135,7 +135,7 @@ class SubscriptionTest extends TestCase
}
/**
- *
+ *
*/
public function it_resume_subscription()
{
@@ -164,7 +164,7 @@ class SubscriptionTest extends TestCase
}
/**
- *
+ *
*/
public function it_get_user_subscription_details()
{
@@ -204,7 +204,7 @@ class SubscriptionTest extends TestCase
}
/**
- *
+ *
*/
public function it_get_user_invoices()
{
@@ -229,7 +229,7 @@ class SubscriptionTest extends TestCase
}
/**
- *
+ *
*/
public function it_get_user_subscription_from_admin()
{
@@ -274,7 +274,7 @@ class SubscriptionTest extends TestCase
}
/**
- *
+ *
*/
public function it_get_user_invoices_from_admin()
{
@@ -296,7 +296,7 @@ class SubscriptionTest extends TestCase
}
/**
- *
+ *
*/
public function it_store_stripe_plans_via_setup_wizard()
{
@@ -306,7 +306,7 @@ class SubscriptionTest extends TestCase
'type' => 'plan',
'attributes' => [
'name' => 'test-plan-' . Str::random(16),
- 'price' => (string) rand(1, 99),
+ 'price' => (string)rand(1, 99),
'description' => 'Some random description',
'capacity' => rand(1, 999),
],
@@ -315,7 +315,7 @@ class SubscriptionTest extends TestCase
'type' => 'plan',
'attributes' => [
'name' => 'test-plan-' . Str::random(16),
- 'price' => (string) rand(1, 99),
+ 'price' => (string)rand(1, 99),
'description' => 'Some random description',
'capacity' => rand(1, 999),
],
@@ -323,4 +323,151 @@ 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
+ ]);
+ }
+
+ /**
+ *
+ */
+ public function it_delete_single_plan()
+ {
+ $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
+ ]);
+
+ $this->deleteJson("/api/admin/plans/" . strtolower($plan_name))
+ ->assertStatus(204);
+ }
+
+ /**
+ *
+ */
+ public function it_update_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
+ ]);
+
+ $this->patchJson("/api/admin/plans/" . strtolower($plan_name), [
+ 'name' => 'description',
+ 'value' => 'updated description'
+ ])->assertStatus(201);
+ }
+
+ /**
+ *
+ */
+ public function it_get_subscribers_from_plan_from_admin()
+ {
+ $user = User::factory(User::class)
+ ->create($this->user);
+
+ Sanctum::actingAs($user);
+
+ $this->postJson('/api/user/subscription/upgrade', [
+ 'billing' => $this->billing,
+ 'plan' => $this->plan,
+ 'payment' => [
+ 'type' => 'stripe',
+ ],
+ ])->assertStatus(204);
+
+ $admin = User::factory(User::class)
+ ->create(['role' => 'admin']);
+
+ Sanctum::actingAs($admin);
+
+ $this->getJson('/api/admin/plans/' . $this->plan['data']['id'] . '/subscribers')
+ ->assertStatus(200)
+ ->assertJsonFragment([
+ 'id' => $user->id
+ ]);
+ }
}