The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
fix(rest-api): prevent silent pagination failures and include valid options in enum validation errors (#20092)
Ratish jain3290bf3ab14a
diff --git a/packages/twenty-server/src/engine/api/common/common-args-processors/data-arg-processor/__tests__/__snapshots__/data-arg-processor.service.spec.ts.snap b/packages/twenty-server/src/engine/api/common/common-args-processors/data-arg-processor/__tests__/__snapshots__/data-arg-processor.service.spec.ts.snapindex e865efde4fc..94f262899c2 100644--- a/packages/twenty-server/src/engine/api/common/common-args-processors/data-arg-processor/__tests__/__snapshots__/data-arg-processor.service.spec.ts.snap+++ b/packages/twenty-server/src/engine/api/common/common-args-processors/data-arg-processor/__tests__/__snapshots__/data-arg-processor.service.spec.ts.snap@@ -150,7 +150,7 @@ exports[`DataArgProcessorService failing inputs validation POSITION should throwexports[`DataArgProcessorService failing inputs validation POSITION should throw for invalid input #4: [] 1`] = `"Invalid position value [] for field "position""`;-exports[`DataArgProcessorService failing inputs validation RATING should throw for invalid input #1: "not-a-rating" 1`] = `"Invalid value 'not-a-rating' for field "ratingField""`;+exports[`DataArgProcessorService failing inputs validation RATING should throw for invalid input #1: "not-a-rating" 1`] = `"Invalid value "not-a-rating" for field "ratingField". Valid values are: RATING_1, RATING_2, RATING_3, RATING_4, RATING_5"`;exports[`DataArgProcessorService failing inputs validation RATING should throw for invalid input #2: {} 1`] = `"Invalid string value {} for text field "ratingField""`;@@ -178,7 +178,7 @@ exports[`DataArgProcessorService failing inputs validation RICH_TEXT should throexports[`DataArgProcessorService failing inputs validation RICH_TEXT should throw for invalid input #3: true 1`] = `"Invalid object value true for field "richTextField""`;-exports[`DataArgProcessorService failing inputs validation SELECT should throw for invalid input #1: "not-a-select-option" 1`] = `"Invalid value 'not-a-select-option' for field "selectField""`;+exports[`DataArgProcessorService failing inputs validation SELECT should throw for invalid input #1: "not-a-select-option" 1`] = `"Invalid value "not-a-select-option" for field "selectField". Valid values are: OPTION_1, OPTION_2"`;exports[`DataArgProcessorService failing inputs validation SELECT should throw for invalid input #2: {} 1`] = `"Invalid string value {} for text field "selectField""`;diff --git a/packages/twenty-server/src/engine/api/common/common-args-processors/data-arg-processor/validator-utils/__tests__/validate-rating-and-select-field-or-throw.util.spec.ts b/packages/twenty-server/src/engine/api/common/common-args-processors/data-arg-processor/validator-utils/__tests__/validate-rating-and-select-field-or-throw.util.spec.tsindex cab559bb3fa..e8af93b7873 100644--- a/packages/twenty-server/src/engine/api/common/common-args-processors/data-arg-processor/validator-utils/__tests__/validate-rating-and-select-field-or-throw.util.spec.ts+++ b/packages/twenty-server/src/engine/api/common/common-args-processors/data-arg-processor/validator-utils/__tests__/validate-rating-and-select-field-or-throw.util.spec.ts@@ -32,14 +32,16 @@ describe('validateRatingAndSelectFieldOrThrow', () => {).toThrow('Invalid options for field "testField"');});- it('should throw when value is not in the options list', () => {+ it('should throw when value is not in the options list and include valid options in error', () => {expect(() =>validateRatingAndSelectFieldOrThrow('invalidOption','testField',validOptions,),- ).toThrow('Invalid value \'invalidOption\' for field "testField"');+ ).toThrow(+ 'Invalid value "invalidOption" for field "testField". Valid values are: option1, option2, option3',+ );});it('should throw when value is a number', () => {diff --git a/packages/twenty-server/src/engine/api/common/common-args-processors/data-arg-processor/validator-utils/validate-rating-and-select-field-or-throw.util.ts b/packages/twenty-server/src/engine/api/common/common-args-processors/data-arg-processor/validator-utils/validate-rating-and-select-field-or-throw.util.tsindex 7cd74de99d7..dbbae7ced70 100644--- a/packages/twenty-server/src/engine/api/common/common-args-processors/data-arg-processor/validator-utils/validate-rating-and-select-field-or-throw.util.ts+++ b/packages/twenty-server/src/engine/api/common/common-args-processors/data-arg-processor/validator-utils/validate-rating-and-select-field-or-throw.util.ts@@ -1,5 +1,3 @@-import { inspect } from 'util';-import { msg } from '@lingui/core/macro';import { isNull } from '@sniptt/guards';import { isDefined } from 'twenty-shared/utils';@@ -27,13 +25,11 @@ export const validateRatingAndSelectFieldOrThrow = (}if (!isNull(preValidatedValue) && !options.includes(preValidatedValue)) {- const inspectedValue = inspect(value);-throw new CommonQueryRunnerException(- `Invalid value ${inspectedValue} for field "${fieldName}"`,+ `Invalid value "${preValidatedValue}" for field "${fieldName}". Valid values are: ${options.join(', ')}`,CommonQueryRunnerExceptionCode.INVALID_ARGS_DATA,{- userFriendlyMessage: msg`Invalid value for select: "${inspectedValue}"`,+ userFriendlyMessage: msg`Invalid value for field "${fieldName}"`,},);}diff --git a/packages/twenty-server/src/engine/api/rest/input-request-parsers/ending-before-parser-utils/__tests__/parse-ending-before-rest-request.util.spec.ts b/packages/twenty-server/src/engine/api/rest/input-request-parsers/ending-before-parser-utils/__tests__/parse-ending-before-rest-request.util.spec.tsindex e761d82bab7..40b096cb056 100644--- a/packages/twenty-server/src/engine/api/rest/input-request-parsers/ending-before-parser-utils/__tests__/parse-ending-before-rest-request.util.spec.ts+++ b/packages/twenty-server/src/engine/api/rest/input-request-parsers/ending-before-parser-utils/__tests__/parse-ending-before-rest-request.util.spec.ts@@ -1,7 +1,7 @@import { parseEndingBeforeRestRequest } from 'src/engine/api/rest/input-request-parsers/ending-before-parser-utils/parse-ending-before-rest-request.util';describe('parseEndingBeforeRestRequest', () => {- it('should return default if ending_before missing', () => {+ it('should return undefined if ending_before missing', () => {const request: any = { query: {} };expect(parseEndingBeforeRestRequest(request)).toEqual(undefined);diff --git a/packages/twenty-server/src/engine/api/rest/input-request-parsers/starting-after-parser-utils/__tests__/parse-starting-after-rest-request.util.spec.ts b/packages/twenty-server/src/engine/api/rest/input-request-parsers/starting-after-parser-utils/__tests__/parse-starting-after-rest-request.util.spec.tsindex dae16e00618..da7860d05cd 100644--- a/packages/twenty-server/src/engine/api/rest/input-request-parsers/starting-after-parser-utils/__tests__/parse-starting-after-rest-request.util.spec.ts+++ b/packages/twenty-server/src/engine/api/rest/input-request-parsers/starting-after-parser-utils/__tests__/parse-starting-after-rest-request.util.spec.ts@@ -1,7 +1,7 @@import { parseStartingAfterRestRequest } from 'src/engine/api/rest/input-request-parsers/starting-after-parser-utils/parse-starting-after-rest-request.util';describe('parseStartingAfterRestRequest', () => {- it('should return default if starting_after missing', () => {+ it('should return undefined if starting_after missing', () => {const request: any = { query: {} };expect(parseStartingAfterRestRequest(request)).toEqual(undefined);diff --git a/packages/twenty-server/test/integration/graphql/suites/inputs-validation/create-validation/__snapshots__/rating-field-create-input-validation.integration-spec.ts.snap b/packages/twenty-server/test/integration/graphql/suites/inputs-validation/create-validation/__snapshots__/rating-field-create-input-validation.integration-spec.ts.snapindex 3116367cb58..afd30698243 100644--- a/packages/twenty-server/test/integration/graphql/suites/inputs-validation/create-validation/__snapshots__/rating-field-create-input-validation.integration-spec.ts.snap+++ b/packages/twenty-server/test/integration/graphql/suites/inputs-validation/create-validation/__snapshots__/rating-field-create-input-validation.integration-spec.ts.snap@@ -1,5 +1,5 @@// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing-exports[`Create input validation - RATING Gql create input - failure RATING - should fail with : {"ratingField":"not-a-rating"} 1`] = `"Invalid value 'not-a-rating' for field "ratingField""`;+exports[`Create input validation - RATING Gql create input - failure RATING - should fail with : {"ratingField":"not-a-rating"} 1`] = `"Invalid value \"not-a-rating\" for field \"ratingField\". Valid values are: RATING_1, RATING_2, RATING_3, RATING_4, RATING_5"`;-exports[`Create input validation - RATING Rest create input - failure RATING - should fail with : {"ratingField":"not-a-rating"} 1`] = `"["Invalid value 'not-a-rating' for field \\"ratingField\\""]"`;+exports[`Create input validation - RATING Rest create input - failure RATING - should fail with : {"ratingField":"not-a-rating"} 1`] = `"[\"Invalid value \\\"not-a-rating\\\" for field \\\"ratingField\\\". Valid values are: RATING_1, RATING_2, RATING_3, RATING_4, RATING_5\"]"`;diff --git a/packages/twenty-server/test/integration/graphql/suites/inputs-validation/create-validation/__snapshots__/select-field-create-input-validation.integration-spec.ts.snap b/packages/twenty-server/test/integration/graphql/suites/inputs-validation/create-validation/__snapshots__/select-field-create-input-validation.integration-spec.ts.snapindex 819b388c4d8..4c5d1679250 100644--- a/packages/twenty-server/test/integration/graphql/suites/inputs-validation/create-validation/__snapshots__/select-field-create-input-validation.integration-spec.ts.snap+++ b/packages/twenty-server/test/integration/graphql/suites/inputs-validation/create-validation/__snapshots__/select-field-create-input-validation.integration-spec.ts.snap@@ -1,9 +1,9 @@// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing-exports[`Create input validation - SELECT Gql create input - failure SELECT - should fail with : {"selectField":"not-a-select-option"} 1`] = `"Invalid value 'not-a-select-option' for field "selectField""`;+exports[`Create input validation - SELECT Gql create input - failure SELECT - should fail with : {"selectField":"not-a-select-option"} 1`] = `"Invalid value \"not-a-select-option\" for field \"selectField\". Valid values are: OPTION_1"`;exports[`Create input validation - SELECT Gql create input - failure SELECT - should fail with : {"selectField":1} 1`] = `"Invalid string value 1 for text field "selectField""`;-exports[`Create input validation - SELECT Rest create input - failure SELECT - should fail with : {"selectField":"not-a-select-option"} 1`] = `"["Invalid value 'not-a-select-option' for field \\"selectField\\""]"`;+exports[`Create input validation - SELECT Rest create input - failure SELECT - should fail with : {"selectField":"not-a-select-option"} 1`] = `"[\"Invalid value \\\"not-a-select-option\\\" for field \\\"selectField\\\". Valid values are: OPTION_1\"]"`;exports[`Create input validation - SELECT Rest create input - failure SELECT - should fail with : {"selectField":1} 1`] = `"["Invalid string value 1 for text field \\"selectField\\""]"`;diff --git a/packages/twenty-server/test/integration/rest/suites/rest-api-core-create-one.integration-spec.ts b/packages/twenty-server/test/integration/rest/suites/rest-api-core-create-one.integration-spec.tsindex fa04e0d5efd..3baa5a1008a 100644--- a/packages/twenty-server/test/integration/rest/suites/rest-api-core-create-one.integration-spec.ts+++ b/packages/twenty-server/test/integration/rest/suites/rest-api-core-create-one.integration-spec.ts@@ -208,7 +208,7 @@ describe('Core REST API Create One endpoint', () => {.expect(400).expect((res) => {expect(res.body.messages[0]).toMatch(- 'Invalid value \'INVALID_ENUM_VALUE\' for field "stage"',+ 'Invalid value "INVALID_ENUM_VALUE" for field "stage". Valid values are: NEW, SCREENING, MEETING, PROPOSAL, CUSTOMER',);expect(res.body.error).toBe('BadRequestException');});