-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor integration validation rules to include form context
- Updated the `getValidationRules` method in various integration handlers (Discord, Email, Google Sheets, Slack, Webhook, Zapier) to accept an optional `Form` parameter, allowing for context-aware validation. - Enhanced the `EmailIntegration` handler to enforce restrictions based on user plans, ensuring free users can only create one email integration per form and can only send to a single email address. - Added a new test suite for `EmailIntegration` to validate the new restrictions and ensure proper functionality for both free and pro users. - Introduced loading state management in the `IntegrationModal` component to improve user experience during save operations. These changes improve the flexibility and user experience of form integrations, particularly for email handling.
- Loading branch information
1 parent
c63571e
commit 01f7fa2
Showing
10 changed files
with
230 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
175 changes: 175 additions & 0 deletions
175
api/tests/Feature/Integrations/Email/EmailIntegrationTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
<?php | ||
|
||
use App\Models\Integration\FormIntegration; | ||
|
||
test('free user can create one email integration', function () { | ||
$user = $this->actingAsUser(); | ||
$workspace = $this->createUserWorkspace($user); | ||
$form = $this->createForm($user, $workspace); | ||
|
||
// First email integration should succeed | ||
$response = $this->postJson(route('open.forms.integration.create', $form), [ | ||
'integration_id' => 'email', | ||
'status' => true, | ||
'settings' => [ | ||
'send_to' => '[email protected]', | ||
'sender_name' => 'Test Sender', | ||
'subject' => 'Test Subject', | ||
'email_content' => 'Test Content', | ||
'include_submission_data' => true | ||
] | ||
]); | ||
|
||
$response->assertSuccessful(); | ||
expect(FormIntegration::where('form_id', $form->id)->count())->toBe(1); | ||
|
||
// Second email integration should fail | ||
$response = $this->postJson(route('open.forms.integration.create', $form), [ | ||
'integration_id' => 'email', | ||
'status' => true, | ||
'settings' => [ | ||
'send_to' => '[email protected]', | ||
'sender_name' => 'Test Sender', | ||
'subject' => 'Test Subject', | ||
'email_content' => 'Test Content', | ||
'include_submission_data' => true | ||
] | ||
]); | ||
|
||
$response->assertStatus(422) | ||
->assertJson([ | ||
'errors' => [ | ||
'settings.send_to' => ['Free users are limited to 1 email integration per form.'] | ||
] | ||
]); | ||
}); | ||
|
||
test('pro user can create multiple email integrations', function () { | ||
$user = $this->actingAsProUser(); | ||
$workspace = $this->createUserWorkspace($user); | ||
$form = $this->createForm($user, $workspace); | ||
|
||
// First email integration | ||
$response = $this->postJson(route('open.forms.integration.create', $form), [ | ||
'integration_id' => 'email', | ||
'status' => true, | ||
'settings' => [ | ||
'send_to' => '[email protected]', | ||
'sender_name' => 'Test Sender', | ||
'subject' => 'Test Subject', | ||
'email_content' => 'Test Content', | ||
'include_submission_data' => true | ||
] | ||
]); | ||
|
||
$response->assertSuccessful(); | ||
|
||
// Second email integration should also succeed for pro users | ||
$response = $this->postJson(route('open.forms.integration.create', $form), [ | ||
'integration_id' => 'email', | ||
'status' => true, | ||
'settings' => [ | ||
'send_to' => '[email protected]', | ||
'sender_name' => 'Test Sender', | ||
'subject' => 'Test Subject', | ||
'email_content' => 'Test Content', | ||
'include_submission_data' => true | ||
] | ||
]); | ||
|
||
$response->assertSuccessful(); | ||
expect(FormIntegration::where('form_id', $form->id)->count())->toBe(2); | ||
}); | ||
|
||
test('free user cannot add multiple emails', function () { | ||
$user = $this->actingAsUser(); | ||
$workspace = $this->createUserWorkspace($user); | ||
$form = $this->createForm($user, $workspace); | ||
|
||
$response = $this->postJson(route('open.forms.integration.create', $form), [ | ||
'integration_id' => 'email', | ||
'status' => true, | ||
'settings' => [ | ||
'send_to' => "[email protected]\n[email protected]", | ||
'sender_name' => 'Test Sender', | ||
'subject' => 'Test Subject', | ||
'email_content' => 'Test Content', | ||
'include_submission_data' => true | ||
] | ||
]); | ||
|
||
$response->assertStatus(422) | ||
->assertJsonValidationErrors(['settings.send_to']) | ||
->assertJson([ | ||
'errors' => [ | ||
'settings.send_to' => ['You can only send to a single email address on the free plan. Please upgrade to the Pro plan to create a new integration.'] | ||
] | ||
]); | ||
}); | ||
|
||
test('pro user can add multiple emails', function () { | ||
$user = $this->actingAsProUser(); | ||
$workspace = $this->createUserWorkspace($user); | ||
$form = $this->createForm($user, $workspace); | ||
|
||
$response = $this->postJson(route('open.forms.integration.create', $form), [ | ||
'integration_id' => 'email', | ||
'status' => true, | ||
'settings' => [ | ||
'send_to' => "[email protected]\n[email protected]\n[email protected]", | ||
'sender_name' => 'Test Sender', | ||
'subject' => 'Test Subject', | ||
'email_content' => 'Test Content', | ||
'include_submission_data' => true | ||
] | ||
]); | ||
|
||
$response->assertSuccessful(); | ||
|
||
$integration = FormIntegration::where('form_id', $form->id)->first(); | ||
expect($integration)->not->toBeNull(); | ||
expect($integration->data->send_to)->toContain('[email protected]'); | ||
expect($integration->data->send_to)->toContain('[email protected]'); | ||
expect($integration->data->send_to)->toContain('[email protected]'); | ||
}); | ||
|
||
test('free user can update their single email integration', function () { | ||
$user = $this->actingAsUser(); | ||
$workspace = $this->createUserWorkspace($user); | ||
$form = $this->createForm($user, $workspace); | ||
|
||
// Create initial integration | ||
$response = $this->postJson(route('open.forms.integration.create', $form), [ | ||
'integration_id' => 'email', | ||
'status' => true, | ||
'settings' => [ | ||
'send_to' => '[email protected]', | ||
'sender_name' => 'Test Sender', | ||
'subject' => 'Test Subject', | ||
'email_content' => 'Test Content', | ||
'include_submission_data' => true | ||
] | ||
]); | ||
|
||
$response->assertSuccessful(); | ||
$integrationId = $response->json('form_integration.id'); | ||
|
||
// Update the integration | ||
$response = $this->putJson(route('open.forms.integration.update', [$form, $integrationId]), [ | ||
'integration_id' => 'email', | ||
'status' => true, | ||
'settings' => [ | ||
'send_to' => '[email protected]', | ||
'sender_name' => 'Updated Sender', | ||
'subject' => 'Updated Subject', | ||
'email_content' => 'Updated Content', | ||
'include_submission_data' => true | ||
] | ||
]); | ||
|
||
$response->assertSuccessful(); | ||
|
||
$integration = FormIntegration::find($integrationId); | ||
expect($integration->data->send_to)->toBe('[email protected]'); | ||
expect($integration->data->sender_name)->toBe('Updated Sender'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters