Common API - Add tests on position field validation at creation (#16630)

Co-authored-by: guillim <guigloo@msn.com>
This commit is contained in:
Etienne
2025-12-17 17:02:37 +01:00
committed by GitHub
parent 0e6a8c04c4
commit 59d3a14922
13 changed files with 353 additions and 55 deletions
@@ -0,0 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Create input validation - NUMBER Gql create input - failure NUMBER - should fail with : {"numberField":"string"} 1`] = `"Float cannot represent non numeric value: "string""`;
exports[`Create input validation - NUMBER Gql create input - failure NUMBER - should fail with : {"numberField":[]} 1`] = `"Float cannot represent non numeric value: []"`;
exports[`Create input validation - NUMBER Gql create input - failure NUMBER - should fail with : {"numberField":{}} 1`] = `"Float cannot represent non numeric value: {}"`;
exports[`Create input validation - NUMBER Gql create input - failure NUMBER - should fail with : {"numberField":true} 1`] = `"Float cannot represent non numeric value: true"`;
exports[`Create input validation - NUMBER Rest create input - failure NUMBER - should fail with : {"numberField":"string"} 1`] = `"["Invalid number value 'string' for field \\"numberField\\""]"`;
exports[`Create input validation - NUMBER Rest create input - failure NUMBER - should fail with : {"numberField":[]} 1`] = `"["Invalid number value [] for field \\"numberField\\""]"`;
exports[`Create input validation - NUMBER Rest create input - failure NUMBER - should fail with : {"numberField":{}} 1`] = `"["Invalid number value {} for field \\"numberField\\""]"`;
exports[`Create input validation - NUMBER Rest create input - failure NUMBER - should fail with : {"numberField":true} 1`] = `"["Invalid number value true for field \\"numberField\\""]"`;
@@ -0,0 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Create input validation - POSITION Gql create input - failure POSITION - should fail with : {"position":"not-a-position"} 1`] = `"Invalid position value: 'not-a-position'. Position must be 'first', 'last', or a number"`;
exports[`Create input validation - POSITION Gql create input - failure POSITION - should fail with : {"position":null} 1`] = `"Invalid position value null for field "position""`;
exports[`Create input validation - POSITION Rest create input - failure POSITION - should fail with : {"position":"not-a-position"} 1`] = `"["Invalid position value 'not-a-position' for field \\"position\\""]"`;
exports[`Create input validation - POSITION Rest create input - failure POSITION - should fail with : {"position":null} 1`] = `"["Invalid position value null for field \\"position\\""]"`;
@@ -374,4 +374,16 @@ export const failingCreateInputByFieldMetadataType: {
},
},
],
[FieldMetadataType.POSITION]: [
{
input: {
position: 'not-a-position',
},
},
{
input: {
position: NaN,
},
},
],
};
@@ -475,4 +475,38 @@ export const successfulCreateInputByFieldMetadataType: {
},
},
],
[FieldMetadataType.POSITION]: [
{
input: {
position: 1000,
},
validateInput: (record: Record<string, any>) => {
return record.position === 1000;
},
},
{
input: {
position: 'last',
},
validateInput: (record: Record<string, any>) => {
return record.position > 1000;
},
},
{
input: {
position: 'first',
},
validateInput: (record: Record<string, any>) => {
return record.position < 1000;
},
},
{
input: {
position: undefined,
},
validateInput: (record: Record<string, any>) => {
return typeof record.position === 'number';
},
},
],
};
@@ -1,5 +1,8 @@
import { failingCreateInputByFieldMetadataType } from 'test/integration/graphql/suites/inputs-validation/create-validation/constants/failing-create-input-by-field-metadata-type.constant';
import { successfulCreateInputByFieldMetadataType } from 'test/integration/graphql/suites/inputs-validation/create-validation/constants/successful-create-input-by-field-metadata-type.constant';
import { expectGqlCreateInputValidationError } from 'test/integration/graphql/suites/inputs-validation/create-validation/utils/expect-gql-create-input-validation-error.util';
import { expectGqlCreateInputValidationSuccess } from 'test/integration/graphql/suites/inputs-validation/create-validation/utils/expect-gql-create-input-validation-success.util';
import { expectRestCreateInputValidationError } from 'test/integration/graphql/suites/inputs-validation/create-validation/utils/expect-rest-create-input-validation-error.util';
import { expectRestCreateInputValidationSuccess } from 'test/integration/graphql/suites/inputs-validation/create-validation/utils/expect-rest-create-input-validation-success.util';
import { destroyManyObjectsMetadata } from 'test/integration/graphql/suites/inputs-validation/utils/destroy-many-objects-metadata';
import { setupTestObjectsWithAllFieldTypes } from 'test/integration/graphql/suites/inputs-validation/utils/setup-test-objects-with-all-field-types.util';
@@ -10,6 +13,9 @@ const FIELD_METADATA_TYPE = FieldMetadataType.NUMBER;
const successfulTestCases =
successfulCreateInputByFieldMetadataType[FIELD_METADATA_TYPE];
const failingTestCases =
failingCreateInputByFieldMetadataType[FIELD_METADATA_TYPE];
describe(`Create input validation - ${FIELD_METADATA_TYPE}`, () => {
let objectMetadataId: string;
let objectMetadataSingularName: string;
@@ -35,39 +41,39 @@ describe(`Create input validation - ${FIELD_METADATA_TYPE}`, () => {
]);
});
// describe('Gql create input - failure', () => {
// it.each(
// failingTestCases.map((testCase) => ({
// ...testCase,
// stringifiedInput: JSON.stringify(testCase.input),
// })),
// )(
// `${FIELD_METADATA_TYPE} - should fail with : $stringifiedInput`,
// async ({ input }) => {
// await expectGqlCreateInputValidationError(
// objectMetadataSingularName,
// input,
// );
// },
// );
// });
describe('Gql create input - failure', () => {
it.each(
failingTestCases.map((testCase) => ({
...testCase,
stringifiedInput: JSON.stringify(testCase.input),
})),
)(
`${FIELD_METADATA_TYPE} - should fail with : $stringifiedInput`,
async ({ input }) => {
await expectGqlCreateInputValidationError(
objectMetadataSingularName,
input,
);
},
);
});
// describe('Rest create input - failure', () => {
// it.each(
// failingTestCases.map((testCase) => ({
// ...testCase,
// stringifiedInput: JSON.stringify(testCase.input),
// })),
// )(
// `${FIELD_METADATA_TYPE} - should fail with : $stringifiedInput`,
// async ({ input }) => {
// await expectRestCreateInputValidationError(
// objectMetadataPluralName,
// input,
// );
// },
// );
// });
describe('Rest create input - failure', () => {
it.each(
failingTestCases.map((testCase) => ({
...testCase,
stringifiedInput: JSON.stringify(testCase.input),
})),
)(
`${FIELD_METADATA_TYPE} - should fail with : $stringifiedInput`,
async ({ input }) => {
await expectRestCreateInputValidationError(
objectMetadataPluralName,
input,
);
},
);
});
describe('Gql create input - success', () => {
it.each(
@@ -0,0 +1,113 @@
import { failingCreateInputByFieldMetadataType } from 'test/integration/graphql/suites/inputs-validation/create-validation/constants/failing-create-input-by-field-metadata-type.constant';
import { successfulCreateInputByFieldMetadataType } from 'test/integration/graphql/suites/inputs-validation/create-validation/constants/successful-create-input-by-field-metadata-type.constant';
import { expectGqlCreateInputValidationError } from 'test/integration/graphql/suites/inputs-validation/create-validation/utils/expect-gql-create-input-validation-error.util';
import { expectGqlCreateInputValidationSuccess } from 'test/integration/graphql/suites/inputs-validation/create-validation/utils/expect-gql-create-input-validation-success.util';
import { expectRestCreateInputValidationError } from 'test/integration/graphql/suites/inputs-validation/create-validation/utils/expect-rest-create-input-validation-error.util';
import { expectRestCreateInputValidationSuccess } from 'test/integration/graphql/suites/inputs-validation/create-validation/utils/expect-rest-create-input-validation-success.util';
import { destroyManyObjectsMetadata } from 'test/integration/graphql/suites/inputs-validation/utils/destroy-many-objects-metadata';
import { setupTestObjectsWithAllFieldTypes } from 'test/integration/graphql/suites/inputs-validation/utils/setup-test-objects-with-all-field-types.util';
import { FieldMetadataType } from 'twenty-shared/types';
const FIELD_METADATA_TYPE = FieldMetadataType.POSITION;
const successfulTestCases =
successfulCreateInputByFieldMetadataType[FIELD_METADATA_TYPE];
const failingTestCases =
failingCreateInputByFieldMetadataType[FIELD_METADATA_TYPE];
describe(`Create input validation - ${FIELD_METADATA_TYPE}`, () => {
let objectMetadataId: string;
let objectMetadataSingularName: string;
let objectMetadataPluralName: string;
let targetObjectMetadata1Id: string;
let targetObjectMetadata2Id: string;
beforeAll(async () => {
const setupTest = await setupTestObjectsWithAllFieldTypes();
objectMetadataId = setupTest.objectMetadataId;
objectMetadataSingularName = setupTest.objectMetadataSingularName;
objectMetadataPluralName = setupTest.objectMetadataPluralName;
targetObjectMetadata1Id = setupTest.targetObjectMetadata1Id;
targetObjectMetadata2Id = setupTest.targetObjectMetadata2Id;
});
afterAll(async () => {
await destroyManyObjectsMetadata([
objectMetadataId,
targetObjectMetadata1Id,
targetObjectMetadata2Id,
]);
});
describe('Gql create input - failure', () => {
it.each(
failingTestCases.map((testCase) => ({
...testCase,
stringifiedInput: JSON.stringify(testCase.input),
})),
)(
`${FIELD_METADATA_TYPE} - should fail with : $stringifiedInput`,
async ({ input }) => {
await expectGqlCreateInputValidationError(
objectMetadataSingularName,
input,
);
},
);
});
describe('Rest create input - failure', () => {
it.each(
failingTestCases.map((testCase) => ({
...testCase,
stringifiedInput: JSON.stringify(testCase.input),
})),
)(
`${FIELD_METADATA_TYPE} - should fail with : $stringifiedInput`,
async ({ input }) => {
await expectRestCreateInputValidationError(
objectMetadataPluralName,
input,
);
},
);
});
describe('Gql create input - success', () => {
it.each(
successfulTestCases.map((testCase) => ({
...testCase,
stringifiedInput: JSON.stringify(testCase.input),
})),
)(
`${FIELD_METADATA_TYPE} - should succeed with : $stringifiedInput`,
async ({ input, validateInput }) => {
await expectGqlCreateInputValidationSuccess(
objectMetadataSingularName,
input,
validateInput,
);
},
);
});
describe('Rest create input - success', () => {
it.each(
successfulTestCases.map((testCase) => ({
...testCase,
stringifiedInput: JSON.stringify(testCase.input),
})),
)(
`${FIELD_METADATA_TYPE} - should succeed with : $stringifiedInput`,
async ({ input, validateInput }) => {
await expectRestCreateInputValidationSuccess(
objectMetadataPluralName,
objectMetadataSingularName,
input,
validateInput,
);
},
);
});
});