diff --git a/api/app/Rules/IntegrationLogicRule.php b/api/app/Rules/IntegrationLogicRule.php index 6fc67705..be0a1212 100644 --- a/api/app/Rules/IntegrationLogicRule.php +++ b/api/app/Rules/IntegrationLogicRule.php @@ -47,6 +47,14 @@ class IntegrationLogicRule implements DataAwareRule, ValidationRule return; } + $typeField = $condition['value']['property_meta']['type']; + $operator = $condition['value']['operator']; + + // If operator has no format and no expected_type, it means it doesn't need input + if (!isset(FormPropertyLogicRule::getConditionMapping()[$typeField]['comparators'][$operator]['expected_type'])) { + return; + } + if (!isset($condition['value']['value'])) { $this->isConditionCorrect = false; $this->conditionErrors[] = 'missing condition value'; @@ -54,8 +62,6 @@ class IntegrationLogicRule implements DataAwareRule, ValidationRule return; } - $typeField = $condition['value']['property_meta']['type']; - $operator = $condition['value']['operator']; $value = $condition['value']['value']; if (!isset(FormPropertyLogicRule::getConditionMapping()[$typeField])) { diff --git a/api/tests/Feature/Forms/FormIntegrationTest.php b/api/tests/Feature/Forms/FormIntegrationTest.php index 5d191480..34278822 100644 --- a/api/tests/Feature/Forms/FormIntegrationTest.php +++ b/api/tests/Feature/Forms/FormIntegrationTest.php @@ -45,3 +45,58 @@ it('can CRUD form integration', function () { 'message' => 'Form Integration was deleted.' ]); }); + +it('can create form integration with checkbox logic', function () { + $user = $this->actingAsProUser(); + $workspace = $this->createUserWorkspace($user); + $form = $this->createForm($user, $workspace, [ + 'properties' => [ + [ + 'id' => 'checkbox_field', + 'name' => 'Checkbox Field', + 'type' => 'checkbox' + ], + [ + 'id' => 'text_field', + 'name' => 'Text Field', + 'type' => 'text', + ], + ], + ]); + + $data = [ + 'status' => true, + 'integration_id' => 'email', + 'logic' => [ + 'operatorIdentifier' => 'and', + 'children' => [ + [ + 'identifier' => 'checkbox_field', + 'value' => [ + 'operator' => 'is_checked', + 'property_meta' => [ + 'id' => 'checkbox_field', + 'type' => 'checkbox', + ] + ], + ], + ], + ], + 'settings' => [ + 'send_to' => 'test@test.com', + 'sender_name' => 'OpnForm', + 'subject' => 'New form submission with checkbox logic', + 'email_content' => 'Checkbox logic triggered.', + 'include_submission_data' => true, + 'include_hidden_fields_submission_data' => false, + 'reply_to' => null + ] + ]; + + $this->postJson(route('open.forms.integration.create', $form->id), $data) + ->assertSuccessful() + ->assertJson([ + 'type' => 'success', + 'message' => 'Form Integration was created.' + ]); +});