Skip to content

Commit

Permalink
[TM-931] Fix unit test that's covering the updated workdays_paid attr…
Browse files Browse the repository at this point in the history
…ibute getter.
  • Loading branch information
roguenet committed May 17, 2024
1 parent 4b53fa4 commit b797f7e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
30 changes: 19 additions & 11 deletions app/Helpers/CustomFormHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CustomFormHelper
* @param string $framework [ppc,terrafund]
* @return Form
*/
public static function generateFakeForm(string $type, string $framework): Form
public static function generateFakeForm(string $type, string $framework, bool $withRelations = false): Form
{
switch ($type) {
case 'project':
Expand Down Expand Up @@ -59,16 +59,24 @@ public static function generateFakeForm(string $type, string $framework): Form

$form = Form::factory()->create(['framework_key' => $framework, 'model' => $model]);
$section = FormSection::factory()->create(['form_id' => $form->uuid]);
foreach (config('wri.linked-fields.models.' . $type . '.fields') as $key => $fieldCfg) {
FormQuestion::factory()->create(
[
'input_type' => data_get($fieldCfg, 'input_type'),
'label' => data_get($fieldCfg, 'label'),
'name' => data_get($fieldCfg, 'label'),
'form_section_id' => $section->id,
'linked_field_key' => $key,
]
);

$generateQuestions = function ($subtype) use ($type, $section) {
foreach (config("wri.linked-fields.models.$type.$subtype") as $key => $fieldCfg) {
FormQuestion::factory()->create(
[
'input_type' => data_get($fieldCfg, 'input_type'),
'label' => data_get($fieldCfg, 'label'),
'name' => data_get($fieldCfg, 'label'),
'form_section_id' => $section->id,
'linked_field_key' => $key,
]
);
}
};

$generateQuestions('fields');
if ($withRelations) {
$generateQuestions('relations');
}

$conditional = FormQuestion::factory()->conditionalField()->create(['form_section_id' => $section->id]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function test_invoke_action()
'status' => EntityStatusStateMachine::STARTED,
]);

$form = CustomFormHelper::generateFakeForm('project-report', 'ppc');
$form = CustomFormHelper::generateFakeForm('project-report', 'ppc', true);

$answers = [];

Expand All @@ -59,8 +59,24 @@ public function test_invoke_action()
if ($question->linked_field_key == 'pro-rep-title') {
$answers[$question->uuid] = '* testing title updated *';
}
if ($question->linked_field_key == 'pro-rep-workdays-paid') {
$answers[$question->uuid] = 24;
if ($question->linked_field_key == 'pro-rep-rel-paid-project-management') {
$answers[$question->uuid] = [[
'collection' => 'paid-project-management',
'demographics' => [[
'type' => 'gender',
'name' => 'male',
'amount' => 24,
], [
'type' => 'age',
'name' => 'youth',
'amount' => 24,
], [
'type' => 'ethnicity',
'subtype' => 'indigenous',
'name' => 'Ohlone',
'amount' => 24,
]],
]];
}
}

Expand Down

0 comments on commit b797f7e

Please sign in to comment.