Custom SMTP Settings (#561)

* Custom SMTP Settings

* Fix lint

* Custom SMTP add in Pricing plan

* Allow reset email settings

* improve custom SMTP using seprate abstract class

* test case for custom SMTP

* fix test case

* UI improvement

* add CASHIER_KEY in phpunit for testcase

* Attempt to fix tests

* Run pint and attempt to fix cache tests

* Fix user management tests

* Fix code linters

* Merged main & fix linting

---------

Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
Chirag Chhatrala
2024-09-24 15:46:20 +05:30
committed by GitHub
parent 5dcd4ff8cb
commit 504c7a0f2f
31 changed files with 876 additions and 510 deletions

View File

@@ -0,0 +1,60 @@
<?php
use App\Mail\Forms\SubmissionConfirmationMail;
use Illuminate\Support\Facades\Mail;
it('can not save custom SMTP settings if not pro user', function () {
$user = $this->actingAsUser();
$workspace = $this->createUserWorkspace($user);
$this->putJson(route('open.workspaces.save-email-settings', [$workspace->id]), [
'host' => 'custom.smtp.host',
'port' => '587',
'username' => 'custom_username',
'password' => 'custom_password',
])->assertStatus(403);
});
it('creates confirmation emails with custom SMTP settings', function () {
$user = $this->actingAsProUser();
$workspace = $this->createUserWorkspace($user);
$form = $this->createForm($user, $workspace);
// Set custom SMTP settings
$this->putJson(route('open.workspaces.save-email-settings', [$workspace->id]), [
'host' => 'custom.smtp.host',
'port' => '587',
'username' => 'custom_username',
'password' => 'custom_password',
])->assertSuccessful();
$integrationData = $this->createFormIntegration('submission_confirmation', $form->id, [
'respondent_email' => true,
'notifications_include_submission' => true,
'notification_sender' => 'Custom Sender',
'notification_subject' => 'Custom SMTP Test',
'notification_body' => 'This email was sent using custom SMTP settings',
]);
$formData = [
collect($form->properties)->first(function ($property) {
return $property['type'] == 'email';
})['id'] => 'test@test.com',
];
Mail::fake();
$this->postJson(route('forms.answer', $form->slug), $formData)
->assertSuccessful()
->assertJson([
'type' => 'success',
'message' => 'Form submission saved.',
]);
Mail::assertQueued(
SubmissionConfirmationMail::class,
function (SubmissionConfirmationMail $mail) {
return $mail->hasTo('test@test.com') && $mail->mailer === 'custom_smtp';
}
);
});

View File

@@ -3,16 +3,19 @@
use App\Models\UserInvite;
use Carbon\Carbon;
beforeEach(function () {
$this->user = $this->actingAsProUser();
$this->workspace = $this->createUserWorkspace($this->user);
});
it('can register with invite token', function () {
$this->withoutExceptionHandling();
$user = $this->actingAsUser();
$workspace = $this->createUserWorkspace($user);
$email = 'invitee@gmail.com';
$inviteData = ['email' => $email, 'role' => 'user'];
$this->postJson(route('open.workspaces.users.add', $workspace->id), $inviteData)
$this->postJson(route('open.workspaces.users.add', $this->workspace->id), $inviteData)
->assertSuccessful();
expect($workspace->invites()->count())->toBe(1);
expect($this->workspace->invites()->count())->toBe(1);
$userInvite = UserInvite::latest()->first();
$token = $userInvite->token;
@@ -30,18 +33,16 @@ it('can register with invite token', function () {
'invite_token' => $token,
]);
$response->assertSuccessful();
expect($workspace->users()->count())->toBe(2);
expect($this->workspace->users()->count())->toBe(2);
});
it('cannot register with expired invite token', function () {
$user = $this->actingAsUser();
$workspace = $this->createUserWorkspace($user);
$email = 'invitee@gmail.com';
$inviteData = ['email' => $email, 'role' => 'user'];
$this->postJson(route('open.workspaces.users.add', $workspace->id), $inviteData)
$this->postJson(route('open.workspaces.users.add', $this->workspace->id), $inviteData)
->assertSuccessful();
expect($workspace->invites()->count())->toBe(1);
expect($this->workspace->invites()->count())->toBe(1);
$userInvite = UserInvite::latest()->first();
$token = $userInvite->token;
@@ -62,18 +63,16 @@ it('cannot register with expired invite token', function () {
$response->assertStatus(400)->assertJson([
'message' => 'Invite token has expired.',
]);
expect($workspace->users()->count())->toBe(1);
expect($this->workspace->users()->count())->toBe(1);
});
it('cannot re-register with accepted invite token', function () {
$user = $this->actingAsUser();
$workspace = $this->createUserWorkspace($user);
$email = 'invitee@gmail.com';
$inviteData = ['email' => $email, 'role' => 'user'];
$this->postJson(route('open.workspaces.users.add', $workspace->id), $inviteData)
$this->postJson(route('open.workspaces.users.add', $this->workspace->id), $inviteData)
->assertSuccessful();
expect($workspace->invites()->count())->toBe(1);
expect($this->workspace->invites()->count())->toBe(1);
$userInvite = UserInvite::latest()->first();
$token = $userInvite->token;
@@ -91,10 +90,10 @@ it('cannot re-register with accepted invite token', function () {
'invite_token' => $token,
]);
$response->assertSuccessful();
expect($workspace->users()->count())->toBe(2);
expect($this->workspace->users()->count())->toBe(2);
$this->postJson('/logout')
->assertSuccessful();
->assertSuccessful();
// Register again with same used token
$response = $this->postJson('/register', [
@@ -110,23 +109,21 @@ it('cannot re-register with accepted invite token', function () {
$response->assertStatus(422)->assertJson([
'message' => 'The email has already been taken.',
]);
expect($workspace->users()->count())->toBe(2);
expect($this->workspace->users()->count())->toBe(2);
});
it('can cancel user invite', function () {
$user = $this->actingAsUser();
$workspace = $this->createUserWorkspace($user);
$email = 'invitee@gmail.com';
$inviteData = ['email' => $email, 'role' => 'user'];
$response = $this->postJson(route('open.workspaces.users.add', $workspace->id), $inviteData)
$response = $this->postJson(route('open.workspaces.users.add', $this->workspace->id), $inviteData)
->assertSuccessful();
expect($workspace->invites()->count())->toBe(1);
expect($this->workspace->invites()->count())->toBe(1);
$userInvite = UserInvite::latest()->first();
$token = $userInvite->token;
// Cancel the invite
$this->deleteJson(route('open.workspaces.invites.cancel', ['workspaceId' => $workspace->id, 'inviteId' => $userInvite->id]))
$this->deleteJson(route('open.workspaces.invites.cancel', ['workspaceId' => $this->workspace->id, 'inviteId' => $userInvite->id]))
->assertSuccessful();
$this->postJson('/logout')
@@ -146,5 +143,5 @@ it('can cancel user invite', function () {
'message' => 'Invite token is invalid.',
]);
expect($workspace->users()->count())->toBe(1);
expect($this->workspace->users()->count())->toBe(1);
});