Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
namespace Tests\Feature;
use App\Models\Task;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class KanbanTest extends TestCase
{
use RefreshDatabase;
private $user, $lists;
/** @test */
public function should_update_the_board_list_id()
{
$this->signIn($this->user);
$task = create(Task::class, ['board_list_id' => $this->lists->first()]);
$task->board_list_id = $this->lists[1]->id;
$this->json('PUT', "api/services/tasks/{$task->id}", array_merge($task->toArray(), ['event' => 'moved']))->assertStatus(200);
$this->assertDatabaseHas('tasks', $task->toArray());
}
/** @test */
function should_move_the_index_when_a_task_is_moved_between_two_existing_ones()
{
$this->signIn($this->user);
$secondListId = $this->lists[1]->id;
$task = create(Task::class, ['board_list_id' => $this->lists->first(), 'order_id' => 1, 'user_id' => $this->user->id]);
$task->board_list_id = $secondListId;
$t1 = create(Task::class, ['board_list_id' => $secondListId, 'order_id' => 0, 'user_id' => $this->user->id]);
$t2 = create(Task::class, ['board_list_id' => $secondListId, 'order_id' => 1, 'user_id' => $this->user->id]);
$t3 = create(Task::class, ['board_list_id' => $secondListId, 'order_id' => 2, 'user_id' => $this->user->id]);
$this->json('PUT', "api/services/tasks/{$task->id}", array_merge($task->toArray(), ['event' => 'added']))->assertStatus(200);
$this->assertDatabaseHas('tasks', $t1->toArray());
$this->assertDatabaseHas('tasks', $task->toArray());
$t2->order_id = 2;
$this->assertDatabaseHas('tasks', $t2->toArray());
$t3->order_id = 3;
$this->assertDatabaseHas('tasks', $t2->toArray());
}
/** @test */
function should_exchange_order_id_when_a_task_is_moved()
{
$this->signIn($this->user);
$firstList = $this->lists->first();
$t1 = create(Task::class, ['board_list_id' => $firstList, 'order_id' => 0, 'user_id' => $this->user->id]);
$t1->order_id = 1;
$t2 = create(Task::class, ['board_list_id' => $firstList, 'order_id' => 1, 'user_id' => $this->user->id]);
$t2->order_id = 0;
$this->json('PUT', "api/services/tasks/{$t1->id}", array_merge($t1->toArray(), ['event' => 'moved']))->assertStatus(200);
$this->assertDatabaseHas('tasks', $t1->toArray());
$this->assertDatabaseHas('tasks', $t2->toArray());
}
protected function setUp(): void
{
parent::setUp();
$this->user = create(User::class);
$this->lists = $this->user->board->lists;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.