Add leader_conditions to backend
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
6c3c8b5703
commit
247a89ae77
|
@ -36,6 +36,7 @@ class FormStoreAction
|
|||
'needs_prevention' => 'present|boolean',
|
||||
'prevention_text' => 'array',
|
||||
'prevention_conditions' => 'array',
|
||||
'leader_conditions' => 'array',
|
||||
'zip' => 'present|nullable|string',
|
||||
'location' => 'present|nullable|string',
|
||||
'country' => 'nullable|string|max:255',
|
||||
|
|
|
@ -38,6 +38,7 @@ class FormUpdateAction
|
|||
'location' => 'present|nullable|string',
|
||||
'zip' => 'present|nullable|string',
|
||||
'country' => 'nullable|string|max:255',
|
||||
'leader_conditions' => 'array',
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ class Form extends Model implements HasMedia
|
|||
'registration_from' => 'datetime',
|
||||
'registration_until' => 'datetime',
|
||||
'country' => Country::class,
|
||||
'leader_condition' => Condition::class,
|
||||
'leader_conditions' => Condition::class,
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
@ -55,6 +55,7 @@ class FormResource extends JsonResource
|
|||
'needs_prevention' => $this->needs_prevention,
|
||||
'prevention_text' => $this->prevention_text,
|
||||
'prevention_conditions' => $this->prevention_conditions,
|
||||
'leader_conditions' => $this->leader_conditions,
|
||||
'zip' => $this->zip,
|
||||
'location' => $this->location,
|
||||
'country' => $this->country,
|
||||
|
|
|
@ -12,7 +12,7 @@ return new class extends Migration
|
|||
public function up(): void
|
||||
{
|
||||
Schema::table('forms', function (Blueprint $table) {
|
||||
$table->json('leader_condition')->after('name')->default(json_encode(['mode' => 'all', 'ifs' => []]));
|
||||
$table->json('leader_conditions')->after('name')->default(json_encode(['mode' => 'all', 'ifs' => []]));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ return new class extends Migration
|
|||
public function down(): void
|
||||
{
|
||||
Schema::table('forms', function (Blueprint $table) {
|
||||
$table->dropColumn('leader_condition');
|
||||
$table->dropColumn('leader_conditions');
|
||||
});
|
||||
}
|
||||
};
|
|
@ -16,6 +16,7 @@ use Tests\RequestFactories\EditorRequestFactory;
|
|||
use Tests\Lib\CreatesFormFields;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Tests\EndToEndTestCase;
|
||||
use Tests\RequestFactories\ConditionRequestFactory;
|
||||
|
||||
uses(CreatesFormFields::class);
|
||||
uses(DatabaseTransactions::class);
|
||||
|
@ -24,6 +25,7 @@ uses(EndToEndTestCase::class);
|
|||
it('testItDisplaysForms', function () {
|
||||
Carbon::setTestNow(Carbon::parse('2023-03-03'));
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
$leaderConditions = ConditionRequestFactory::new()->whenField('f', 'v');
|
||||
$form = Form::factory()
|
||||
->name('lala')
|
||||
->excerpt('fff')
|
||||
|
@ -39,7 +41,7 @@ it('testItDisplaysForms', function () {
|
|||
->zip('12345')
|
||||
->location('SG')
|
||||
->country(Country::CH)
|
||||
->create();
|
||||
->create(['leader_conditions' => $leaderConditions->toData()]);
|
||||
|
||||
sleep(1);
|
||||
$this->get(route('form.index'))
|
||||
|
@ -58,6 +60,7 @@ it('testItDisplaysForms', function () {
|
|||
->assertInertiaPath('data.data.0.location', 'SG')
|
||||
->assertInertiaPath('data.data.0.country', 'Schweiz')
|
||||
->assertInertiaPath('data.data.0.participants_count', 5)
|
||||
->assertInertiaPath('data.data.0.leader_conditions', $leaderConditions->create())
|
||||
->assertInertiaPath('data.data.0.to', '2023-06-07')
|
||||
->assertInertiaPath('data.data.0.is_active', true)
|
||||
->assertInertiaPath('data.data.0.is_private', false)
|
||||
|
|
|
@ -8,6 +8,7 @@ use App\Form\Models\Form;
|
|||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Tests\RequestFactories\EditorRequestFactory;
|
||||
use Tests\Lib\CreatesFormFields;
|
||||
use Tests\RequestFactories\ConditionRequestFactory;
|
||||
|
||||
uses(DatabaseTransactions::class);
|
||||
uses(CreatesFormFields::class);
|
||||
|
@ -170,3 +171,16 @@ it('testItUpdatesPrevention', function () {
|
|||
$this->assertEquals('lorem ipsum', $form->fresh()->prevention_text->blocks[0]['data']['text']);
|
||||
$this->assertEquals(['mode' => 'all', 'ifs' => [['field' => 'vorname', 'value' => 'Max', 'comparator' => 'isEqual']]], $form->fresh()->prevention_conditions->toArray());
|
||||
});
|
||||
|
||||
it('updates leader conditions', function () {
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
$form = Form::factory()->create();
|
||||
$condition = ConditionRequestFactory::new()->whenField('A', 'TT')->create();
|
||||
$payload = FormRequest::new()
|
||||
->preventionText(EditorRequestFactory::new()->text(10, 'lorem ipsum'))
|
||||
->state(['leader_conditions' => ConditionRequestFactory::new()->whenField('A', 'TT')])
|
||||
->create();
|
||||
|
||||
$this->patchJson(route('form.update', ['form' => $form]), $payload);
|
||||
$this->assertEquals($condition, $form->fresh()->leader_conditions->toArray());
|
||||
});
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Tests\RequestFactories;
|
||||
|
||||
use Worksome\RequestFactories\RequestFactory;
|
||||
use App\Lib\Editor\Condition;
|
||||
|
||||
class ConditionRequestFactory extends RequestFactory
|
||||
{
|
||||
|
@ -17,8 +18,12 @@ class ConditionRequestFactory extends RequestFactory
|
|||
public function whenField(string $field, string $value): self {
|
||||
return $this->state([
|
||||
'ifs' => [
|
||||
['field' => $field, 'comparator' => 'isEqual', 'value' => $value]
|
||||
['field' => $field, 'value' => $value, 'comparator' => 'isEqual']
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function toData(): Condition {
|
||||
return Condition::from($this->create());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue