add guest invitation read & valide with route
This commit is contained in:
@@ -4,11 +4,10 @@ namespace Tests\Feature;
|
||||
|
||||
use App\Models\Event;
|
||||
use App\Models\EventCategory;
|
||||
use App\Models\Memo;
|
||||
use App\Models\EventGuestsNonUsers;
|
||||
use App\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\TestCase;
|
||||
|
||||
class EventsTest extends TestCase
|
||||
@@ -641,7 +640,107 @@ class EventsTest extends TestCase
|
||||
$this->assertCount(0, $event->guests);
|
||||
}
|
||||
|
||||
// owner_can_invite_a_non_user_with_an_email
|
||||
/** @test */
|
||||
public function owner_or_staff_can_invite_a_non_user_with_an_email()
|
||||
{
|
||||
$this->withoutExceptionHandling();
|
||||
$this->actingAs($user = factory(User::class)->create(), 'api');
|
||||
$event = factory(Event::class)->create(['user_id' => $user->id, 'private' => false]);
|
||||
|
||||
$response = $this->post('api/events/'.$event->id.'/invite/with-email', ['email' => 'test@mail.fr']);
|
||||
|
||||
$event = $event->fresh();
|
||||
|
||||
$this->assertCount(1, $event->emailedGuests);
|
||||
$response->assertJson([
|
||||
'data' => [
|
||||
'event_id' => $event->id,
|
||||
'attributes' => [
|
||||
'data' => [
|
||||
'invitations-with-email' => [
|
||||
'data' => [
|
||||
[
|
||||
'email' => 'test@mail.fr',
|
||||
'read_at' => null,
|
||||
'validated_at' => null,
|
||||
]
|
||||
],
|
||||
],
|
||||
]
|
||||
]
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function a_guest_with_an_email_can_read_event()
|
||||
{
|
||||
$user = factory(User::class)->create();
|
||||
$event = factory(Event::class)->create(['user_id' => $user->id, 'private' => false]);
|
||||
$token = (string) Str::uuid();
|
||||
$guest = new EventGuestsNonUsers(['event_id' => $event->id, 'email' => 'test@mail.fr', 'token' => $token]);
|
||||
$guest->save();
|
||||
|
||||
$response = $this->get('api/events/'.$event->id.'/with-email?email=test@mail.fr&token='.$token);
|
||||
|
||||
$response->assertStatus(200);
|
||||
$this->assertCount(0, $event->guests);
|
||||
$this->assertCount(1, $event->emailedGuests);
|
||||
$response->assertJson([
|
||||
'data' => [
|
||||
'event_id' => $event->id,
|
||||
'attributes' => [
|
||||
'data' => [
|
||||
'invitations-with-email' => [
|
||||
'data' => [
|
||||
[
|
||||
'email' => 'test@mail.fr',
|
||||
'read_at' => now()->toDateTimeString(),
|
||||
'validated_at' => null,
|
||||
]
|
||||
],
|
||||
],
|
||||
]
|
||||
]
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function a_guest_with_an_email_can_confirm_participation()
|
||||
{
|
||||
$this->withoutExceptionHandling();
|
||||
$user = factory(User::class)->create();
|
||||
$event = factory(Event::class)->create(['user_id' => $user->id, 'private' => false]);
|
||||
$token = (string) Str::uuid();
|
||||
$guest = new EventGuestsNonUsers(['event_id' => $event->id, 'email' => 'test@mail.fr', 'token' => $token]);
|
||||
$guest->save();
|
||||
|
||||
$response = $this->patch('api/events/'.$event->id.'/with-email', [ 'email' => 'test@mail.fr', 'token' => $token ]);
|
||||
|
||||
$response->assertStatus(200);
|
||||
$this->assertCount(1, $event->emailedGuests);
|
||||
$response->assertJson([
|
||||
'data' => [
|
||||
'event_id' => $event->id,
|
||||
'attributes' => [
|
||||
'data' => [
|
||||
'invitations-with-email' => [
|
||||
'data' => [
|
||||
[
|
||||
'validated_at' => now()->toDateTimeString(),
|
||||
]
|
||||
],
|
||||
],
|
||||
]
|
||||
]
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
// an_invitation_mail_is_seed_to_new_guest
|
||||
|
||||
// a_guest_can_confirm_participation_in_mail
|
||||
|
||||
private function data()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user