work in progress: predefinedmutations
This commit is contained in:
@@ -172,3 +172,39 @@ test('creating a mutation with less than -1000 points fails validation', functio
|
||||
$response->assertSessionHasErrors(['amount']);
|
||||
expect(Mutation::where('description', 'Abusive negative point demerit')->exists())->toBeFalse();
|
||||
});
|
||||
|
||||
test('participant can choose and request a predefined mutation', function () {
|
||||
$owner = User::factory()->create();
|
||||
$participant = User::factory()->create();
|
||||
$dynamic = Dynamic::factory()->create();
|
||||
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
|
||||
$dynamic->participants()->attach($participant->id, ['role' => 'participant']);
|
||||
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id, 'score' => 100]);
|
||||
|
||||
$predefined = \App\Models\PredefinedMutation::create([
|
||||
'ledger_id' => $ledger->id,
|
||||
'name' => 'Wash the Motorbunny',
|
||||
'amount' => 50,
|
||||
'description' => 'Must be fully cleaned and dried.',
|
||||
]);
|
||||
|
||||
$this->actingAs($participant);
|
||||
|
||||
$response = $this->post(route('dynamics.ledgers.mutations.store', [$dynamic, $ledger]), [
|
||||
'amount' => 50,
|
||||
'description' => 'Completed Wash the Motorbunny template chore.',
|
||||
'predefined_mutation_id' => $predefined->uuid,
|
||||
]);
|
||||
|
||||
$response->assertRedirect(route('dynamics.ledgers.show', [$dynamic, $ledger]));
|
||||
|
||||
$mutation = Mutation::firstWhere('description', 'Completed Wash the Motorbunny template chore.');
|
||||
|
||||
expect($mutation)->not->toBeNull();
|
||||
expect($mutation->status)->toBe('pending');
|
||||
expect($mutation->predefined_mutation_id)->toBe($predefined->id);
|
||||
|
||||
// Score should NOT be updated since it is pending!
|
||||
$ledger->refresh();
|
||||
expect($ledger->score)->toBe(100);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user