Allow Q&A rounds without upvotes and limit upvotes per question
- max_upvotes = 0 disables upvoting: the voting stage is skipped (collect -> discuss), questions are discussed in submission order - new setting max_upvotes_per_question caps a participant's upvotes on a single question (0 = no limit besides max_upvotes) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3e44ded107
commit
bc86ec2db6
16 files changed
+235
-38
No files matched your search
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
namespace App\Test\TestCase\Controller;
|
||||
|
||||
use App\Model\Entity\Slide;
|
||||
use App\Service\QaService;
|
||||
use App\Service\VoteService;
|
||||
use App\Test\TestCase\PlenarioTestTrait;
|
||||
use Cake\TestSuite\IntegrationTestTrait;
|
||||
@@ -79,6 +80,38 @@ class QaSlideTest extends TestCase
|
||||
$this->assertResponseContains('max. 5 Upvotes pro Person');
|
||||
}
|
||||
|
||||
public function testSwitchingOffUpvotesSkipsTheVotingStage(): void
|
||||
{
|
||||
[$poll, $token] = $this->createPoll();
|
||||
$slide = $this->createSlide($poll, Slide::TYPE_QA, ['settings' => ['max_upvotes' => 2]]);
|
||||
$this->goLive($poll, $slide);
|
||||
(new QaService())->setStage($slide, Slide::QA_VOTE);
|
||||
|
||||
$this->get("/admin/$token/slides/{$slide->id}/edit");
|
||||
$this->assertResponseContains('keine – ohne Abstimmung');
|
||||
$this->assertResponseContains('Höchstens pro Frage');
|
||||
|
||||
// Switched off while voting: the round continues with the discussion.
|
||||
$this->post("/admin/$token/slides/{$slide->id}/edit", [
|
||||
'question' => $slide->question,
|
||||
'settings' => ['max_upvotes' => '0', 'max_upvotes_per_question' => '0'],
|
||||
]);
|
||||
$this->assertRedirect();
|
||||
$slide = $this->slidesTable()->get($slide->id);
|
||||
$this->assertSame([0, Slide::QA_DISCUSS, false], [$slide->setting('max_upvotes'), $slide->qaStage(), $slide->is_voting_open]);
|
||||
|
||||
$this->get("/admin/$token");
|
||||
$this->assertResponseContains('ohne Upvotes');
|
||||
|
||||
// Back to collecting, V goes straight to discussing; "vote" is rejected.
|
||||
$state = $this->control($token, ['action' => 'stage', 'stage' => 'collect']);
|
||||
$this->assertSame(['collect', 'discuss'], $state['results']['stages']);
|
||||
$state = $this->control($token, ['action' => 'toggle']);
|
||||
$this->assertSame('discuss', $state['results']['stage']);
|
||||
$this->post("/admin/$token/control", ['action' => 'stage', 'stage' => 'vote']);
|
||||
$this->assertResponseCode(400);
|
||||
}
|
||||
|
||||
public function testFullRoundTrip(): void
|
||||
{
|
||||
[$poll, $token] = $this->createPoll();
|
||||
|
||||
@@ -12,6 +12,7 @@ use App\Service\VoteException;
|
||||
use App\Service\VoteService;
|
||||
use App\Test\TestCase\PlenarioTestTrait;
|
||||
use Cake\TestSuite\TestCase;
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Q&A slides: collect questions, upvote, discuss one by one.
|
||||
@@ -76,8 +77,73 @@ class QaTest extends TestCase
|
||||
$this->assertSame(Slide::QA_COLLECT, $slide->qaStage());
|
||||
|
||||
$table = $this->slidesTable();
|
||||
$this->assertSame(1, $table->patchEntity($slide, ['type' => 'qa', 'settings' => ['max_upvotes' => '0']])->setting('max_upvotes'));
|
||||
$this->assertSame(0, $table->patchEntity($slide, ['type' => 'qa', 'settings' => ['max_upvotes' => '0']])->setting('max_upvotes'));
|
||||
$this->assertSame(0, $table->patchEntity($slide, ['type' => 'qa', 'settings' => ['max_upvotes' => '-3']])->setting('max_upvotes'));
|
||||
$this->assertSame(10, $table->patchEntity($slide, ['type' => 'qa', 'settings' => ['max_upvotes' => '99']])->setting('max_upvotes'));
|
||||
|
||||
$this->assertSame(0, $slide->setting('max_upvotes_per_question'));
|
||||
$patched = $table->patchEntity($slide, ['type' => 'qa', 'settings' => ['max_upvotes' => '5', 'max_upvotes_per_question' => '2']]);
|
||||
$this->assertSame([2, 2], [$patched->setting('max_upvotes_per_question'), $patched->qaUpvotesPerQuestion()]);
|
||||
$patched = $table->patchEntity($slide, ['type' => 'qa', 'settings' => ['max_upvotes' => '3', 'max_upvotes_per_question' => '99']]);
|
||||
// Never more per question than in total.
|
||||
$this->assertSame([10, 3], [$patched->setting('max_upvotes_per_question'), $patched->qaUpvotesPerQuestion()]);
|
||||
$patched = $table->patchEntity($slide, ['type' => 'qa', 'settings' => ['max_upvotes' => '4', 'max_upvotes_per_question' => '0']]);
|
||||
$this->assertSame(4, $patched->qaUpvotesPerQuestion(), '0 = no limit per question');
|
||||
}
|
||||
|
||||
public function testWithoutUpvotesThereIsNoVotingStage(): void
|
||||
{
|
||||
[$poll, $slide] = $this->createQa(0);
|
||||
$this->assertFalse($slide->hasQaUpvotes());
|
||||
$this->assertSame([Slide::QA_COLLECT, Slide::QA_DISCUSS], $slide->qaStages());
|
||||
$first = $this->ask($poll, $slide, 'p1', 'Frage A');
|
||||
$this->ask($poll, $slide, 'p2', 'Frage B');
|
||||
$this->assertVoteFails('Bei dieser Fragerunde wird nicht abgestimmt.', fn() => $this->vote($poll, $slide, 'p2', $first));
|
||||
|
||||
$qa = new QaService();
|
||||
try {
|
||||
$qa->setStage($slide, Slide::QA_VOTE);
|
||||
$this->fail('No voting stage expected');
|
||||
} catch (InvalidArgumentException) {
|
||||
}
|
||||
|
||||
// collect → discuss, in submission order.
|
||||
$this->assertTrue($qa->advance($slide));
|
||||
$slide = $this->slidesTable()->get($slide->id);
|
||||
$this->assertSame([Slide::QA_DISCUSS, $first, false], [$slide->qaStage(), $slide->focus_response_id, $slide->is_voting_open]);
|
||||
$this->assertFalse($qa->advance($slide));
|
||||
|
||||
$results = (new ResultsService())->forSlide($slide);
|
||||
$this->assertSame([['collect', 'discuss'], 0], [$results['stages'], $results['maxUpvotes']]);
|
||||
$this->assertSame(['Frage A', 'Frage B'], array_column($results['questions'], 'text'));
|
||||
$this->assertSame(0, (new PollStateService())->forParticipant($poll, 'p1')['qa']['maxUpvotes']);
|
||||
}
|
||||
|
||||
public function testUpvotesPerQuestionAreLimited(): void
|
||||
{
|
||||
[$poll] = $this->createPoll();
|
||||
$slide = $this->createSlide($poll, Slide::TYPE_QA, ['settings' => ['max_upvotes' => 3, 'max_upvotes_per_question' => 1]]);
|
||||
$poll = $this->goLive($poll, $slide);
|
||||
$a = $this->ask($poll, $slide, 'p1', 'Frage A');
|
||||
$b = $this->ask($poll, $slide, 'p1', 'Frage B');
|
||||
$slide = $this->stage($slide, Slide::QA_VOTE);
|
||||
|
||||
$this->vote($poll, $slide, 'p2', $a);
|
||||
$this->assertVoteFails('Du kannst jeder Frage nur eine Stimme geben.', fn() => $this->vote($poll, $slide, 'p2', $a));
|
||||
$this->vote($poll, $slide, 'p2', $b);
|
||||
// Withdrawing frees the question again.
|
||||
$this->vote($poll, $slide, 'p2', $a, 'remove');
|
||||
$this->vote($poll, $slide, 'p2', $a);
|
||||
|
||||
$state = (new PollStateService())->forParticipant($poll, 'p2')['qa'];
|
||||
$this->assertEquals([1, 1, [$a => 1, $b => 1]], [$state['maxPerQuestion'], $state['votesLeft'], $state['upvoted']]);
|
||||
|
||||
$this->slidesTable()->patchEntity($slide, ['type' => 'qa', 'settings' => ['max_upvotes' => 3, 'max_upvotes_per_question' => 2]]);
|
||||
$this->slidesTable()->saveOrFail($slide);
|
||||
$this->vote($poll, $slide, 'p2', $a);
|
||||
$this->vote($poll, $slide, 'p3', $b);
|
||||
$this->vote($poll, $slide, 'p3', $b);
|
||||
$this->assertVoteFails('Du kannst jeder Frage höchstens 2 Stimmen geben.', fn() => $this->vote($poll, $slide, 'p3', $b));
|
||||
}
|
||||
|
||||
public function testCollectQuestionsSeveralPerParticipantWithoutDuplicates(): void
|
||||
|
||||
Reference in new issue
Block a user