|
| 1 | +<?php |
| 2 | + |
| 3 | +use App\Service\Forms\FormSubmissionProcessor; |
| 4 | + |
| 5 | +it('processes synchronously with editable submissions', function () { |
| 6 | + $user = $this->actingAsUser(); |
| 7 | + $workspace = $this->createUserWorkspace($user); |
| 8 | + $form = $this->createForm($user, $workspace, [ |
| 9 | + 'editable_submissions' => true |
| 10 | + ]); |
| 11 | + |
| 12 | + $processor = new FormSubmissionProcessor(); |
| 13 | + expect($processor->shouldProcessSynchronously($form))->toBeTrue(); |
| 14 | +}); |
| 15 | + |
| 16 | +it('processes synchronously with UUID field in redirect URL', function () { |
| 17 | + $user = $this->actingAsUser(); |
| 18 | + $workspace = $this->createUserWorkspace($user); |
| 19 | + $form = $this->createForm($user, $workspace, [ |
| 20 | + 'redirect_url' => 'https://example.com/{field_1}', |
| 21 | + 'properties' => [ |
| 22 | + [ |
| 23 | + 'id' => 'field_1', |
| 24 | + 'type' => 'text', |
| 25 | + 'generates_uuid' => true, |
| 26 | + 'name' => 'UUID Field' |
| 27 | + ] |
| 28 | + ] |
| 29 | + ]); |
| 30 | + |
| 31 | + $processor = new FormSubmissionProcessor(); |
| 32 | + expect($processor->shouldProcessSynchronously($form))->toBeTrue(); |
| 33 | +}); |
| 34 | + |
| 35 | +it('processes synchronously with auto increment field in redirect URL', function () { |
| 36 | + $user = $this->actingAsUser(); |
| 37 | + $workspace = $this->createUserWorkspace($user); |
| 38 | + $form = $this->createForm($user, $workspace, [ |
| 39 | + 'redirect_url' => 'https://example.com/{field_1}', |
| 40 | + 'properties' => [ |
| 41 | + [ |
| 42 | + 'id' => 'field_1', |
| 43 | + 'type' => 'text', |
| 44 | + 'generates_auto_increment_id' => true, |
| 45 | + 'name' => 'Auto Increment Field' |
| 46 | + ] |
| 47 | + ] |
| 48 | + ]); |
| 49 | + |
| 50 | + $processor = new FormSubmissionProcessor(); |
| 51 | + expect($processor->shouldProcessSynchronously($form))->toBeTrue(); |
| 52 | +}); |
| 53 | + |
| 54 | +it('processes asynchronously with no generated fields in redirect URL', function () { |
| 55 | + $user = $this->actingAsUser(); |
| 56 | + $workspace = $this->createUserWorkspace($user); |
| 57 | + $form = $this->createForm($user, $workspace, [ |
| 58 | + 'redirect_url' => 'https://example.com/{field_1}', |
| 59 | + 'properties' => [ |
| 60 | + [ |
| 61 | + 'id' => 'field_1', |
| 62 | + 'type' => 'text', |
| 63 | + 'name' => 'Regular Field' |
| 64 | + ] |
| 65 | + ] |
| 66 | + ]); |
| 67 | + |
| 68 | + $processor = new FormSubmissionProcessor(); |
| 69 | + expect($processor->shouldProcessSynchronously($form))->toBeFalse(); |
| 70 | +}); |
| 71 | + |
| 72 | +it('processes asynchronously when generated field is not used in redirect URL', function () { |
| 73 | + $user = $this->actingAsUser(); |
| 74 | + $workspace = $this->createUserWorkspace($user); |
| 75 | + $form = $this->createForm($user, $workspace, [ |
| 76 | + 'redirect_url' => 'https://example.com/{field_2}', |
| 77 | + 'properties' => [ |
| 78 | + [ |
| 79 | + 'id' => 'field_1', |
| 80 | + 'type' => 'text', |
| 81 | + 'generates_uuid' => true, |
| 82 | + 'name' => 'UUID Field' |
| 83 | + ], |
| 84 | + [ |
| 85 | + 'id' => 'field_2', |
| 86 | + 'type' => 'text', |
| 87 | + 'name' => 'Regular Field' |
| 88 | + ] |
| 89 | + ] |
| 90 | + ]); |
| 91 | + |
| 92 | + $processor = new FormSubmissionProcessor(); |
| 93 | + expect($processor->shouldProcessSynchronously($form))->toBeFalse(); |
| 94 | +}); |
| 95 | + |
| 96 | +it('processes asynchronously with no redirect URL', function () { |
| 97 | + $user = $this->actingAsUser(); |
| 98 | + $workspace = $this->createUserWorkspace($user); |
| 99 | + $form = $this->createForm($user, $workspace, [ |
| 100 | + 'redirect_url' => null, |
| 101 | + 'properties' => [ |
| 102 | + [ |
| 103 | + 'id' => 'field_1', |
| 104 | + 'type' => 'text', |
| 105 | + 'generates_uuid' => true, |
| 106 | + 'name' => 'UUID Field' |
| 107 | + ] |
| 108 | + ] |
| 109 | + ]); |
| 110 | + |
| 111 | + $processor = new FormSubmissionProcessor(); |
| 112 | + expect($processor->shouldProcessSynchronously($form))->toBeFalse(); |
| 113 | +}); |
| 114 | + |
| 115 | +it('formats redirect data correctly for pro users', function () { |
| 116 | + $user = $this->actingAsProUser(); |
| 117 | + $workspace = $this->createUserWorkspace($user); |
| 118 | + $form = $this->createForm($user, $workspace, [ |
| 119 | + 'redirect_url' => 'https://example.com/<span mention mention-field-id="field_1"></span>' |
| 120 | + ]); |
| 121 | + |
| 122 | + $processor = new FormSubmissionProcessor(); |
| 123 | + $redirectData = $processor->getRedirectData($form, [ |
| 124 | + 'field_1' => [ |
| 125 | + 'id' => 'field_1', |
| 126 | + 'value' => 'test-value' |
| 127 | + ] |
| 128 | + ]); |
| 129 | + |
| 130 | + expect($redirectData)->toBe([ |
| 131 | + 'redirect' => true, |
| 132 | + 'redirect_url' => 'https://example.com/test-value' |
| 133 | + ]); |
| 134 | +}); |
| 135 | + |
| 136 | +it('returns no redirect for non-pro users', function () { |
| 137 | + $user = $this->actingAsUser(); |
| 138 | + $workspace = $this->createUserWorkspace($user); |
| 139 | + $form = $this->createForm($user, $workspace, [ |
| 140 | + 'redirect_url' => 'https://example.com/<span mention mention-field-id="field_1"></span>' |
| 141 | + ]); |
| 142 | + |
| 143 | + $processor = new FormSubmissionProcessor(); |
| 144 | + $redirectData = $processor->getRedirectData($form, [ |
| 145 | + 'field_1' => [ |
| 146 | + 'id' => 'field_1', |
| 147 | + 'value' => 'test-value' |
| 148 | + ] |
| 149 | + ]); |
| 150 | + |
| 151 | + expect($redirectData)->toBe([ |
| 152 | + 'redirect' => false |
| 153 | + ]); |
| 154 | +}); |
0 commit comments