Files v2 - Add new FILES field type (#17236)
In this PR : - New field type FieldMetadataType.FILES added (as jsonb in DB) - Backend: GraphQL types, validation, REST API schema, data processor handling - Frontend: field configuration in settings - Feature flag IS_FILES_FIELD_ENABLED to gate the feature - Integration tests for create/filter validation - Dev seed: Feature flag enabled + FILES field on survey result object To do in next PRs : - Backend : -- new workspaceFile controller (for download) & new workspaceFile upload resolver (for upload) -- pre-hook/post-hook to ensure fileId existence + listener to ensure cleaning - Frontend : FILES field display/edit in table view, record, ...
This commit is contained in:
+25
@@ -0,0 +1,25 @@
|
||||
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
|
||||
|
||||
exports[`Create input validation - FILES Gql create input - failure FILES - should fail with : {"filesField":"not-a-files-array"} 1`] = `"Expected type "FileInput" to be an object."`;
|
||||
|
||||
exports[`Create input validation - FILES Gql create input - failure FILES - should fail with : {"filesField":[{"fileId":"550e8400-e29b-41d4-a716-446655440000","label":"Document.pdf","fileType":"application/pdf"}]} 1`] = `"Field "fileType" is not defined by type "FileInput". Did you mean "fileId"?"`;
|
||||
|
||||
exports[`Create input validation - FILES Gql create input - failure FILES - should fail with : {"filesField":[{"fileId":"550e8400-e29b-41d4-a716-446655440000","label":"Document.pdf"},{"fileId":"550e8400-e29b-41d4-a716-446655440001","label":"Document.pdf"},{"fileId":"550e8400-e29b-41d4-a716-446655440002","label":"Document.pdf"},{"fileId":"550e8400-e29b-41d4-a716-446655440003","label":"Document.pdf"},{"fileId":"550e8400-e29b-41d4-a716-446655440004","label":"Document.pdf"},{"fileId":"550e8400-e29b-41d4-a716-446655440005","label":"Document.pdf"}]} 1`] = `"Max number of files is 2"`;
|
||||
|
||||
exports[`Create input validation - FILES Gql create input - failure FILES - should fail with : {"filesField":[{"fileId":"550e8400-e29b-41d4-a716-446655440000","label":12345}]} 1`] = `"String cannot represent a non string value: 12345"`;
|
||||
|
||||
exports[`Create input validation - FILES Gql create input - failure FILES - should fail with : {"filesField":[{"fileId":"not-a-uuid","label":"Document.pdf"}]} 1`] = `"Invalid UUID"`;
|
||||
|
||||
exports[`Create input validation - FILES Gql create input - failure FILES - should fail with : {"filesField":[{"invalidField":"test"}]} 1`] = `"Field "fileId" of required type "UUID!" was not provided."`;
|
||||
|
||||
exports[`Create input validation - FILES Rest create input - failure FILES - should fail with : {"filesField":"not-a-files-array"} 1`] = `"["Invalid value \\"'not-a-files-array'\\" for FILES field \\"filesField\\" - It should be an array of objects with \\"fileId\\" and \\"label\\" properties."]"`;
|
||||
|
||||
exports[`Create input validation - FILES Rest create input - failure FILES - should fail with : {"filesField":[{"fileId":"550e8400-e29b-41d4-a716-446655440000","label":"Document.pdf","fileType":"application/pdf"}]} 1`] = `"["Invalid value \\"[\\n {\\n fileId: '550e8400-e29b-41d4-a716-446655440000',\\n label: 'Document.pdf',\\n fileType: 'application/pdf'\\n }\\n]\\" for FILES field \\"filesField\\" - 0: Unrecognized key: \\"fileType\\""]"`;
|
||||
|
||||
exports[`Create input validation - FILES Rest create input - failure FILES - should fail with : {"filesField":[{"fileId":"550e8400-e29b-41d4-a716-446655440000","label":"Document.pdf"},{"fileId":"550e8400-e29b-41d4-a716-446655440001","label":"Document.pdf"},{"fileId":"550e8400-e29b-41d4-a716-446655440002","label":"Document.pdf"},{"fileId":"550e8400-e29b-41d4-a716-446655440003","label":"Document.pdf"},{"fileId":"550e8400-e29b-41d4-a716-446655440004","label":"Document.pdf"},{"fileId":"550e8400-e29b-41d4-a716-446655440005","label":"Document.pdf"}]} 1`] = `"["Max number of files is 2"]"`;
|
||||
|
||||
exports[`Create input validation - FILES Rest create input - failure FILES - should fail with : {"filesField":[{"fileId":"550e8400-e29b-41d4-a716-446655440000","label":12345}]} 1`] = `"["Invalid value \\"[ { fileId: '550e8400-e29b-41d4-a716-446655440000', label: 12345 } ]\\" for FILES field \\"filesField\\" - 0.label: Invalid input: expected string, received number"]"`;
|
||||
|
||||
exports[`Create input validation - FILES Rest create input - failure FILES - should fail with : {"filesField":[{"fileId":"not-a-uuid","label":"Document.pdf"}]} 1`] = `"["Invalid value \\"[ { fileId: 'not-a-uuid', label: 'Document.pdf' } ]\\" for FILES field \\"filesField\\" - 0.fileId: Invalid UUID"]"`;
|
||||
|
||||
exports[`Create input validation - FILES Rest create input - failure FILES - should fail with : {"filesField":[{"invalidField":"test"}]} 1`] = `"["Invalid value \\"[ { invalidField: 'test' } ]\\" for FILES field \\"filesField\\" - 0.fileId: Invalid input: expected string, received undefined, 0.label: Invalid input: expected string, received undefined, 0: Unrecognized key: \\"invalidField\\""]"`;
|
||||
+66
@@ -386,4 +386,70 @@ export const failingCreateInputByFieldMetadataType: {
|
||||
},
|
||||
},
|
||||
],
|
||||
[FieldMetadataType.FILES]: [
|
||||
{
|
||||
input: {
|
||||
filesField: 'not-a-files-array',
|
||||
},
|
||||
},
|
||||
{
|
||||
input: {
|
||||
filesField: [{ invalidField: 'test' }],
|
||||
},
|
||||
},
|
||||
{
|
||||
input: {
|
||||
filesField: [{ fileId: 'not-a-uuid', label: 'Document.pdf' }],
|
||||
},
|
||||
},
|
||||
{
|
||||
input: {
|
||||
filesField: [
|
||||
{ fileId: '550e8400-e29b-41d4-a716-446655440000', label: 12345 },
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
input: {
|
||||
filesField: [
|
||||
{
|
||||
fileId: '550e8400-e29b-41d4-a716-446655440000',
|
||||
label: 'Document.pdf',
|
||||
fileType: 'application/pdf',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
//Should fail because max number of files is 2
|
||||
{
|
||||
input: {
|
||||
filesField: [
|
||||
{
|
||||
fileId: '550e8400-e29b-41d4-a716-446655440000',
|
||||
label: 'Document.pdf',
|
||||
},
|
||||
{
|
||||
fileId: '550e8400-e29b-41d4-a716-446655440001',
|
||||
label: 'Document.pdf',
|
||||
},
|
||||
{
|
||||
fileId: '550e8400-e29b-41d4-a716-446655440002',
|
||||
label: 'Document.pdf',
|
||||
},
|
||||
{
|
||||
fileId: '550e8400-e29b-41d4-a716-446655440003',
|
||||
label: 'Document.pdf',
|
||||
},
|
||||
{
|
||||
fileId: '550e8400-e29b-41d4-a716-446655440004',
|
||||
label: 'Document.pdf',
|
||||
},
|
||||
{
|
||||
fileId: '550e8400-e29b-41d4-a716-446655440005',
|
||||
label: 'Document.pdf',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
+37
@@ -509,4 +509,41 @@ export const successfulCreateInputByFieldMetadataType: {
|
||||
},
|
||||
},
|
||||
],
|
||||
[FieldMetadataType.FILES]: [
|
||||
{
|
||||
input: {
|
||||
filesField: [
|
||||
{
|
||||
fileId: '20202020-a21e-4ec2-873b-de4264d89025',
|
||||
label: 'Document.pdf',
|
||||
},
|
||||
],
|
||||
},
|
||||
validateInput: (record: Record<string, any>) => {
|
||||
return (
|
||||
Array.isArray(record.filesField) &&
|
||||
record.filesField.length === 1 &&
|
||||
record.filesField[0].fileId ===
|
||||
'20202020-a21e-4ec2-873b-de4264d89025' &&
|
||||
record.filesField[0].label === 'Document.pdf'
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
input: {
|
||||
filesField: [],
|
||||
},
|
||||
validateInput: (record: Record<string, any>) => {
|
||||
return record.filesField === null;
|
||||
},
|
||||
},
|
||||
{
|
||||
input: {
|
||||
filesField: null,
|
||||
},
|
||||
validateInput: (record: Record<string, any>) => {
|
||||
return record.filesField === null;
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
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 { makeGraphqlAPIRequest } from 'test/integration/graphql/utils/make-graphql-api-request.util';
|
||||
import { updateFeatureFlagFactory } from 'test/integration/graphql/utils/update-feature-flag-factory.util';
|
||||
import { FieldMetadataType } from 'twenty-shared/types';
|
||||
|
||||
import { FeatureFlagKey } from 'src/engine/core-modules/feature-flag/enums/feature-flag-key.enum';
|
||||
import { SEED_APPLE_WORKSPACE_ID } from 'src/engine/workspace-manager/dev-seeder/core/constants/seeder-workspaces.constant';
|
||||
|
||||
const FIELD_METADATA_TYPE = FieldMetadataType.FILES;
|
||||
|
||||
const failingTestCases =
|
||||
failingCreateInputByFieldMetadataType[FIELD_METADATA_TYPE];
|
||||
const successfulTestCases =
|
||||
successfulCreateInputByFieldMetadataType[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 () => {
|
||||
await makeGraphqlAPIRequest(
|
||||
updateFeatureFlagFactory(
|
||||
SEED_APPLE_WORKSPACE_ID,
|
||||
FeatureFlagKey.IS_FILES_FIELD_ENABLED,
|
||||
true,
|
||||
),
|
||||
);
|
||||
|
||||
const setupTest = await setupTestObjectsWithAllFieldTypes(true);
|
||||
|
||||
objectMetadataId = setupTest.objectMetadataId;
|
||||
objectMetadataSingularName = setupTest.objectMetadataSingularName;
|
||||
objectMetadataPluralName = setupTest.objectMetadataPluralName;
|
||||
targetObjectMetadata1Id = setupTest.targetObjectMetadata1Id;
|
||||
targetObjectMetadata2Id = setupTest.targetObjectMetadata2Id;
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await destroyManyObjectsMetadata([
|
||||
objectMetadataId,
|
||||
targetObjectMetadata1Id,
|
||||
targetObjectMetadata2Id,
|
||||
]);
|
||||
|
||||
await makeGraphqlAPIRequest(
|
||||
updateFeatureFlagFactory(
|
||||
SEED_APPLE_WORKSPACE_ID,
|
||||
FeatureFlagKey.IS_FILES_FIELD_ENABLED,
|
||||
false,
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
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,
|
||||
true,
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
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,
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
+9
-1
@@ -8,10 +8,18 @@ export const expectGqlCreateInputValidationSuccess = async (
|
||||
objectMetadataSingularName: string,
|
||||
input: any,
|
||||
validateInput: (record: Record<string, any>) => boolean,
|
||||
withFilesField: boolean = false,
|
||||
) => {
|
||||
const createOneOperation = createOneOperationFactory({
|
||||
objectMetadataSingularName: objectMetadataSingularName,
|
||||
gqlFields: TEST_OBJECT_GQL_FIELDS,
|
||||
gqlFields:
|
||||
TEST_OBJECT_GQL_FIELDS +
|
||||
(withFilesField
|
||||
? ` filesField {
|
||||
fileId
|
||||
label
|
||||
}`
|
||||
: ''),
|
||||
data: input,
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user