|
303 | 303 | $this->assertEquals(sizeof($errors), 1);
|
304 | 304 | $response->assertStatus(422);
|
305 | 305 | });
|
| 306 | + |
| 307 | + |
| 308 | +it('executes custom validation before required field validation', function () { |
| 309 | + $user = $this->actingAsUser(); |
| 310 | + $workspace = $this->createUserWorkspace($user); |
| 311 | + $form = $this->createForm($user, $workspace); |
| 312 | + |
| 313 | + $emailField = collect($form->properties)->where('name', 'Email')->first(); |
| 314 | + $condition = [ |
| 315 | + 'actions' => [], |
| 316 | + 'conditions' => [ |
| 317 | + 'operatorIdentifier' => 'and', |
| 318 | + 'children' => [ |
| 319 | + [ |
| 320 | + 'identifier' => $emailField['id'], |
| 321 | + 'value' => [ |
| 322 | + 'operator' => 'contains', |
| 323 | + 'property_meta' => [ |
| 324 | + 'id' => $emailField['id'], |
| 325 | + 'type' => 'email', |
| 326 | + ], |
| 327 | + 'value' => '@company.com', |
| 328 | + ], |
| 329 | + ], |
| 330 | + ], |
| 331 | + ], |
| 332 | + ]; |
| 333 | + |
| 334 | + $submissionData = []; |
| 335 | + $validationMessage = 'Must use company email'; |
| 336 | + $form->properties = collect($form->properties)->map(function ($property) use (&$submissionData, &$condition, &$validationMessage, $emailField) { |
| 337 | + if (in_array($property['name'], ['Name'])) { |
| 338 | + $property['required'] = true; |
| 339 | + $property['validation'] = ['error_conditions' => $condition, 'error_message' => $validationMessage]; |
| 340 | + $submissionData[$emailField['id']] = 'test@other.com'; |
| 341 | + } |
| 342 | + return $property; |
| 343 | + })->toArray(); |
| 344 | + $form->update(); |
| 345 | + |
| 346 | + $formData = FormSubmissionDataFactory::generateSubmissionData($form, $submissionData); |
| 347 | + |
| 348 | + $this->postJson(route('forms.answer', $form->slug), $formData) |
| 349 | + ->assertStatus(422) |
| 350 | + ->assertJson([ |
| 351 | + 'message' => $validationMessage, |
| 352 | + ]); |
| 353 | +}); |
0 commit comments