Skip to content

Commit

Permalink
bugfix: allow posting empty aggregates in order to clear all
Browse files Browse the repository at this point in the history
  • Loading branch information
rtrzebinski committed Oct 5, 2019
1 parent fd16884 commit 3960561
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/Http/Requests/SyncLessonAggregateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function authorize()
public function rules()
{
return [
'aggregates' => 'required|array',
'aggregates' => 'array',
];
}
}
25 changes: 24 additions & 1 deletion tests/Http/Controllers/Web/LessonAggregateControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,25 @@ public function itShould_syncLessonAggregate()
$this->assertEquals($anotherLesson->id, $parentLesson->childLessons[0]->id);
}

/** @test */
public function itShould_syncLessonAggregate_clearAll()
{
$user = $this->createUser();
$this->be($user);

$parentLesson = $this->createPrivateLesson($user);
$childLesson = $this->createPrivateLesson($user);
$parentLesson->childLessons()->attach($childLesson);

$this->expectsEvents(LessonAggregatesUpdated::class);

$this->call('POST', '/lessons/aggregate/'.$parentLesson->id);
$this->assertResponseRedirectedTo('/lessons/aggregate/'.$parentLesson->id);

$parentLesson = $parentLesson->fresh();
$this->assertCount(0, $parentLesson->childLessons);
}

/** @test */
public function itShould_notSyncLessonAggregate_unauthorized()
{
Expand All @@ -95,7 +114,11 @@ public function itShould_notSyncLessonAggregate_invalidInput()

$parentLesson = $this->createPrivateLesson($user);

$this->call('POST', '/lessons/aggregate/'.$parentLesson->id);
$data = [
'aggregates' => uniqid(), // should be an array
];

$this->call('POST', '/lessons/aggregate/'.$parentLesson->id, $data);

$this->assertResponseInvalidInput();
}
Expand Down

0 comments on commit 3960561

Please sign in to comment.