add test
This commit is contained in:
@@ -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