added it_get_all_plans_from_admin, it_get_single_plan_from_admin, it_create_single_plan_from_admin, it_delete_single_plan, it_update_single_plan_from_admin, it_get_subscribers_from_plan_from_admin test

This commit is contained in:
Peter Papp
2021-03-06 12:14:09 +01:00
parent 88540bd2a6
commit dd4fab8e7c
7 changed files with 173 additions and 26 deletions
@@ -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);
}
/**
+1 -1
View File
@@ -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'));
}
+1 -1
View File
@@ -177,7 +177,7 @@
},
methods: {
changeStatus(val, id) {
this.$updateText('/plans/' + id + '/update', 'is_active', val)
this.$updateText('/plans/' + id, 'is_active', val)
}
},
created() {
@@ -132,7 +132,7 @@
// Send request to get user token
axios
.post('/api/plans/store', {
.post('/api/plans', {
attributes: this.plan
})
.then(response => {
@@ -23,7 +23,7 @@
<div class="block-wrapper">
<label>{{ $t('admin_page_plans.form.name') }}:</label>
<ValidationProvider tag="div" mode="passive" class="input-wrapper" name="Name" rules="required" v-slot="{ errors }">
<input @input="$updateText('/plans/' + $route.params.id + '/update', 'name', plan.attributes.name)" v-model="plan.attributes.name" :placeholder="$t('admin_page_plans.form.name_plac')" type="text" :class="{'is-error': errors[0]}"/>
<input @input="$updateText('/plans/' + $route.params.id, 'name', plan.attributes.name)" v-model="plan.attributes.name" :placeholder="$t('admin_page_plans.form.name_plac')" type="text" :class="{'is-error': errors[0]}"/>
<span class="error-message" v-if="errors[0]">{{ errors[0] }}</span>
</ValidationProvider>
</div>
@@ -32,7 +32,7 @@
<div class="block-wrapper">
<label>{{ $t('admin_page_plans.form.description') }}:</label>
<ValidationProvider tag="div" mode="passive" class="input-wrapper" name="Description" v-slot="{ errors }">
<textarea @input="$updateText('/plans/' + $route.params.id + '/update', 'description', plan.attributes.description)" v-model="plan.attributes.description" :placeholder="$t('admin_page_plans.form.description_plac')" :class="{'is-error': errors[0]}"></textarea>
<textarea @input="$updateText('/plans/' + $route.params.id, 'description', plan.attributes.description)" v-model="plan.attributes.description" :placeholder="$t('admin_page_plans.form.description_plac')" :class="{'is-error': errors[0]}"></textarea>
<span class="error-message" v-if="errors[0]">{{ errors[0] }}</span>
</ValidationProvider>
</div>
@@ -41,7 +41,7 @@
<div class="block-wrapper">
<label>{{ $t('admin_page_plans.form.storage') }}:</label>
<ValidationProvider tag="div" mode="passive" class="input-wrapper" name="Storage capacity" rules="required" v-slot="{ errors }">
<input @input="$updateText('/plans/' + $route.params.id + '/update', 'capacity', plan.attributes.capacity)" v-model="plan.attributes.capacity" :placeholder="$t('admin_page_plans.form.storage_plac')" type="number" min="1" max="999999999" :class="{'is-error': errors[0]}"/>
<input @input="$updateText('/plans/' + $route.params.id, 'capacity', plan.attributes.capacity)" v-model="plan.attributes.capacity" :placeholder="$t('admin_page_plans.form.storage_plac')" type="number" min="1" max="999999999" :class="{'is-error': errors[0]}"/>
<span class="error-message" v-if="errors[0]">{{ errors[0] }}</span>
</ValidationProvider>
<small class="input-help">
@@ -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)
}
}
}
+2 -3
View File
@@ -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']);
});
+158 -11
View File
@@ -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
]);
}
}