fix tests
This commit is contained in:
@@ -20,7 +20,7 @@ class ToDoFactory extends Factory
|
|||||||
return [
|
return [
|
||||||
'user_id' => User::inRandomOrder()->value('id'),
|
'user_id' => User::inRandomOrder()->value('id'),
|
||||||
'name' => $this->faker->words(1, 4),
|
'name' => $this->faker->words(1, 4),
|
||||||
'checked' => $this->faker->boolean,
|
'checked' => rand(0, 1) ? now() : null,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ const ToDoShow = () => {
|
|||||||
</> : <>
|
</> : <>
|
||||||
<button className="absolute right-5" onClick={handleEditTodoMode}><EditSVG className="w-5"/></button>
|
<button className="absolute right-5" onClick={handleEditTodoMode}><EditSVG className="w-5"/></button>
|
||||||
<h1 className="text-lg font-bold">{toDo?.name}</h1>
|
<h1 className="text-lg font-bold">{toDo?.name}</h1>
|
||||||
<p>Terminé le {toDo?.checked ? (new Date(toDo.checked)).toSmallFrDate() : ''}</p>
|
{toDo?.checked && <p>Terminé le {(new Date(toDo.checked)).toSmallFrDate()}</p>}
|
||||||
<p>{toDo?.description}</p>
|
<p>{toDo?.description}</p>
|
||||||
</>}
|
</>}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ test('user can start a time tracker', function () {
|
|||||||
Sanctum::actingAs($user = User::factory()->create());
|
Sanctum::actingAs($user = User::factory()->create());
|
||||||
$toDo = ToDo::factory()->create(['user_id' => $user->id, 'checked' => false]);
|
$toDo = ToDo::factory()->create(['user_id' => $user->id, 'checked' => false]);
|
||||||
|
|
||||||
$this->postJson('/api/time-tracker', ['todo_id' => $toDo->id])
|
$this->postJson('/api/time-trackers', ['todo_id' => $toDo->id])
|
||||||
->assertCreated()
|
->assertCreated()
|
||||||
->assertJson([
|
->assertJson([
|
||||||
'id' => $toDo->timeTrackers()->value('id'),
|
'id' => $toDo->timeTrackers()->value('id'),
|
||||||
@@ -27,10 +27,10 @@ test('user can retrieve his current timer', function () {
|
|||||||
Sanctum::actingAs($user = User::factory()->create());
|
Sanctum::actingAs($user = User::factory()->create());
|
||||||
$toDo = ToDo::factory()->create(['user_id' => $user->id, 'checked' => false]);
|
$toDo = ToDo::factory()->create(['user_id' => $user->id, 'checked' => false]);
|
||||||
|
|
||||||
$this->postJson('/api/time-tracker', ['todo_id' => $toDo->id])
|
$this->postJson('/api/time-trackers', ['todo_id' => $toDo->id])
|
||||||
->assertCreated();
|
->assertCreated();
|
||||||
|
|
||||||
$this->get('/api/time-tracker/user')
|
$this->get('/api/time-trackers/user')
|
||||||
->assertOk()
|
->assertOk()
|
||||||
->assertJson([
|
->assertJson([
|
||||||
'id' => $toDo->timeTrackers()->value('id'),
|
'id' => $toDo->timeTrackers()->value('id'),
|
||||||
@@ -48,7 +48,7 @@ test('user can retrieve his current timer', function () {
|
|||||||
test('user has no content response if not current time tracker', function () {
|
test('user has no content response if not current time tracker', function () {
|
||||||
Sanctum::actingAs($user = User::factory()->create());
|
Sanctum::actingAs($user = User::factory()->create());
|
||||||
|
|
||||||
$this->get('/api/time-tracker/user')
|
$this->get('/api/time-trackers/user')
|
||||||
->assertNoContent();
|
->assertNoContent();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -56,10 +56,10 @@ test('user can stop current time tracker', function () {
|
|||||||
Sanctum::actingAs($user = User::factory()->create());
|
Sanctum::actingAs($user = User::factory()->create());
|
||||||
$toDo = ToDo::factory()->create(['user_id' => $user->id, 'checked' => false]);
|
$toDo = ToDo::factory()->create(['user_id' => $user->id, 'checked' => false]);
|
||||||
|
|
||||||
$this->postJson('/api/time-tracker', ['todo_id' => $toDo->id])
|
$this->postJson('/api/time-trackers', ['todo_id' => $toDo->id])
|
||||||
->assertCreated();
|
->assertCreated();
|
||||||
|
|
||||||
$this->delete('/api/time-tracker/user')
|
$this->delete('/api/time-trackers/user')
|
||||||
->assertNoContent();
|
->assertNoContent();
|
||||||
|
|
||||||
expect($toDo->timeTrackers->first())
|
expect($toDo->timeTrackers->first())
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ test('an user can retrieve his to dos', function () {
|
|||||||
Sanctum::actingAs($this->user);
|
Sanctum::actingAs($this->user);
|
||||||
ToDo::factory()->count(10)->create([
|
ToDo::factory()->count(10)->create([
|
||||||
'user_id' => $this->user->id,
|
'user_id' => $this->user->id,
|
||||||
'checked' => false,
|
'checked' => null,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$response = $this->get('api/todos');
|
$response = $this->get('api/todos');
|
||||||
@@ -48,6 +48,25 @@ test('an user can retrieve his to dos', function () {
|
|||||||
->assertJson($toDos);
|
->assertJson($toDos);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('an user can retrieve his finished to dos', function () {
|
||||||
|
Sanctum::actingAs($this->user);
|
||||||
|
ToDo::factory()->count(10)->create([
|
||||||
|
'user_id' => $this->user->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response = $this->get('api/todos/finished');
|
||||||
|
|
||||||
|
$toDos = $this->user->toDos()->whereNotNull('checked')->get()->map(fn ($toDo) => [
|
||||||
|
'id' => $toDo->id,
|
||||||
|
'user_id' => $toDo->user_id,
|
||||||
|
'name' => $toDo->name,
|
||||||
|
'checked' => now(),
|
||||||
|
])->toArray();
|
||||||
|
|
||||||
|
$response->assertOk()
|
||||||
|
->assertJson($toDos);
|
||||||
|
});
|
||||||
|
|
||||||
test('an user can retrieve a to do', function () {
|
test('an user can retrieve a to do', function () {
|
||||||
Sanctum::actingAs($this->user);
|
Sanctum::actingAs($this->user);
|
||||||
$toDos = ToDo::factory()->count(10)->create([
|
$toDos = ToDo::factory()->count(10)->create([
|
||||||
|
|||||||
Reference in New Issue
Block a user