mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Unique subscription nameS
This commit is contained in:
parent
1e83b729d5
commit
a2e0fd0849
@ -54,7 +54,7 @@ class StoreSubscriptionRequest extends Request
|
|||||||
'plan_map' => ['sometimes'],
|
'plan_map' => ['sometimes'],
|
||||||
'refund_period' => ['sometimes'],
|
'refund_period' => ['sometimes'],
|
||||||
'webhook_configuration' => ['array'],
|
'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)]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,6 @@ class SubscriptionTransformer extends EntityTransformer
|
|||||||
|
|
||||||
public function transform(Subscription $subscription): array
|
public function transform(Subscription $subscription): array
|
||||||
{
|
{
|
||||||
$std = new \stdClass;
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'id' => $this->encodePrimaryKey($subscription->id),
|
'id' => $this->encodePrimaryKey($subscription->id),
|
||||||
@ -61,7 +60,7 @@ class SubscriptionTransformer extends EntityTransformer
|
|||||||
'allow_plan_changes' => (bool)$subscription->allow_plan_changes,
|
'allow_plan_changes' => (bool)$subscription->allow_plan_changes,
|
||||||
'plan_map' => (string)$subscription->plan_map,
|
'plan_map' => (string)$subscription->plan_map,
|
||||||
'refund_period' => (int)$subscription->refund_period,
|
'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),
|
'purchase_page' => (string)route('client.subscription.purchase', $subscription->hashed_id),
|
||||||
'is_deleted' => (bool)$subscription->is_deleted,
|
'is_deleted' => (bool)$subscription->is_deleted,
|
||||||
'created_at' => (int)$subscription->created_at,
|
'created_at' => (int)$subscription->created_at,
|
||||||
|
@ -11,14 +11,15 @@
|
|||||||
|
|
||||||
namespace Tests\Feature;
|
namespace Tests\Feature;
|
||||||
|
|
||||||
use App\Models\Subscription;
|
|
||||||
use App\Models\Product;
|
use App\Models\Product;
|
||||||
|
use App\Models\Subscription;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
use Illuminate\Foundation\Testing\WithFaker;
|
use Illuminate\Foundation\Testing\WithFaker;
|
||||||
use Illuminate\Support\Facades\Session;
|
use Illuminate\Support\Facades\Session;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
use Tests\MockAccountData;
|
use Tests\MockAccountData;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
@ -55,6 +56,7 @@ class SubscriptionApiTest extends TestCase
|
|||||||
$billing_subscription = Subscription::factory()->create([
|
$billing_subscription = Subscription::factory()->create([
|
||||||
'product_ids' => $product->id,
|
'product_ids' => $product->id,
|
||||||
'company_id' => $this->company->id,
|
'company_id' => $this->company->id,
|
||||||
|
'name' => Str::random(5)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
||||||
@ -78,7 +80,7 @@ class SubscriptionApiTest extends TestCase
|
|||||||
$response = $this->withHeaders([
|
$response = $this->withHeaders([
|
||||||
'X-API-SECRET' => config('ninja.api_secret'),
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
'X-API-TOKEN' => $this->token,
|
'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);
|
// nlog($response);
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
@ -93,7 +95,7 @@ class SubscriptionApiTest extends TestCase
|
|||||||
|
|
||||||
$response1 = $this
|
$response1 = $this
|
||||||
->withHeaders(['X-API-SECRET' => config('ninja.api_secret'),'X-API-TOKEN' => $this->token])
|
->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)
|
->assertStatus(200)
|
||||||
->json();
|
->json();
|
||||||
|
|
||||||
@ -126,6 +128,7 @@ class SubscriptionApiTest extends TestCase
|
|||||||
$billing_subscription = Subscription::factory()->create([
|
$billing_subscription = Subscription::factory()->create([
|
||||||
'product_ids' => $product->id,
|
'product_ids' => $product->id,
|
||||||
'company_id' => $this->company->id,
|
'company_id' => $this->company->id,
|
||||||
|
'name' => Str::random(5)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$response = $this
|
$response = $this
|
||||||
|
Loading…
x
Reference in New Issue
Block a user