test schedule rescheduling
This commit is contained in:
parent
a06bb6f003
commit
258e4ea27a
2 changed files with 338 additions and 0 deletions
|
|
@ -558,6 +558,125 @@ class ScheduleEndpointTest extends TestCase
|
|||
->assertJsonCount(2, 'assignments');
|
||||
}
|
||||
|
||||
public function test_it_reschedules_only_unfinished_assignments(): void
|
||||
{
|
||||
$user = $this->createUser('reader@example.com');
|
||||
$set = $this->createSet($user, 'Course');
|
||||
$lessonLevel = $this->createLevel($set, 'lesson');
|
||||
$repository = app(ElementRepository::class);
|
||||
foreach (range(1, 4) as $number) {
|
||||
$repository->create(new CreateElementDto(
|
||||
name: "Lesson {$number}",
|
||||
level: $lessonLevel,
|
||||
parentElement: null,
|
||||
));
|
||||
}
|
||||
$this->createSession($user, 'valid-token');
|
||||
$completedAt = new DateTimeImmutable(
|
||||
'2026-08-15T12:30:45',
|
||||
new DateTimeZone('UTC'),
|
||||
);
|
||||
$this->app->instance(Clock::class, new FakeClock($completedAt));
|
||||
$this->credentialedPost('/api/schedules', [
|
||||
'setId' => $set->getId(),
|
||||
'levelId' => $lessonLevel->getId(),
|
||||
'startDate' => '2026-08-10',
|
||||
'targetDate' => '2026-08-13',
|
||||
])->assertCreated();
|
||||
$this->credentialedPatch('/api/assignments/1', [
|
||||
'completed' => true,
|
||||
])->assertOk();
|
||||
|
||||
$response = $this->credentialedPatch('/api/schedules/1', [
|
||||
'startDate' => '2026-08-20',
|
||||
'targetDate' => '2026-08-21',
|
||||
'workloadPlacement' => 'end',
|
||||
]);
|
||||
|
||||
$response->assertOk()
|
||||
->assertJsonPath('schedule.startDate', '2026-08-20')
|
||||
->assertJsonPath('schedule.targetDate', '2026-08-21')
|
||||
->assertJsonPath('schedule.days.0.date', '2026-08-10')
|
||||
->assertJsonPath(
|
||||
'schedule.days.0.assignments.0.completedAt',
|
||||
'2026-08-15T12:30:45+00:00',
|
||||
)
|
||||
->assertJsonPath('schedule.days.1.date', '2026-08-20')
|
||||
->assertJsonCount(1, 'schedule.days.1.assignments')
|
||||
->assertJsonPath('schedule.days.1.assignments.0.id', 2)
|
||||
->assertJsonPath('schedule.days.2.date', '2026-08-21')
|
||||
->assertJsonCount(2, 'schedule.days.2.assignments')
|
||||
->assertJsonPath('schedule.days.2.assignments.0.id', 3)
|
||||
->assertJsonPath('schedule.days.2.assignments.1.id', 4);
|
||||
$this->assertDatabaseHas('schedules', [
|
||||
'id' => 1,
|
||||
'start_date' => '2026-08-20',
|
||||
'target_date' => '2026-08-21',
|
||||
]);
|
||||
$this->assertDatabaseHas('schedule_assignments', [
|
||||
'id' => 1,
|
||||
'scheduled_date' => '2026-08-10',
|
||||
'completed_at' => '2026-08-15 12:30:45',
|
||||
]);
|
||||
$this->assertDatabaseHas('schedule_assignments', [
|
||||
'id' => 2,
|
||||
'scheduled_date' => '2026-08-20',
|
||||
'completed_at' => null,
|
||||
]);
|
||||
$this->assertDatabaseHas('schedule_assignments', [
|
||||
'id' => 3,
|
||||
'scheduled_date' => '2026-08-21',
|
||||
'completed_at' => null,
|
||||
]);
|
||||
$this->assertDatabaseHas('schedule_assignments', [
|
||||
'id' => 4,
|
||||
'scheduled_date' => '2026-08-21',
|
||||
'completed_at' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_it_hides_another_users_schedule_when_rescheduling(): void
|
||||
{
|
||||
$owner = $this->createUser('owner@example.com');
|
||||
$viewer = $this->createUser('viewer@example.com');
|
||||
$set = $this->createSet($owner, 'Course');
|
||||
$lessonLevel = $this->createLevel($set, 'lesson');
|
||||
app(ElementRepository::class)->create(new CreateElementDto(
|
||||
name: 'Welcome',
|
||||
level: $lessonLevel,
|
||||
parentElement: null,
|
||||
));
|
||||
$this->createSession($owner, 'owner-token');
|
||||
$this->createSession($viewer, 'viewer-token');
|
||||
$this->withCredentials()
|
||||
->withUnencryptedCookie(
|
||||
AuthMiddleware::COOKIE_NAME,
|
||||
'owner-token',
|
||||
)->postJson('/api/schedules', [
|
||||
'setId' => $set->getId(),
|
||||
'levelId' => $lessonLevel->getId(),
|
||||
'startDate' => '2026-08-10',
|
||||
'targetDate' => '2026-08-10',
|
||||
])->assertCreated();
|
||||
|
||||
$this->withCredentials()
|
||||
->withUnencryptedCookie(
|
||||
AuthMiddleware::COOKIE_NAME,
|
||||
'viewer-token',
|
||||
)->patchJson('/api/schedules/1', [
|
||||
'startDate' => '2026-08-20',
|
||||
'targetDate' => '2026-08-21',
|
||||
'workloadPlacement' => 'middle',
|
||||
])->assertNotFound()->assertExactJson([
|
||||
'error' => 'schedule not found',
|
||||
]);
|
||||
$this->assertDatabaseHas('schedules', [
|
||||
'id' => 1,
|
||||
'start_date' => '2026-08-10',
|
||||
'target_date' => '2026-08-10',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_it_rejects_invalid_assignment_completion_input(): void
|
||||
{
|
||||
$user = $this->createUser('reader@example.com');
|
||||
|
|
@ -718,6 +837,7 @@ class ScheduleEndpointTest extends TestCase
|
|||
])->assertStatus(401);
|
||||
$this->getJson('/api/schedules')->assertStatus(401);
|
||||
$this->getJson('/api/schedules/1')->assertStatus(401);
|
||||
$this->patchJson('/api/schedules/1', [])->assertStatus(401);
|
||||
$this->postJson('/api/schedules', [])->assertStatus(401);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue