add test
This commit is contained in:
@@ -53,7 +53,7 @@ class TimeTrackerController extends Controller
|
||||
*/
|
||||
public function show(TimeTracker $timeTracker)
|
||||
{
|
||||
//
|
||||
return response()->json(new TimeTrackerResource($timeTracker->load('toDo')));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,7 +19,7 @@ class ToDoResource extends JsonResource
|
||||
'user_id' => $this->user_id,
|
||||
'name' => $this->name,
|
||||
'description' => $this->description,
|
||||
'checked' => $this->checked,
|
||||
'checked' => $this->checked?->format('Y-m-d H:i:s'),
|
||||
'duration' => $this->duration,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -17,6 +17,10 @@ class ToDo extends Model
|
||||
'description',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'checked' => 'datetime',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
|
||||
@@ -54,6 +54,27 @@ test('user has no content response if not current time tracker', function () {
|
||||
->assertNoContent();
|
||||
});
|
||||
|
||||
test('user can retrieve a time tracker', function () {
|
||||
Sanctum::actingAs($user = User::factory()->create());
|
||||
$toDo = ToDo::factory()->create(['user_id' => $user->id, 'checked' => null]);
|
||||
$timeTracker = $toDo->timeTrackers()->create([
|
||||
'start_at' => now()->subMinutes(20),
|
||||
'end_at' => now()->subMinutes(10),
|
||||
]);
|
||||
|
||||
$this->get('/api/time-trackers/'.$timeTracker->id)
|
||||
->assertOk()
|
||||
->assertJson([
|
||||
'id' => $timeTracker->id,
|
||||
'start_at' => now()->subMinutes(20),
|
||||
'end_at' => now()->subMinutes(10),
|
||||
'to_do' => [
|
||||
'id' => $toDo->id,
|
||||
'user_id' => $user->id,
|
||||
],
|
||||
]);
|
||||
});
|
||||
|
||||
test('user can stop current time tracker', function () {
|
||||
Sanctum::actingAs($user = User::factory()->create());
|
||||
$toDo = ToDo::factory()->create(['user_id' => $user->id, 'checked' => null]);
|
||||
@@ -115,3 +136,18 @@ test('user can update a time tracker', function () {
|
||||
|
||||
expect($toDo->refresh())->duration->toBe(660);
|
||||
});
|
||||
|
||||
test('user can retrieve time trackers of a todo', function () {
|
||||
Sanctum::actingAs($user = User::factory()->create());
|
||||
$toDo = ToDo::factory()->create(['user_id' => $user->id, 'duration' => 600, 'checked' => null]);
|
||||
for ($i = 10; $i > 0; $i--) {
|
||||
$toDo->timeTrackers()->create([
|
||||
'start_at' => now()->subMinutes(20 + $i * 10),
|
||||
'end_at' => now()->subMinutes(10 + $i * 10),
|
||||
]);
|
||||
}
|
||||
|
||||
$this->get("/api/todos/{$toDo->id}/time-trackers")
|
||||
->assertOk()
|
||||
->assertJsonCount(10);
|
||||
});
|
||||
|
||||
@@ -96,9 +96,8 @@ test('an user can update a to do', function () {
|
||||
|
||||
$toDo = $toDos[rand(0, 9)];
|
||||
|
||||
$response = $this->put('api/todos/'.$toDo->id, ['name' => 'update test']);
|
||||
|
||||
$response->assertOk()
|
||||
$this->put('api/todos/'.$toDo->id, ['name' => 'update test'])
|
||||
->assertOk()
|
||||
->assertJson([
|
||||
'id' => $toDo->id,
|
||||
'user_id' => $toDo->user_id,
|
||||
@@ -108,6 +107,15 @@ test('an user can update a to do', function () {
|
||||
|
||||
expect(ToDo::find($toDo->id))
|
||||
->name->toBe('update test');
|
||||
|
||||
$this->put('api/todos/'.$toDo->id, ['checked' => true])
|
||||
->assertOk()
|
||||
->assertJson([
|
||||
'id' => $toDo->id,
|
||||
'user_id' => $toDo->user_id,
|
||||
'name' => 'update test',
|
||||
'checked' => now()->format('Y-m-d H:i:s'),
|
||||
]);
|
||||
});
|
||||
|
||||
test('an user can delete a to do', function () {
|
||||
|
||||
Reference in New Issue
Block a user