/
CreateTest.php
70 lines (54 loc) · 1.85 KB
/
CreateTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
use Carbon\Carbon;
use Illuminate\Foundation\Testing\RefreshDatabase;
use LaravelEnso\Calendar\Enums\Frequencies;
use LaravelEnso\Calendar\Models\Event;
use LaravelEnso\Core\Models\User;
use Tests\TestCase;
class CreateTest extends TestCase
{
use RefreshDatabase;
protected Event $event;
protected Carbon $date;
protected function setUp(): void
{
parent::setUp();
$this->seed();
$this->actingAs(User::first());
$this->date = Carbon::today();
$this->event = Event::factory()->make();
}
/** @test */
public function create_event()
{
$this->post(route('core.calendar.events.store'), [
'start_date' => $this->date->format('Y-m-d'),
'end_date' => $this->date->format('Y-m-d'),
'frequency' => Frequencies::Once,
] + $this->event->toArray());
$this->assertTrue(Event::exists());
}
/** @test */
public function create_sequence()
{
$count = 5;
$recurrenceEndsAt = $this->date->clone()->addDays($count - 1);
$this->post(route('core.calendar.events.store'), [
'start_date' => $this->date->format('Y-m-d'),
'end_date' => $this->date->format('Y-m-d'),
'frequency' => Frequencies::Daily,
'recurrence_ends_at' => $recurrenceEndsAt->format('Y-m-d'),
] + $this->event->toArray());
$events = Event::all();
$this->assertCount($count, $events);
$this->assertCount($count - 1, $events->first()->events);
$events->each(function ($event, $index) use ($recurrenceEndsAt) {
$this->assertTrue(
$event->start_date->eq($this->date->clone()->addDays($index))
);
$this->assertTrue(
$event->recurrence_ends_at->eq($recurrenceEndsAt)
);
});
}
}