diff --git a/api/app/Jobs/Form/StoreFormSubmissionJob.php b/api/app/Jobs/Form/StoreFormSubmissionJob.php index 5326c237..42a7f1ad 100644 --- a/api/app/Jobs/Form/StoreFormSubmissionJob.php +++ b/api/app/Jobs/Form/StoreFormSubmissionJob.php @@ -179,9 +179,9 @@ class StoreFormSubmissionJob implements ShouldQueue } } else { // Standard field processing (text, ID generation, etc.) - if ($field['type'] == 'text' && isset($field['generates_uuid']) && $field['generates_uuid']) { + if ((!$answerValue || !Str::isUuid($answerValue)) && $field['type'] == 'text' && isset($field['generates_uuid']) && $field['generates_uuid']) { $finalData[$field['id']] = ($this->form->is_pro) ? Str::uuid()->toString() : 'Please upgrade your OpenForm subscription to use our ID generation features'; - } elseif ($field['type'] == 'text' && isset($field['generates_auto_increment_id']) && $field['generates_auto_increment_id']) { + } elseif ((!$answerValue || !is_int($answerValue)) && $field['type'] == 'text' && isset($field['generates_auto_increment_id']) && $field['generates_auto_increment_id']) { $finalData[$field['id']] = ($this->form->is_pro) ? (string) ($this->form->submissions_count + 1) : 'Please upgrade your OpenForm subscription to use our ID generation features'; } else { $finalData[$field['id']] = $answerValue; diff --git a/api/tests/Feature/Forms/FormUpdateTest.php b/api/tests/Feature/Forms/FormUpdateTest.php index e4efb476..22fa80e8 100644 --- a/api/tests/Feature/Forms/FormUpdateTest.php +++ b/api/tests/Feature/Forms/FormUpdateTest.php @@ -1,6 +1,6 @@ actingAsProUser(); @@ -39,3 +39,56 @@ it('can update form with existing record', function () { expect($response->json('data.' . $nameProperty['id']))->toBe('Testing Updated'); } }); + +it('can update form with existing record but generates_uuid field is not update', function () { + $user = $this->actingAsProUser(); + $workspace = $this->createUserWorkspace($user); + $form = $this->createForm($user, $workspace, [ + 'editable_submissions' => true, + 'properties' => [ + [ + 'id' => 'uuid_field', + 'type' => 'text', + 'generates_uuid' => true, + 'name' => 'UUID Field' + ], + [ + 'id' => 'name', + 'type' => 'text', + 'name' => 'Name' + ] + ] + ]); + + $response = $this->postJson(route('forms.answer', $form->slug), ['name' => 'Testing', 'uuid_field' => null]) + ->assertSuccessful() + ->assertJson([ + 'type' => 'success', + 'message' => 'Form submission saved.', + ]); + $submissionId = $response->json('submission_id'); + expect($submissionId)->toBeString(); + $response = $this->getJson(route('forms.fetchSubmission', [$form->slug, $submissionId])) + ->assertSuccessful(); + $uuid = $response->json('data.uuid_field'); + expect(Str::isUuid($uuid))->toBeTrue(); + + if ($submissionId) { + $formData = $this->generateFormSubmissionData($form, ['submission_id' => $submissionId, 'name' => 'Testing Updated', 'uuid_field' => $uuid]); + $response = $this->postJson(route('forms.answer', $form->slug), $formData) + ->assertSuccessful() + ->assertJson([ + 'type' => 'success', + 'message' => 'Form submission saved.', + ]); + $submissionId2 = $response->json('submission_id'); + expect($submissionId2)->toBeString(); + expect($submissionId2)->toBe($submissionId); + + $response = $this->getJson(route('forms.fetchSubmission', [$form->slug, $submissionId])) + ->assertSuccessful(); + expect($response->json('data.name'))->toBe('Testing Updated'); + $uuid2 = $response->json('data.uuid_field'); + expect($uuid2)->toBe($uuid); + } +});