68 lines
2.1 KiB
PHP
68 lines
2.1 KiB
PHP
<?php
|
|
|
|
use App\Models\ToDo;
|
|
use App\Models\User;
|
|
use Laravel\Sanctum\Sanctum;
|
|
|
|
test('user can start a time tracker', function () {
|
|
Sanctum::actingAs($user = User::factory()->create());
|
|
$toDo = ToDo::factory()->create(['user_id' => $user->id, 'checked' => false]);
|
|
|
|
$this->postJson('/api/time-tracker', ['todo_id' => $toDo->id])
|
|
->assertCreated()
|
|
->assertJson([
|
|
'id' => $toDo->timeTrackers()->value('id'),
|
|
'start_at' => now()->format('Y-m-d H:i:s'),
|
|
'end_at' => null,
|
|
'to_do' => [
|
|
'id' => $toDo->id,
|
|
'user_id' => $user->id,
|
|
'name' => $toDo->name,
|
|
'checked' => false,
|
|
],
|
|
]);
|
|
});
|
|
|
|
test('user can retrieve his current timer', function () {
|
|
Sanctum::actingAs($user = User::factory()->create());
|
|
$toDo = ToDo::factory()->create(['user_id' => $user->id, 'checked' => false]);
|
|
|
|
$this->postJson('/api/time-tracker', ['todo_id' => $toDo->id])
|
|
->assertCreated();
|
|
|
|
$this->get('/api/time-tracker/user')
|
|
->assertOk()
|
|
->assertJson([
|
|
'id' => $toDo->timeTrackers()->value('id'),
|
|
'start_at' => now()->format('Y-m-d H:i:s'),
|
|
'end_at' => null,
|
|
'to_do' => [
|
|
'id' => $toDo->id,
|
|
'user_id' => $user->id,
|
|
'name' => $toDo->name,
|
|
'checked' => false,
|
|
],
|
|
]);
|
|
});
|
|
|
|
test('user has no content response if not current time tracker', function () {
|
|
Sanctum::actingAs($user = User::factory()->create());
|
|
|
|
$this->get('/api/time-tracker/user')
|
|
->assertNoContent();
|
|
});
|
|
|
|
test('user can stop current time tracker', function () {
|
|
Sanctum::actingAs($user = User::factory()->create());
|
|
$toDo = ToDo::factory()->create(['user_id' => $user->id, 'checked' => false]);
|
|
|
|
$this->postJson('/api/time-tracker', ['todo_id' => $toDo->id])
|
|
->assertCreated();
|
|
|
|
$this->delete('/api/time-tracker/user')
|
|
->assertNoContent();
|
|
|
|
expect($toDo->timeTrackers->first())
|
|
->end_at->format('Y-m-d H:i:s')->toBe(now()->format('Y-m-d H:i:s'));
|
|
});
|