test dated assignment listing
This commit is contained in:
parent
66d9c8cbd7
commit
6afe7864be
2 changed files with 275 additions and 0 deletions
|
|
@ -221,6 +221,136 @@ class ScheduleEndpointTest extends TestCase
|
|||
]);
|
||||
}
|
||||
|
||||
public function test_it_lists_the_users_assignments_for_a_date(): void
|
||||
{
|
||||
$user = $this->createUser('reader@example.com');
|
||||
$otherUser = $this->createUser('other@example.com');
|
||||
$olderSet = $this->createSet($user, 'Older course');
|
||||
$olderLevel = $this->createLevel($olderSet, 'lesson');
|
||||
$olderRepository = app(ElementRepository::class);
|
||||
$olderRepository->create(new CreateElementDto(
|
||||
name: 'First lesson',
|
||||
level: $olderLevel,
|
||||
parentElement: null,
|
||||
));
|
||||
$olderRepository->create(new CreateElementDto(
|
||||
name: 'Second lesson',
|
||||
level: $olderLevel,
|
||||
parentElement: null,
|
||||
));
|
||||
$newerSet = $this->createSet($user, 'Newer course');
|
||||
$newerLevel = $this->createLevel($newerSet, 'chapter');
|
||||
app(ElementRepository::class)->create(new CreateElementDto(
|
||||
name: 'Only chapter',
|
||||
level: $newerLevel,
|
||||
parentElement: null,
|
||||
));
|
||||
$this->createSession($user, 'valid-token');
|
||||
$this->createSession($otherUser, 'other-token');
|
||||
|
||||
$this->credentialedPost('/api/schedules', [
|
||||
'setId' => $olderSet->getId(),
|
||||
'levelId' => $olderLevel->getId(),
|
||||
'startDate' => '2026-08-15',
|
||||
'targetDate' => '2026-08-15',
|
||||
])->assertCreated();
|
||||
$this->credentialedPost('/api/schedules', [
|
||||
'setId' => $newerSet->getId(),
|
||||
'levelId' => $newerLevel->getId(),
|
||||
'startDate' => '2026-08-15',
|
||||
'targetDate' => '2026-08-15',
|
||||
])->assertCreated();
|
||||
$this->withCredentials()
|
||||
->withUnencryptedCookie(
|
||||
AuthMiddleware::COOKIE_NAME,
|
||||
'other-token',
|
||||
)->postJson('/api/schedules', [
|
||||
'setId' => $newerSet->getId(),
|
||||
'levelId' => $newerLevel->getId(),
|
||||
'startDate' => '2026-08-15',
|
||||
'targetDate' => '2026-08-15',
|
||||
])->assertCreated();
|
||||
$this->credentialedPost('/api/schedules', [
|
||||
'setId' => $olderSet->getId(),
|
||||
'levelId' => $olderLevel->getId(),
|
||||
'startDate' => '2026-08-16',
|
||||
'targetDate' => '2026-08-16',
|
||||
])->assertCreated();
|
||||
|
||||
$this->credentialedGet('/api/assignments?date=2026-08-15')
|
||||
->assertOk()
|
||||
->assertExactJson([
|
||||
'date' => '2026-08-15',
|
||||
'assignments' => [
|
||||
[
|
||||
'id' => 3,
|
||||
'schedule' => [
|
||||
'id' => 2,
|
||||
'set' => [
|
||||
'name' => 'Newer course',
|
||||
],
|
||||
],
|
||||
'element' => [
|
||||
'name' => 'Only chapter',
|
||||
'kind' => 'chapter',
|
||||
'path' => ['Only chapter'],
|
||||
],
|
||||
],
|
||||
[
|
||||
'id' => 1,
|
||||
'schedule' => [
|
||||
'id' => 1,
|
||||
'set' => [
|
||||
'name' => 'Older course',
|
||||
],
|
||||
],
|
||||
'element' => [
|
||||
'name' => 'First lesson',
|
||||
'kind' => 'lesson',
|
||||
'path' => ['First lesson'],
|
||||
],
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'schedule' => [
|
||||
'id' => 1,
|
||||
'set' => [
|
||||
'name' => 'Older course',
|
||||
],
|
||||
],
|
||||
'element' => [
|
||||
'name' => 'Second lesson',
|
||||
'kind' => 'lesson',
|
||||
'path' => ['Second lesson'],
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_it_returns_an_empty_assignment_list_for_a_date(): void
|
||||
{
|
||||
$user = $this->createUser('reader@example.com');
|
||||
$this->createSession($user, 'valid-token');
|
||||
|
||||
$this->credentialedGet('/api/assignments?date=2026-08-15')
|
||||
->assertOk()
|
||||
->assertExactJson([
|
||||
'date' => '2026-08-15',
|
||||
'assignments' => [],
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_it_rejects_invalid_assignment_dates(): void
|
||||
{
|
||||
$user = $this->createUser('reader@example.com');
|
||||
$this->createSession($user, 'valid-token');
|
||||
|
||||
$this->credentialedGet('/api/assignments')
|
||||
->assertBadRequest()
|
||||
->assertExactJson(['error' => 'date is required']);
|
||||
}
|
||||
|
||||
public function test_it_is_stable_after_sources_change_or_are_deleted(): void
|
||||
{
|
||||
$user = $this->createUser('reader@example.com');
|
||||
|
|
@ -323,6 +453,8 @@ class ScheduleEndpointTest extends TestCase
|
|||
|
||||
public function test_schedule_endpoints_require_authentication(): void
|
||||
{
|
||||
$this->getJson('/api/assignments?date=2026-08-15')
|
||||
->assertStatus(401);
|
||||
$this->getJson('/api/schedules')->assertStatus(401);
|
||||
$this->getJson('/api/schedules/1')->assertStatus(401);
|
||||
$this->postJson('/api/schedules', [])->assertStatus(401);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue