feat: disable custom script for trial users (#371)
* feat: disable custom script for trial users * fix: logic error for trial users --------- Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
@@ -168,3 +168,26 @@ it('can create form with dark mode', function () {
|
||||
->etc();
|
||||
});
|
||||
});
|
||||
|
||||
it('can create form with custom scripts', function () {
|
||||
$user = $this->actingAsTrialingUser();
|
||||
$workspace = $this->createUserWorkspace($user);
|
||||
$form = $this->createForm($user, $workspace, [
|
||||
'custom_code' => "<script>console.log('Hello')</script>",
|
||||
]);
|
||||
$formData = (new \App\Http\Resources\FormResource($form))->toArray(request());
|
||||
$this->postJson(route('open.forms.store', $formData))
|
||||
->assertSuccessful()
|
||||
->assertJson([
|
||||
'type' => 'success',
|
||||
'message' => 'Form successfully created, but the Non-trial features you used will be disabled when sharing your form:',
|
||||
'form' => ['custom_code' => null]
|
||||
]);
|
||||
|
||||
$this->getJson(route('forms.show', $form->slug))
|
||||
->assertSuccessful()->assertJson([
|
||||
'id' => $form->id,
|
||||
'title' => $form->title,
|
||||
'custom_code' => null
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -179,6 +179,21 @@ trait TestHelpers
|
||||
return $user;
|
||||
}
|
||||
|
||||
public function createTrialingUser()
|
||||
{
|
||||
$user = $this->createUser();
|
||||
$user->subscriptions()->create([
|
||||
'name' => 'default',
|
||||
'stripe_id' => Str::random(),
|
||||
'stripe_status' => 'trialing',
|
||||
'stripe_price' => Str::random(),
|
||||
'trial_ends_at' => now()->addDays(5),
|
||||
'quantity' => 1,
|
||||
]);
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
public function actingAsUser(?User $user = null)
|
||||
{
|
||||
if ($user == null) {
|
||||
@@ -207,6 +222,15 @@ trait TestHelpers
|
||||
return $this->actingAsUser($user);
|
||||
}
|
||||
|
||||
public function actingAsTrialingUser(User $user = null)
|
||||
{
|
||||
if ($user == null) {
|
||||
$user = $this->createTrialingUser();
|
||||
}
|
||||
|
||||
return $this->actingAsUser($user);
|
||||
}
|
||||
|
||||
public function actingAsGuest()
|
||||
{
|
||||
if (Auth::check()) {
|
||||
|
||||
Reference in New Issue
Block a user