mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-17 04:32:15 +01:00
Added resend invitation endpoint
This commit is contained in:
committed by
Constantin Graf
parent
9973368156
commit
53ba60bbe5
@@ -6,6 +6,7 @@ namespace Tests;
|
||||
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use TiMacDonald\Log\LogFake;
|
||||
|
||||
abstract class TestCase extends BaseTestCase
|
||||
@@ -15,6 +16,7 @@ abstract class TestCase extends BaseTestCase
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Mail::fake();
|
||||
LogFake::bind();
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ declare(strict_types=1);
|
||||
namespace Tests\Unit\Endpoint\Api\V1;
|
||||
|
||||
use App\Models\OrganizationInvitation;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Laravel\Jetstream\Mail\TeamInvitation;
|
||||
use Laravel\Passport\Passport;
|
||||
|
||||
class InvitationEndpointTest extends ApiEndpointTestAbstract
|
||||
@@ -77,6 +79,65 @@ class InvitationEndpointTest extends ApiEndpointTestAbstract
|
||||
$this->assertEquals('employee', $invitation->role);
|
||||
}
|
||||
|
||||
public function test_resend_fails_if_user_has_no_permission_to_resend_the_invitation(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
]);
|
||||
Passport::actingAs($data->user);
|
||||
$invitation = OrganizationInvitation::factory()->forOrganization($data->organization)->create();
|
||||
|
||||
// Act
|
||||
$response = $this->postJson(route('api.v1.invitations.resend', [
|
||||
$data->organization->getKey(),
|
||||
$invitation->getKey(),
|
||||
]));
|
||||
|
||||
// Assert
|
||||
Mail::assertNothingSent();
|
||||
Mail::assertNothingQueued();
|
||||
$response->assertStatus(403);
|
||||
}
|
||||
|
||||
public function test_resend_fails_if_invitation_belongs_to_different_organization(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'invitations:resend',
|
||||
]);
|
||||
Passport::actingAs($data->user);
|
||||
$invitation = OrganizationInvitation::factory()->create();
|
||||
|
||||
// Act
|
||||
$response = $this->postJson(route('api.v1.invitations.resend', [$data->organization->getKey(), $invitation->getKey()]));
|
||||
|
||||
// Assert
|
||||
Mail::assertNothingSent();
|
||||
Mail::assertNothingQueued();
|
||||
$response->assertStatus(403);
|
||||
}
|
||||
|
||||
public function test_resend_resends_invitation_email(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'invitations:resend',
|
||||
]);
|
||||
Passport::actingAs($data->user);
|
||||
$invitation = OrganizationInvitation::factory()->forOrganization($data->organization)->create();
|
||||
|
||||
// Act
|
||||
$response = $this->postJson(route('api.v1.invitations.resend', [
|
||||
$data->organization->getKey(),
|
||||
$invitation->getKey(),
|
||||
]));
|
||||
|
||||
// Assert
|
||||
Mail::assertSent(fn (TeamInvitation $mail): bool => $mail->invitation->is($invitation));
|
||||
Mail::assertNothingQueued();
|
||||
$response->assertStatus(204);
|
||||
}
|
||||
|
||||
public function test_delete_fails_if_user_has_no_permission_to_remove_invitations(): void
|
||||
{
|
||||
// Arrange
|
||||
|
||||
Reference in New Issue
Block a user