Unique subscription nameS

This commit is contained in:
David Bomba 2021-04-01 20:56:50 +11:00
parent 1e83b729d5
commit a2e0fd0849
3 changed files with 8 additions and 6 deletions

View File

@ -54,7 +54,7 @@ class StoreSubscriptionRequest extends Request
'plan_map' => ['sometimes'],
'refund_period' => ['sometimes'],
'webhook_configuration' => ['array'],
'name' => Rule::unique('subscriptions')->where('company_id', auth()->user()->company()->id)
'name' => ['required', Rule::unique('subscriptions')->where('company_id', auth()->user()->company()->id)]
];
}

View File

@ -33,7 +33,6 @@ class SubscriptionTransformer extends EntityTransformer
public function transform(Subscription $subscription): array
{
$std = new \stdClass;
return [
'id' => $this->encodePrimaryKey($subscription->id),
@ -61,7 +60,7 @@ class SubscriptionTransformer extends EntityTransformer
'allow_plan_changes' => (bool)$subscription->allow_plan_changes,
'plan_map' => (string)$subscription->plan_map,
'refund_period' => (int)$subscription->refund_period,
'webhook_configuration' => $subscription->webhook_configuration ?: $std,
'webhook_configuration' => $subscription->webhook_configuration ?: [],
'purchase_page' => (string)route('client.subscription.purchase', $subscription->hashed_id),
'is_deleted' => (bool)$subscription->is_deleted,
'created_at' => (int)$subscription->created_at,

View File

@ -11,14 +11,15 @@
namespace Tests\Feature;
use App\Models\Subscription;
use App\Models\Product;
use App\Models\Subscription;
use App\Utils\Traits\MakesHash;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Str;
use Tests\MockAccountData;
use Tests\TestCase;
@ -55,6 +56,7 @@ class SubscriptionApiTest extends TestCase
$billing_subscription = Subscription::factory()->create([
'product_ids' => $product->id,
'company_id' => $this->company->id,
'name' => Str::random(5)
]);
@ -78,7 +80,7 @@ class SubscriptionApiTest extends TestCase
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/subscriptions', ['product_ids' => $product->id, 'allow_cancellation' => true]);
])->post('/api/v1/subscriptions', ['product_ids' => $product->id, 'allow_cancellation' => true, 'name' => Str::random(5)]);
// nlog($response);
$response->assertStatus(200);
@ -93,7 +95,7 @@ class SubscriptionApiTest extends TestCase
$response1 = $this
->withHeaders(['X-API-SECRET' => config('ninja.api_secret'),'X-API-TOKEN' => $this->token])
->post('/api/v1/subscriptions', ['product_ids' => $product->id])
->post('/api/v1/subscriptions', ['product_ids' => $product->id, 'name' => Str::random(5)])
->assertStatus(200)
->json();
@ -126,6 +128,7 @@ class SubscriptionApiTest extends TestCase
$billing_subscription = Subscription::factory()->create([
'product_ids' => $product->id,
'company_id' => $this->company->id,
'name' => Str::random(5)
]);
$response = $this