Skip to content

Commit

Permalink
add is_required field to form blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilReinking committed Oct 15, 2022
1 parent 97aee99 commit 6d8c51c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/Http/Requests/FormBlockUpdateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function rules()
'webhook_url' => 'url|nullable',
'options' => 'array|nullable',
'title' => 'string|nullable',
'is_required' => 'boolean|nullable',
'type' => [new Enum(FormBlockType::class)]
];
}
Expand Down
5 changes: 2 additions & 3 deletions app/Models/FormBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ class FormBlock extends Model
protected $with = ['formBlockInteractions'];

protected $casts = [
'responses' => 'array',
'is_skippable' => 'boolean',
'is_child' => 'boolean',
'has_parent_interaction' => 'boolean',
'is_required' => 'boolean',
'form_id' => 'integer',
'options' => 'array',
'type' => FormBlockType::class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('form_blocks', function (Blueprint $table) {
$table->boolean('is_required')
->default(false)
->nullable()
->after('uuid');
});
}
};
16 changes: 16 additions & 0 deletions tests/Feature/Forms/BlockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,22 @@ public function can_remove_a_title_for_the_results_view()
$this->assertNull($block->fresh()->title);
}

/** @test */
public function can_make_a_block_required_for_form_user()
{
$block = FormBlock::factory()->create();

$this->actingAs($block->form->user)
->json('POST', route('api.blocks.update', $block->id), ['is_required' => true]);

$this->assertTrue($block->fresh()->is_required);

$this->actingAs($block->form->user)
->json('POST', route('api.blocks.update', $block->id), ['is_required' => false]);

$this->assertFalse($block->fresh()->is_required);
}

/** @test */
public function can_save_information_in_an_options_field()
{
Expand Down

0 comments on commit 6d8c51c

Please sign in to comment.