first commit
This commit is contained in:
218
tests/Feature/TimeIntervals/BulkEditTest.php
Normal file
218
tests/Feature/TimeIntervals/BulkEditTest.php
Normal file
@@ -0,0 +1,218 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Tests\Feature\TimeIntervals;
|
||||
|
||||
use App\Models\Task;
|
||||
use App\Models\TimeInterval;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
use Tests\Facades\IntervalFactory;
|
||||
use Tests\Facades\TaskFactory;
|
||||
use Tests\Facades\UserFactory;
|
||||
use Tests\TestCase;
|
||||
|
||||
class BulkEditTest extends TestCase
|
||||
{
|
||||
use WithFaker;
|
||||
|
||||
private const URI = 'time-intervals/bulk-edit';
|
||||
|
||||
private const INTERVALS_AMOUNT = 5;
|
||||
|
||||
/** @var User $admin */
|
||||
private User $admin;
|
||||
/** @var User $manager */
|
||||
private User $manager;
|
||||
/** @var User $auditor */
|
||||
private User $auditor;
|
||||
/** @var User $user */
|
||||
private User $user;
|
||||
|
||||
private Collection $intervals;
|
||||
private Collection $intervalsForManager;
|
||||
private Collection $intervalsForAuditor;
|
||||
private Collection $intervalsForUser;
|
||||
|
||||
private Task $task;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->admin = UserFactory::refresh()->asAdmin()->withTokens()->create();
|
||||
$this->manager = UserFactory::refresh()->asManager()->withTokens()->create();
|
||||
$this->auditor = UserFactory::refresh()->asAuditor()->withTokens()->create();
|
||||
$this->user = UserFactory::refresh()->asUser()->withTokens()->create();
|
||||
|
||||
$this->task = TaskFactory::refresh()->create();
|
||||
|
||||
$this->intervals = IntervalFactory::refresh()->withRandomRelations()->createMany(self::INTERVALS_AMOUNT);
|
||||
$this->intervalsForManager = IntervalFactory::refresh()
|
||||
->forUser($this->manager)
|
||||
->createMany(self::INTERVALS_AMOUNT);
|
||||
$this->intervalsForAuditor = IntervalFactory::refresh()
|
||||
->forUser($this->auditor)
|
||||
->createMany(self::INTERVALS_AMOUNT);
|
||||
$this->intervalsForUser = IntervalFactory::refresh()
|
||||
->forUser($this->user)
|
||||
->createMany(self::INTERVALS_AMOUNT);
|
||||
}
|
||||
|
||||
public function test_bulk_edit_as_admin(): void
|
||||
{
|
||||
$this->intervals->each->setAttribute('task_id', $this->task->id);
|
||||
|
||||
foreach ($this->intervals as $interval) {
|
||||
$this->assertDatabaseMissing('time_intervals', $interval->toArray());
|
||||
}
|
||||
|
||||
$requestData = ['intervals' => $this->intervals->toArray()];
|
||||
|
||||
$response = $this->actingAs($this->admin)->postJson(self::URI, $requestData);
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
foreach ($this->intervals as $interval) {
|
||||
$this->assertDatabaseHas('time_intervals', $interval->toArray());
|
||||
}
|
||||
}
|
||||
|
||||
public function test_bulk_edit_as_manager(): void
|
||||
{
|
||||
$this->intervals->each->setAttribute('task_id', $this->task->id);
|
||||
|
||||
foreach ($this->intervals as $interval) {
|
||||
$this->assertDatabaseMissing('time_intervals', $interval->toArray());
|
||||
}
|
||||
|
||||
$requestData = ['intervals' => $this->intervals->toArray()];
|
||||
|
||||
$response = $this->actingAs($this->manager)->postJson(self::URI, $requestData);
|
||||
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_bulk_edit_your_own_as_manager(): void
|
||||
{
|
||||
$this->intervals->each->setAttribute('task_id', $this->task->id);
|
||||
|
||||
foreach ($this->intervalsForManager as $interval) {
|
||||
$this->assertDatabaseHas('time_intervals', $interval->toArray());
|
||||
}
|
||||
|
||||
$requestData = ['intervals' => $this->intervalsForManager->toArray()];
|
||||
|
||||
$response = $this->actingAs($this->manager)->postJson(self::URI, $requestData);
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
foreach ($this->intervalsForManager as $interval) {
|
||||
$this->assertDatabaseHas('time_intervals', $interval->toArray());
|
||||
}
|
||||
}
|
||||
|
||||
public function test_bulk_edit_as_auditor(): void
|
||||
{
|
||||
$this->intervals->each->setAttribute('task_id', $this->task->id);
|
||||
|
||||
foreach ($this->intervals as $interval) {
|
||||
$this->assertDatabaseMissing('time_intervals', $interval->toArray());
|
||||
}
|
||||
|
||||
$requestData = ['intervals' => $this->intervals->toArray()];
|
||||
|
||||
$response = $this->actingAs($this->auditor)->postJson(self::URI, $requestData);
|
||||
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_bulk_edit_your_own_as_auditor(): void
|
||||
{
|
||||
$this->intervals->each->setAttribute('task_id', $this->task->id);
|
||||
|
||||
foreach ($this->intervalsForAuditor as $interval) {
|
||||
$this->assertDatabaseHas('time_intervals', $interval->toArray());
|
||||
}
|
||||
|
||||
$requestData = ['intervals' => $this->intervalsForAuditor->toArray()];
|
||||
|
||||
$response = $this->actingAs($this->auditor)->postJson(self::URI, $requestData);
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
foreach ($this->intervalsForAuditor as $interval) {
|
||||
$this->assertDatabaseHas('time_intervals', $interval->toArray());
|
||||
}
|
||||
}
|
||||
|
||||
public function test_bulk_edit_as_user(): void
|
||||
{
|
||||
$this->intervals->each->setAttribute('task_id', $this->task->id);
|
||||
|
||||
foreach ($this->intervals as $interval) {
|
||||
$this->assertDatabaseMissing('time_intervals', $interval->toArray());
|
||||
}
|
||||
|
||||
$requestData = ['intervals' => $this->intervals->toArray()];
|
||||
|
||||
$response = $this->actingAs($this->user)->postJson(self::URI, $requestData);
|
||||
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_bulk_edit_your_own_as_user(): void
|
||||
{
|
||||
$this->intervals->each->setAttribute('task_id', $this->task->id);
|
||||
|
||||
foreach ($this->intervalsForUser as $interval) {
|
||||
$this->assertDatabaseHas('time_intervals', $interval->toArray());
|
||||
}
|
||||
|
||||
$requestData = ['intervals' => $this->intervalsForUser->toArray()];
|
||||
|
||||
$response = $this->actingAs($this->user)->postJson(self::URI, $requestData);
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
foreach ($this->intervalsForUser as $interval) {
|
||||
$this->assertDatabaseHas('time_intervals', $interval->toArray());
|
||||
}
|
||||
}
|
||||
|
||||
public function test_with_not_existing_intervals(): void
|
||||
{
|
||||
$this->intervals->each->setAttribute('task_id', $this->task->id);
|
||||
|
||||
$nonIntervals = [
|
||||
['id' => TimeInterval::max('id') + 1, 'task_id' => $this->task->id],
|
||||
['id' => TimeInterval::max('id') + 2, 'task_id' => $this->task->id]
|
||||
];
|
||||
|
||||
$requestData = ['intervals' => array_merge($this->intervals->toArray(), $nonIntervals)];
|
||||
|
||||
foreach ($this->intervals as $interval) {
|
||||
$this->assertDatabaseMissing('time_intervals', $interval->toArray());
|
||||
}
|
||||
|
||||
$response = $this->actingAs($this->admin)->postJson(self::URI, $requestData);
|
||||
|
||||
$response->assertValidationError();
|
||||
}
|
||||
|
||||
public function test_unauthorized(): void
|
||||
{
|
||||
$response = $this->postJson(self::URI);
|
||||
|
||||
$response->assertUnauthorized();
|
||||
}
|
||||
|
||||
public function test_without_params(): void
|
||||
{
|
||||
$response = $this->actingAs($this->admin)->postJson(self::URI);
|
||||
|
||||
$response->assertValidationError();
|
||||
}
|
||||
}
|
||||
177
tests/Feature/TimeIntervals/BulkRemoveTest.php
Normal file
177
tests/Feature/TimeIntervals/BulkRemoveTest.php
Normal file
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Tests\Feature\TimeIntervals;
|
||||
|
||||
use App\Models\TimeInterval;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
use Tests\Facades\IntervalFactory;
|
||||
use Tests\Facades\UserFactory;
|
||||
use Tests\TestCase;
|
||||
|
||||
class BulkRemoveTest extends TestCase
|
||||
{
|
||||
private const URI = 'time-intervals/bulk-remove';
|
||||
|
||||
private const INTERVALS_AMOUNT = 5;
|
||||
|
||||
/** @var User $admin */
|
||||
private User $admin;
|
||||
/** @var User $manager */
|
||||
private User $manager;
|
||||
/** @var User $auditor */
|
||||
private User $auditor;
|
||||
/** @var User $user */
|
||||
private User $user;
|
||||
|
||||
private Collection $intervals;
|
||||
private Collection $intervalsForManager;
|
||||
private Collection $intervalsForAuditor;
|
||||
private Collection $intervalsForUser;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->admin = UserFactory::refresh()->asAdmin()->withTokens()->create();
|
||||
$this->manager = UserFactory::refresh()->asManager()->withTokens()->create();
|
||||
$this->auditor = UserFactory::refresh()->asAuditor()->withTokens()->create();
|
||||
$this->user = UserFactory::refresh()->asUser()->withTokens()->create();
|
||||
|
||||
$this->intervals = IntervalFactory::refresh()->withRandomRelations()->createMany(self::INTERVALS_AMOUNT);
|
||||
$this->intervalsForManager = IntervalFactory::refresh()
|
||||
->forUser($this->manager)
|
||||
->createMany(self::INTERVALS_AMOUNT);
|
||||
$this->intervalsForAuditor = IntervalFactory::refresh()
|
||||
->forUser($this->auditor)
|
||||
->createMany(self::INTERVALS_AMOUNT);
|
||||
$this->intervalsForUser = IntervalFactory::refresh()
|
||||
->forUser($this->user)
|
||||
->createMany(self::INTERVALS_AMOUNT);
|
||||
}
|
||||
|
||||
public function test_bulk_remove_as_admin(): void
|
||||
{
|
||||
foreach ($this->intervals as $interval) {
|
||||
$this->assertDatabaseHas('time_intervals', $interval->toArray());
|
||||
}
|
||||
|
||||
$requestData = ['intervals' => $this->intervals->pluck('id')->toArray()];
|
||||
|
||||
$response = $this->actingAs($this->admin)->postJson(self::URI, $requestData);
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
foreach ($this->intervals as $interval) {
|
||||
$this->assertSoftDeleted('time_intervals', $interval->toArray());
|
||||
}
|
||||
}
|
||||
|
||||
public function test_bulk_remove_as_manager(): void
|
||||
{
|
||||
foreach ($this->intervals as $interval) {
|
||||
$this->assertDatabaseHas('time_intervals', $interval->toArray());
|
||||
}
|
||||
|
||||
$requestData = ['intervals' => $this->intervals->pluck('id')->toArray()];
|
||||
|
||||
$response = $this->actingAs($this->manager)->postJson(self::URI, $requestData);
|
||||
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_bulk_remove_your_own_as_manager(): void
|
||||
{
|
||||
foreach ($this->intervalsForManager as $interval) {
|
||||
$this->assertDatabaseHas('time_intervals', $interval->toArray());
|
||||
}
|
||||
|
||||
$requestData = ['intervals' => $this->intervalsForManager->pluck('id')->toArray()];
|
||||
|
||||
$response = $this->actingAs($this->manager)->postJson(self::URI, $requestData);
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
foreach ($this->intervalsForManager as $interval) {
|
||||
$this->assertDatabaseHas('time_intervals', $interval->toArray());
|
||||
}
|
||||
}
|
||||
|
||||
public function test_bulk_remove_as_user(): void
|
||||
{
|
||||
foreach ($this->intervals as $interval) {
|
||||
$this->assertDatabaseHas('time_intervals', $interval->toArray());
|
||||
}
|
||||
|
||||
$requestData = ['intervals' => $this->intervals->pluck('id')->toArray()];
|
||||
|
||||
$response = $this->actingAs($this->user)->postJson(self::URI, $requestData);
|
||||
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_bulk_remove_your_own_as_user(): void
|
||||
{
|
||||
foreach ($this->intervalsForUser as $interval) {
|
||||
$this->assertDatabaseHas('time_intervals', $interval->toArray());
|
||||
}
|
||||
|
||||
$requestData = ['intervals' => $this->intervalsForUser->pluck('id')->toArray()];
|
||||
|
||||
$response = $this->actingAs($this->user)->postJson(self::URI, $requestData);
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
foreach ($this->intervalsForUser as $interval) {
|
||||
$this->assertDatabaseHas('time_intervals', $interval->toArray());
|
||||
}
|
||||
}
|
||||
|
||||
public function test_bulk_remove_your_own_as_auditor(): void
|
||||
{
|
||||
foreach ($this->intervalsForAuditor as $interval) {
|
||||
$this->assertDatabaseHas('time_intervals', $interval->toArray());
|
||||
}
|
||||
|
||||
$requestData = ['intervals' => $this->intervalsForAuditor->pluck('id')->toArray()];
|
||||
|
||||
$response = $this->actingAs($this->auditor)->postJson(self::URI, $requestData);
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
foreach ($this->intervalsForAuditor as $interval) {
|
||||
$this->assertDatabaseHas('time_intervals', $interval->toArray());
|
||||
}
|
||||
}
|
||||
|
||||
public function test_with_not_existing_intervals(): void
|
||||
{
|
||||
$nonIntervals = [TimeInterval::max('id') + 1, TimeInterval::max('id') + 2];
|
||||
|
||||
$requestData = ['intervals' => array_merge($this->intervals->pluck('id')->toArray(), $nonIntervals)];
|
||||
|
||||
foreach ($this->intervals as $interval) {
|
||||
$this->assertDatabaseHas('time_intervals', $interval->toArray());
|
||||
}
|
||||
|
||||
$response = $this->actingAs($this->admin)->postJson(self::URI, $requestData);
|
||||
|
||||
$response->assertValidationError();
|
||||
}
|
||||
|
||||
public function test_unauthorized(): void
|
||||
{
|
||||
$response = $this->postJson(self::URI);
|
||||
|
||||
$response->assertUnauthorized();
|
||||
}
|
||||
|
||||
public function test_without_params(): void
|
||||
{
|
||||
$response = $this->actingAs($this->admin)->postJson(self::URI);
|
||||
|
||||
$response->assertValidationError();
|
||||
}
|
||||
}
|
||||
43
tests/Feature/TimeIntervals/CountTest.php
Normal file
43
tests/Feature/TimeIntervals/CountTest.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Tests\Feature\TimeIntervals;
|
||||
|
||||
use App\Models\TimeInterval;
|
||||
use App\Models\User;
|
||||
use Tests\Facades\IntervalFactory;
|
||||
use Tests\Facades\UserFactory;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CountTest extends TestCase
|
||||
{
|
||||
private const URI = 'time-intervals/count';
|
||||
|
||||
private const SCREENSHOTS_AMOUNT = 10;
|
||||
|
||||
private User $admin;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->admin = UserFactory::asAdmin()->withTokens()->create();
|
||||
|
||||
IntervalFactory::createMany(self::SCREENSHOTS_AMOUNT);
|
||||
}
|
||||
|
||||
public function test_count(): void
|
||||
{
|
||||
$response = $this->actingAs($this->admin)->getJson(self::URI);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['total' => TimeInterval::count()]);
|
||||
}
|
||||
|
||||
public function test_unauthorized(): void
|
||||
{
|
||||
$response = $this->getJson(self::URI);
|
||||
|
||||
$response->assertUnauthorized();
|
||||
}
|
||||
}
|
||||
169
tests/Feature/TimeIntervals/CreateTest.php
Normal file
169
tests/Feature/TimeIntervals/CreateTest.php
Normal file
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\TimeIntervals;
|
||||
|
||||
use App\Models\Task;
|
||||
use App\Models\TimeInterval;
|
||||
use App\Models\User;
|
||||
use Tests\Facades\IntervalFactory;
|
||||
use Tests\Facades\TaskFactory;
|
||||
use Tests\Facades\UserFactory;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CreateTest extends TestCase
|
||||
{
|
||||
private const URI = 'time-intervals/create';
|
||||
|
||||
private User $admin;
|
||||
private Task $task;
|
||||
|
||||
private array $intervalData;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->admin = UserFactory::asAdmin()->withTokens()->create();
|
||||
|
||||
$this->task = TaskFactory::forUser($this->admin)->create();
|
||||
|
||||
$this->intervalData = IntervalFactory::createRandomModelDataWithRelation();
|
||||
$this->intervalData['user_id'] = $this->admin->id;
|
||||
}
|
||||
|
||||
public function test_create(): void
|
||||
{
|
||||
$this->assertDatabaseMissing('time_intervals', $this->intervalData);
|
||||
|
||||
$response = $this->actingAs($this->admin)->postJson(self::URI, $this->intervalData);
|
||||
|
||||
$response->assertOk();
|
||||
$this->assertDatabaseHas('time_intervals', $this->intervalData);
|
||||
}
|
||||
|
||||
public function test_already_exists_left(): void
|
||||
{
|
||||
$this->intervalData['start_at'] = '1900-01-01 01:00:00';
|
||||
$this->intervalData['end_at'] = '1900-01-01 01:05:00';
|
||||
|
||||
TimeInterval::create($this->intervalData);
|
||||
$this->assertDatabaseHas('time_intervals', $this->intervalData);
|
||||
|
||||
$newInterval = $this->intervalData;
|
||||
$newInterval['start_at'] = '1900-01-01 00:55:00';
|
||||
$newInterval['end_at'] = '1900-01-01 01:05:00';
|
||||
|
||||
$response = $this->actingAs($this->admin)->postJson(self::URI, $newInterval);
|
||||
|
||||
$response->assertValidationError();
|
||||
}
|
||||
|
||||
public function test_already_exists_right(): void
|
||||
{
|
||||
$this->intervalData['start_at'] = '1900-01-01 01:00:00';
|
||||
$this->intervalData['end_at'] = '1900-01-01 01:05:00';
|
||||
|
||||
TimeInterval::create($this->intervalData);
|
||||
$this->assertDatabaseHas('time_intervals', $this->intervalData);
|
||||
|
||||
$newInterval = $this->intervalData;
|
||||
$newInterval['start_at'] = '1900-01-01 01:00:00';
|
||||
$newInterval['end_at'] = '1900-01-01 01:10:00';
|
||||
|
||||
$response = $this->actingAs($this->admin)->postJson(self::URI, $newInterval);
|
||||
|
||||
$response->assertValidationError();
|
||||
}
|
||||
|
||||
public function test_already_exists_left_inner(): void
|
||||
{
|
||||
$this->intervalData['start_at'] = '1900-01-01 01:00:00';
|
||||
$this->intervalData['end_at'] = '1900-01-01 01:05:00';
|
||||
|
||||
TimeInterval::create($this->intervalData);
|
||||
$this->assertDatabaseHas('time_intervals', $this->intervalData);
|
||||
|
||||
$newInterval = $this->intervalData;
|
||||
$newInterval['start_at'] = '1900-01-01 00:55:00';
|
||||
$newInterval['end_at'] = '1900-01-01 01:03:00';
|
||||
|
||||
$response = $this->actingAs($this->admin)->postJson(self::URI, $newInterval);
|
||||
|
||||
$response->assertValidationError();
|
||||
}
|
||||
|
||||
public function test_already_exists_right_inner(): void
|
||||
{
|
||||
$this->intervalData['start_at'] = '1900-01-01 01:00:00';
|
||||
$this->intervalData['end_at'] = '1900-01-01 01:05:00';
|
||||
|
||||
TimeInterval::create($this->intervalData);
|
||||
$this->assertDatabaseHas('time_intervals', $this->intervalData);
|
||||
|
||||
$newInterval = $this->intervalData;
|
||||
$newInterval['start_at'] = '1900-01-01 01:03:00';
|
||||
$newInterval['end_at'] = '1900-01-01 01:10:00';
|
||||
|
||||
$response = $this->actingAs($this->admin)->postJson(self::URI, $newInterval);
|
||||
|
||||
$response->assertValidationError();
|
||||
}
|
||||
|
||||
public function test_already_exists_inner(): void
|
||||
{
|
||||
$this->intervalData['start_at'] = '1900-01-01 01:00:00';
|
||||
$this->intervalData['end_at'] = '1900-01-01 01:05:00';
|
||||
|
||||
TimeInterval::create($this->intervalData);
|
||||
$this->assertDatabaseHas('time_intervals', $this->intervalData);
|
||||
|
||||
$newInterval = $this->intervalData;
|
||||
$newInterval['start_at'] = '1900-01-01 01:01:00';
|
||||
$newInterval['end_at'] = '1900-01-01 01:03:00';
|
||||
|
||||
$response = $this->actingAs($this->admin)->postJson(self::URI, $newInterval);
|
||||
|
||||
$response->assertValidationError();
|
||||
}
|
||||
|
||||
public function test_already_exists_outer(): void
|
||||
{
|
||||
$this->intervalData['start_at'] = '1900-01-01 01:00:00';
|
||||
$this->intervalData['end_at'] = '1900-01-01 01:05:00';
|
||||
|
||||
TimeInterval::create($this->intervalData);
|
||||
$this->assertDatabaseHas('time_intervals', $this->intervalData);
|
||||
|
||||
$newInterval = $this->intervalData;
|
||||
$newInterval['start_at'] = '1900-01-01 00:55:00';
|
||||
$newInterval['end_at'] = '1900-01-01 01:10:00';
|
||||
|
||||
$response = $this->actingAs($this->admin)->postJson(self::URI, $newInterval);
|
||||
|
||||
$response->assertValidationError();
|
||||
}
|
||||
|
||||
public function test_already_exists(): void
|
||||
{
|
||||
TimeInterval::create($this->intervalData);
|
||||
$this->assertDatabaseHas('time_intervals', $this->intervalData);
|
||||
|
||||
$response = $this->actingAs($this->admin)->postJson(self::URI, $this->intervalData);
|
||||
|
||||
$response->assertValidationError();
|
||||
}
|
||||
|
||||
public function test_unauthorized(): void
|
||||
{
|
||||
$response = $this->postJson(self::URI);
|
||||
|
||||
$response->assertUnauthorized();
|
||||
}
|
||||
|
||||
public function test_without_params(): void
|
||||
{
|
||||
$response = $this->actingAs($this->admin)->postJson(self::URI);
|
||||
|
||||
$response->assertValidationError();
|
||||
}
|
||||
}
|
||||
61
tests/Feature/TimeIntervals/DashboardTest.php
Normal file
61
tests/Feature/TimeIntervals/DashboardTest.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\TimeIntervals;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Collection;
|
||||
use Tests\Facades\IntervalFactory;
|
||||
use Tests\Facades\UserFactory;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DashboardTest extends TestCase
|
||||
{
|
||||
private const URI = 'time-intervals/dashboard';
|
||||
|
||||
private const INTERVALS_AMOUNT = 2;
|
||||
|
||||
private Collection $intervals;
|
||||
private User $admin;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->admin = UserFactory::asAdmin()->withTokens()->create();
|
||||
|
||||
$this->intervals = IntervalFactory::forUser($this->admin)->createMany(self::INTERVALS_AMOUNT);
|
||||
}
|
||||
|
||||
public function test_dashboard(): void
|
||||
{
|
||||
$requestData = [
|
||||
'start_at' => $this->intervals->min('start_at'),
|
||||
'end_at' => $this->intervals->max('start_at')->addHour(),
|
||||
'user_ids' => [$this->admin->id]
|
||||
];
|
||||
|
||||
$response = $this->actingAs($this->admin)->postJson(self::URI, $requestData);
|
||||
|
||||
$response->assertOk();
|
||||
$this->assertCount(
|
||||
$this->intervals->count(),
|
||||
$response->json('userIntervals')[$this->admin->id]['intervals']
|
||||
);
|
||||
|
||||
#TODO change later
|
||||
}
|
||||
|
||||
public function test_unauthorized(): void
|
||||
{
|
||||
$response = $this->getJson(self::URI);
|
||||
|
||||
$response->assertUnauthorized();
|
||||
}
|
||||
|
||||
public function test_without_params(): void
|
||||
{
|
||||
$response = $this->actingAs($this->admin)->getJson(self::URI);
|
||||
|
||||
$response->assertValidationError();
|
||||
}
|
||||
}
|
||||
151
tests/Feature/TimeIntervals/EditTest.php
Normal file
151
tests/Feature/TimeIntervals/EditTest.php
Normal file
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Tests\Feature\TimeIntervals;
|
||||
|
||||
use App\Models\TimeInterval;
|
||||
use App\Models\User;
|
||||
use Tests\Facades\IntervalFactory;
|
||||
use Tests\Facades\UserFactory;
|
||||
use Tests\TestCase;
|
||||
|
||||
class EditTest extends TestCase
|
||||
{
|
||||
private const URI = 'time-intervals/edit';
|
||||
|
||||
/** @var User $admin */
|
||||
private User $admin;
|
||||
/** @var User $manager */
|
||||
private User $manager;
|
||||
/** @var User $auditor */
|
||||
private User $auditor;
|
||||
/** @var User $user */
|
||||
private User $user;
|
||||
|
||||
/** @var TimeInterval $timeInterval */
|
||||
private TimeInterval $timeInterval;
|
||||
/** @var TimeInterval $timeIntervalForManager */
|
||||
private TimeInterval $timeIntervalForManager;
|
||||
/** @var TimeInterval $timeIntervalForAuditor */
|
||||
private TimeInterval $timeIntervalForAuditor;
|
||||
/** @var TimeInterval $timeIntervalForUser */
|
||||
private TimeInterval $timeIntervalForUser;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->admin = UserFactory::refresh()->asAdmin()->withTokens()->create();
|
||||
$this->manager = UserFactory::refresh()->asManager()->withTokens()->create();
|
||||
$this->auditor = UserFactory::refresh()->asAuditor()->withTokens()->create();
|
||||
$this->user = UserFactory::refresh()->asUser()->withTokens()->create();
|
||||
|
||||
$this->timeInterval = IntervalFactory::create();
|
||||
$this->timeIntervalForManager = IntervalFactory::forUser($this->manager)->create();
|
||||
$this->timeIntervalForAuditor = IntervalFactory::forUser($this->auditor)->create();
|
||||
$this->timeIntervalForUser = IntervalFactory::forUser($this->user)->create();
|
||||
}
|
||||
|
||||
public function test_edit_as_admin(): void
|
||||
{
|
||||
$this->assertDatabaseHas('time_intervals', $this->timeInterval->toArray());
|
||||
|
||||
$editedInterval = clone $this->timeInterval;
|
||||
$editedInterval->user_id = UserFactory::refresh()->asUser()->create()->id;
|
||||
|
||||
$response = $this->actingAs($this->admin)->postJson(self::URI, $editedInterval->toArray());
|
||||
|
||||
$response->assertOk();
|
||||
$this->assertDatabaseHas('time_intervals', $editedInterval->toArray());
|
||||
}
|
||||
|
||||
public function test_edit_as_manager(): void
|
||||
{
|
||||
$this->assertDatabaseHas('time_intervals', $this->timeInterval->toArray());
|
||||
|
||||
$editedInterval = clone $this->timeInterval;
|
||||
$editedInterval->user_id = UserFactory::refresh()->asUser()->create()->id;
|
||||
|
||||
$response = $this->actingAs($this->manager)->postJson(self::URI, $editedInterval->toArray());
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_edit_your_own_as_manager(): void
|
||||
{
|
||||
$this->assertDatabaseHas('time_intervals', $this->timeInterval->toArray());
|
||||
|
||||
$editedInterval = clone $this->timeIntervalForManager;
|
||||
$editedInterval->user_id = UserFactory::refresh()->asUser()->create()->id;
|
||||
|
||||
$response = $this->actingAs($this->manager)->postJson(self::URI, $editedInterval->toArray());
|
||||
|
||||
$response->assertOk();
|
||||
$this->assertDatabaseHas('time_intervals', $editedInterval->toArray());
|
||||
}
|
||||
|
||||
public function test_edit_as_auditor(): void
|
||||
{
|
||||
$this->assertDatabaseHas('time_intervals', $this->timeInterval->toArray());
|
||||
|
||||
$editedInterval = clone $this->timeInterval;
|
||||
$editedInterval->user_id = UserFactory::refresh()->asUser()->create()->id;
|
||||
|
||||
$response = $this->actingAs($this->auditor)->postJson(self::URI, $editedInterval->toArray());
|
||||
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_edit_your_own_as_auditor(): void
|
||||
{
|
||||
$this->assertDatabaseHas('time_intervals', $this->timeIntervalForAuditor->toArray());
|
||||
|
||||
$editedInterval = clone $this->timeIntervalForAuditor;
|
||||
$editedInterval->user_id = UserFactory::refresh()->asUser()->create()->id;
|
||||
|
||||
$response = $this->actingAs($this->auditor)->postJson(self::URI, $editedInterval->toArray());
|
||||
|
||||
$response->assertOk();
|
||||
$this->assertDatabaseHas('time_intervals', $editedInterval->toArray());
|
||||
}
|
||||
|
||||
public function test_edit_as_user(): void
|
||||
{
|
||||
$this->assertDatabaseHas('time_intervals', $this->timeInterval->toArray());
|
||||
|
||||
$editedInterval = clone $this->timeInterval;
|
||||
$editedInterval->user_id = UserFactory::refresh()->asUser()->create()->id;
|
||||
|
||||
$response = $this->actingAs($this->user)->postJson(self::URI, $editedInterval->toArray());
|
||||
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_edit_your_own_as_user(): void
|
||||
{
|
||||
$this->assertDatabaseHas('time_intervals', $this->timeIntervalForManager->toArray());
|
||||
|
||||
$editedInterval = clone $this->timeIntervalForUser;
|
||||
$editedInterval->user_id = UserFactory::refresh()->asUser()->create()->id;
|
||||
|
||||
$response = $this
|
||||
->actingAs($this->user)
|
||||
->postJson(self::URI, $editedInterval->toArray());
|
||||
|
||||
$response->assertOk();
|
||||
$this->assertDatabaseHas('time_intervals', $editedInterval->toArray());
|
||||
}
|
||||
|
||||
public function test_unauthorized(): void
|
||||
{
|
||||
$response = $this->postJson(self::URI);
|
||||
|
||||
$response->assertUnauthorized();
|
||||
}
|
||||
|
||||
public function test_without_params(): void
|
||||
{
|
||||
$response = $this->actingAs($this->admin)->postJson(self::URI);
|
||||
|
||||
$response->assertValidationError();
|
||||
}
|
||||
}
|
||||
42
tests/Feature/TimeIntervals/ListTest.php
Normal file
42
tests/Feature/TimeIntervals/ListTest.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\TimeIntervals;
|
||||
|
||||
use App\Models\TimeInterval;
|
||||
use App\Models\User;
|
||||
use Tests\Facades\IntervalFactory;
|
||||
use Tests\Facades\UserFactory;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ListTest extends TestCase
|
||||
{
|
||||
private const URI = 'time-intervals/list';
|
||||
|
||||
private const INTERVALS_AMOUNT = 10;
|
||||
|
||||
private User $admin;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->admin = UserFactory::asAdmin()->withTokens()->create();
|
||||
|
||||
IntervalFactory::createMany(self::INTERVALS_AMOUNT);
|
||||
}
|
||||
|
||||
public function test_list(): void
|
||||
{
|
||||
$response = $this->actingAs($this->admin)->getJson(self::URI);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(TimeInterval::all()->toArray());
|
||||
}
|
||||
|
||||
public function test_unauthorized(): void
|
||||
{
|
||||
$response = $this->getJson(self::URI);
|
||||
|
||||
$response->assertUnauthorized();
|
||||
}
|
||||
}
|
||||
135
tests/Feature/TimeIntervals/RemoveTest.php
Normal file
135
tests/Feature/TimeIntervals/RemoveTest.php
Normal file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Tests\Feature\TimeIntervals;
|
||||
|
||||
use App\Models\TimeInterval;
|
||||
use App\Models\User;
|
||||
use Tests\Facades\IntervalFactory;
|
||||
use Tests\Facades\UserFactory;
|
||||
use Tests\TestCase;
|
||||
|
||||
class RemoveTest extends TestCase
|
||||
{
|
||||
private const URI = 'time-intervals/remove';
|
||||
|
||||
/** @var User $admin */
|
||||
private User $admin;
|
||||
/** @var User $manager */
|
||||
private User $manager;
|
||||
/** @var User $auditor */
|
||||
private User $auditor;
|
||||
/** @var User $user */
|
||||
private User $user;
|
||||
|
||||
/** @var TimeInterval $timeInterval */
|
||||
private TimeInterval $timeInterval;
|
||||
/** @var TimeInterval $timeIntervalForManager */
|
||||
private TimeInterval $timeIntervalForManager;
|
||||
/** @var TimeInterval $timeIntervalForAuditor */
|
||||
private TimeInterval $timeIntervalForAuditor;
|
||||
/** @var TimeInterval $timeIntervalForUser */
|
||||
private TimeInterval $timeIntervalForUser;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->admin = UserFactory::refresh()->asAdmin()->withTokens()->create();
|
||||
$this->manager = UserFactory::refresh()->asManager()->withTokens()->create();
|
||||
$this->auditor = UserFactory::refresh()->asAuditor()->withTokens()->create();
|
||||
$this->user = UserFactory::refresh()->asUser()->withTokens()->create();
|
||||
|
||||
$this->timeInterval = IntervalFactory::create();
|
||||
$this->timeIntervalForManager = IntervalFactory::forUser($this->manager)->create();
|
||||
$this->timeIntervalForAuditor = IntervalFactory::forUser($this->auditor)->create();
|
||||
$this->timeIntervalForUser = IntervalFactory::forUser($this->user)->create();
|
||||
}
|
||||
|
||||
public function test_remove_as_admin(): void
|
||||
{
|
||||
$this->assertDatabaseHas('time_intervals', $this->timeInterval->toArray());
|
||||
|
||||
$response = $this->actingAs($this->admin)->postJson(self::URI, $this->timeInterval->only('id'));
|
||||
|
||||
$response->assertOk();
|
||||
$this->assertSoftDeleted('time_intervals', ['id' => $this->timeInterval->id]);
|
||||
}
|
||||
|
||||
public function test_remove_as_manager(): void
|
||||
{
|
||||
$this->assertDatabaseHas('time_intervals', $this->timeInterval->toArray());
|
||||
|
||||
$response = $this->actingAs($this->manager)->postJson(self::URI, $this->timeInterval->only('id'));
|
||||
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_remove_your_own_as_manager(): void
|
||||
{
|
||||
$this->assertDatabaseHas('time_intervals', $this->timeIntervalForManager->toArray());
|
||||
|
||||
$response = $this
|
||||
->actingAs($this->manager)
|
||||
->postJson(self::URI, $this->timeIntervalForManager->only('id'));
|
||||
|
||||
$response->assertOk();
|
||||
$this->assertSoftDeleted('time_intervals', ['id' => $this->timeIntervalForManager->id]);
|
||||
}
|
||||
|
||||
public function test_remove_as_auditor(): void
|
||||
{
|
||||
$this->assertDatabaseHas('time_intervals', $this->timeInterval->toArray());
|
||||
|
||||
$response = $this->actingAs($this->auditor)->postJson(self::URI, $this->timeInterval->only('id'));
|
||||
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_remove_your_own_as_auditor(): void
|
||||
{
|
||||
$this->assertDatabaseHas('time_intervals', $this->timeIntervalForManager->toArray());
|
||||
|
||||
$response = $this
|
||||
->actingAs($this->auditor)
|
||||
->postJson(self::URI, $this->timeIntervalForAuditor->only('id'));
|
||||
|
||||
$response->assertOk();
|
||||
$this->assertSoftDeleted('time_intervals', ['id' => $this->timeIntervalForAuditor->id]);
|
||||
}
|
||||
|
||||
public function test_remove_as_user(): void
|
||||
{
|
||||
$this->assertDatabaseHas('time_intervals', $this->timeInterval->toArray());
|
||||
|
||||
$response = $this->actingAs($this->user)->postJson(self::URI, $this->timeInterval->only('id'));
|
||||
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_remove_your_own_as_user(): void
|
||||
{
|
||||
$this->assertDatabaseHas('time_intervals', $this->timeIntervalForManager->toArray());
|
||||
|
||||
$response = $this
|
||||
->actingAs($this->user)
|
||||
->postJson(self::URI, $this->timeIntervalForUser->only('id'));
|
||||
|
||||
$response->assertOk();
|
||||
$this->assertSoftDeleted('time_intervals', ['id' => $this->timeIntervalForUser->id]);
|
||||
}
|
||||
|
||||
public function test_unauthorized(): void
|
||||
{
|
||||
$response = $this->postJson(self::URI);
|
||||
|
||||
$response->assertUnauthorized();
|
||||
}
|
||||
|
||||
public function test_without_params(): void
|
||||
{
|
||||
$response = $this->actingAs($this->admin)->postJson(self::URI);
|
||||
|
||||
$response->assertValidationError();
|
||||
}
|
||||
}
|
||||
106
tests/Feature/TimeIntervals/ShowTest.php
Normal file
106
tests/Feature/TimeIntervals/ShowTest.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Tests\Feature\TimeIntervals;
|
||||
|
||||
use App\Models\TimeInterval;
|
||||
use App\Models\User;
|
||||
use Tests\Facades\IntervalFactory;
|
||||
use Tests\Facades\UserFactory;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ShowTest extends TestCase
|
||||
{
|
||||
private const URI = 'time-intervals/show';
|
||||
|
||||
/** @var User $admin */
|
||||
private User $admin;
|
||||
/** @var User $manager */
|
||||
private User $manager;
|
||||
/** @var User $auditor */
|
||||
private User $auditor;
|
||||
/** @var User $user */
|
||||
private User $user;
|
||||
|
||||
/** @var TimeInterval $timeInterval */
|
||||
private TimeInterval $timeInterval;
|
||||
/** @var TimeInterval $timeIntervalForUser */
|
||||
private TimeInterval $timeIntervalForUser;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->admin = UserFactory::refresh()->asAdmin()->withTokens()->create();
|
||||
$this->manager = UserFactory::refresh()->asManager()->withTokens()->create();
|
||||
$this->auditor = UserFactory::refresh()->asAuditor()->withTokens()->create();
|
||||
$this->user = UserFactory::refresh()->asUser()->withTokens()->create();
|
||||
|
||||
$this->timeInterval = IntervalFactory::create();
|
||||
$this->timeIntervalForUser = IntervalFactory::forUser($this->user)->create();
|
||||
}
|
||||
|
||||
public function test_show_as_admin(): void
|
||||
{
|
||||
$this->assertDatabaseHas('time_intervals', $this->timeInterval->toArray());
|
||||
|
||||
$response = $this->actingAs($this->admin)->postJson(self::URI, $this->timeInterval->only('id'));
|
||||
$response->assertOk();
|
||||
|
||||
$response->assertJson($this->timeInterval->toArray());
|
||||
}
|
||||
|
||||
public function test_show_as_manager(): void
|
||||
{
|
||||
$this->assertDatabaseHas('time_intervals', $this->timeInterval->toArray());
|
||||
|
||||
$response = $this->actingAs($this->manager)->postJson(self::URI, $this->timeInterval->only('id'));
|
||||
$response->assertOk();
|
||||
|
||||
$response->assertJson($this->timeInterval->toArray());
|
||||
}
|
||||
|
||||
public function test_show_as_auditor(): void
|
||||
{
|
||||
$this->assertDatabaseHas('time_intervals', $this->timeInterval->toArray());
|
||||
|
||||
$response = $this->actingAs($this->auditor)->postJson(self::URI, $this->timeInterval->only('id'));
|
||||
$response->assertOk();
|
||||
|
||||
$response->assertJson($this->timeInterval->toArray());
|
||||
}
|
||||
|
||||
public function test_show_as_user(): void
|
||||
{
|
||||
$this->assertDatabaseHas('time_intervals', $this->timeInterval->toArray());
|
||||
|
||||
$response = $this->actingAs($this->user)->postJson(self::URI, $this->timeInterval->only('id'));
|
||||
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_show_your_own_as_user(): void
|
||||
{
|
||||
$this->assertDatabaseHas('time_intervals', $this->timeIntervalForUser->toArray());
|
||||
|
||||
$response = $this
|
||||
->actingAs($this->user)
|
||||
->postJson(self::URI, $this->timeIntervalForUser->only('id'));
|
||||
|
||||
$response->assertJson($this->timeIntervalForUser->toArray());
|
||||
}
|
||||
|
||||
public function test_unauthorized(): void
|
||||
{
|
||||
$response = $this->getJson(self::URI);
|
||||
|
||||
$response->assertUnauthorized();
|
||||
}
|
||||
|
||||
public function test_without_params(): void
|
||||
{
|
||||
$response = $this->actingAs($this->admin)->getJson(self::URI);
|
||||
|
||||
$response->assertValidationError();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user