Fix: multi-select default values validation (#12271)
https://github.com/user-attachments/assets/3bea63cc-b098-4252-8787-fc6263f01e8d Closes #12277 --------- Co-authored-by: prastoin <paul@twenty.com> Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -1,321 +0,0 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`Field metadata select creation tests group Create should fail with an invalid default value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Default value for existing options is invalid: invalid",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select creation tests group Create should fail with an unknown default value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Default value for existing options is invalid: 'OPTION_424242'",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select creation tests group Create should fail with comma in option label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Label must not contain a comma",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select creation tests group Create should fail with duplicated option ids 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Duplicated option id "fd1f11fd-3f05-4a33-bddf-800c3412ce98"",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select creation tests group Create should fail with duplicated option positions 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Duplicated option position "1"",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select creation tests group Create should fail with duplicated option values 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Duplicated option value "OPTION_1"",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select creation tests group Create should fail with duplicated trimmed option values 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Duplicated option value "OPTION_1"",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select creation tests group Create should fail with empty options 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Options are required for enum fields",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select creation tests group Create should fail with empty string id 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option id is invalid",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select creation tests group Create should fail with empty string label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option label "" is beneath 1 character",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select creation tests group Create should fail with empty string value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option value "" is beneath 1 character",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select creation tests group Create should fail with invalid option id 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option id is invalid",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select creation tests group Create should fail with invalid option value format 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Value must be in UPPER_CASE and follow snake_case "Option 1 and some other things, /"",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select creation tests group Create should fail with not a string id 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option id is invalid",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select creation tests group Create should fail with not a string label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "INTERNAL_SERVER_ERROR",
|
||||
"exceptionEventId": "mocked-exception-id",
|
||||
},
|
||||
"message": "label.includes is not a function",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select creation tests group Create should fail with not a string value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Value must be in UPPER_CASE and follow snake_case "22222"",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select creation tests group Create should fail with null id 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option id is required",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select creation tests group Create should fail with null label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option label is required",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select creation tests group Create should fail with null options 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Options are required for enum fields",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select creation tests group Create should fail with null value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option value is required",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select creation tests group Create should fail with only white spaces id 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option id is invalid",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select creation tests group Create should fail with only white spaces label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option label "" is beneath 1 character",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select creation tests group Create should fail with only white spaces value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option value "" is beneath 1 character",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select creation tests group Create should fail with too long id 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option id is invalid",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select creation tests group Create should fail with too long label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option label "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" exceeds 63 characters",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select creation tests group Create should fail with too long value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option value "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" exceeds 63 characters",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select creation tests group Create should fail with undefined option label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option label is required",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select creation tests group Create should fail with undefined option value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option value is required",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select creation tests group Create should fail with undefined options 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Options are required for enum fields",
|
||||
},
|
||||
]
|
||||
`;
|
||||
@ -1,310 +0,0 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`Field metadata select update tests group Update should fail with an invalid default value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Default value for existing options is invalid: invalid",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select update tests group Update should fail with an unknown default value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Default value for existing options is invalid: 'OPTION_424242'",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select update tests group Update should fail with comma in option label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Label must not contain a comma",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select update tests group Update should fail with duplicated option ids 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Duplicated option id "fd1f11fd-3f05-4a33-bddf-800c3412ce98"",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select update tests group Update should fail with duplicated option positions 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Duplicated option position "1"",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select update tests group Update should fail with duplicated option values 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Duplicated option value "OPTION_1"",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select update tests group Update should fail with duplicated trimmed option values 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Duplicated option value "OPTION_1"",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select update tests group Update should fail with empty options 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Options are required for enum fields",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select update tests group Update should fail with empty string id 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option id is invalid",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select update tests group Update should fail with empty string label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option label "" is beneath 1 character",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select update tests group Update should fail with empty string value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option value "" is beneath 1 character",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select update tests group Update should fail with invalid option id 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option id is invalid",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select update tests group Update should fail with invalid option value format 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Value must be in UPPER_CASE and follow snake_case "Option 1 and some other things, /"",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select update tests group Update should fail with not a string id 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option id is invalid",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select update tests group Update should fail with not a string label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "INTERNAL_SERVER_ERROR",
|
||||
"exceptionEventId": "mocked-exception-id",
|
||||
},
|
||||
"message": "label.includes is not a function",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select update tests group Update should fail with not a string value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Value must be in UPPER_CASE and follow snake_case "22222"",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select update tests group Update should fail with null id 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option id is required",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select update tests group Update should fail with null label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option label is required",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select update tests group Update should fail with null value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option value is required",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select update tests group Update should fail with only white spaces id 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option id is invalid",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select update tests group Update should fail with only white spaces label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option label "" is beneath 1 character",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select update tests group Update should fail with only white spaces value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option value "" is beneath 1 character",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select update tests group Update should fail with too long id 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option id is invalid",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select update tests group Update should fail with too long label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option label "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" exceeds 63 characters",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select update tests group Update should fail with too long value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option value "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" exceeds 63 characters",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select update tests group Update should fail with undefined option label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option label is required",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select update tests group Update should fail with undefined option value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option value is required",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Field metadata select update tests group Update should fail with unknown default value and no options 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Default value for existing options is invalid: 'OPTION_42'",
|
||||
},
|
||||
]
|
||||
`;
|
||||
@ -1,128 +0,0 @@
|
||||
import {
|
||||
UPDATE_CREATE_ONE_FIELD_METADATA_SELECT_TEST_CASES,
|
||||
UpdateCreateFieldMetadataSelectTestCase,
|
||||
} from 'test/integration/metadata/suites/field-metadata/update-create-one-field-metadata-select-tests-cases';
|
||||
import { createOneFieldMetadata } from 'test/integration/metadata/suites/field-metadata/utils/create-one-field-metadata.util';
|
||||
import {
|
||||
LISTING_NAME_PLURAL,
|
||||
LISTING_NAME_SINGULAR,
|
||||
} from 'test/integration/metadata/suites/object-metadata/constants/test-object-names.constant';
|
||||
import { createOneObjectMetadata } from 'test/integration/metadata/suites/object-metadata/utils/create-one-object-metadata.util';
|
||||
import { deleteOneObjectMetadata } from 'test/integration/metadata/suites/object-metadata/utils/delete-one-object-metadata.util';
|
||||
import { FieldMetadataType } from 'twenty-shared/types';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
import {
|
||||
FieldMetadataComplexOption,
|
||||
FieldMetadataDefaultOption,
|
||||
} from 'src/engine/metadata-modules/field-metadata/dtos/options.input';
|
||||
|
||||
const { failingTestCases, successfulTestCases } =
|
||||
UPDATE_CREATE_ONE_FIELD_METADATA_SELECT_TEST_CASES;
|
||||
|
||||
describe('Field metadata select creation tests group', () => {
|
||||
let createdObjectMetadataId: string;
|
||||
|
||||
beforeEach(async () => {
|
||||
const { data } = await createOneObjectMetadata({
|
||||
input: {
|
||||
labelSingular: LISTING_NAME_SINGULAR,
|
||||
labelPlural: LISTING_NAME_PLURAL,
|
||||
nameSingular: LISTING_NAME_SINGULAR,
|
||||
namePlural: LISTING_NAME_PLURAL,
|
||||
icon: 'IconBuildingSkyscraper',
|
||||
isLabelSyncedWithName: false,
|
||||
},
|
||||
});
|
||||
|
||||
createdObjectMetadataId = data.createOneObject.id;
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await deleteOneObjectMetadata({
|
||||
input: { idToDelete: createdObjectMetadataId },
|
||||
});
|
||||
});
|
||||
|
||||
test.each(successfulTestCases)(
|
||||
'Create $title',
|
||||
async ({ context: { input, expectedOptions } }) => {
|
||||
const { data, errors } = await createOneFieldMetadata({
|
||||
input: {
|
||||
objectMetadataId: createdObjectMetadataId,
|
||||
type: FieldMetadataType.SELECT,
|
||||
name: 'testField',
|
||||
label: 'Test Field',
|
||||
isLabelSyncedWithName: false,
|
||||
...input,
|
||||
},
|
||||
gqlFields: `
|
||||
id
|
||||
options
|
||||
defaultValue
|
||||
`,
|
||||
});
|
||||
|
||||
expect(data).not.toBeNull();
|
||||
expect(data.createOneField).toBeDefined();
|
||||
const createdOptions:
|
||||
| FieldMetadataDefaultOption[]
|
||||
| FieldMetadataComplexOption[] = data.createOneField.options;
|
||||
|
||||
const optionsToCompare = expectedOptions ?? input.options;
|
||||
|
||||
expect(errors).toBeUndefined();
|
||||
expect(createdOptions.length).toBe(optionsToCompare.length);
|
||||
createdOptions.forEach((option) => expect(option.id).toBeDefined());
|
||||
expect(createdOptions).toMatchObject(optionsToCompare);
|
||||
|
||||
if (isDefined(input.defaultValue)) {
|
||||
expect(data.createOneField.defaultValue).toEqual(input.defaultValue);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
const createSpecificFailingTestCases: UpdateCreateFieldMetadataSelectTestCase[] =
|
||||
[
|
||||
{
|
||||
title: 'should fail with null options',
|
||||
context: {
|
||||
input: {
|
||||
options: null as unknown as FieldMetadataComplexOption[],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'should fail with undefined options',
|
||||
context: {
|
||||
input: {
|
||||
options: undefined as unknown as FieldMetadataComplexOption[],
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
test.each([...failingTestCases, ...createSpecificFailingTestCases])(
|
||||
'Create $title',
|
||||
async ({ context: { input } }) => {
|
||||
const { data, errors } = await createOneFieldMetadata({
|
||||
input: {
|
||||
objectMetadataId: createdObjectMetadataId,
|
||||
type: FieldMetadataType.SELECT,
|
||||
name: 'testField',
|
||||
label: 'Test Field',
|
||||
isLabelSyncedWithName: false,
|
||||
...input,
|
||||
},
|
||||
gqlFields: `
|
||||
id
|
||||
options
|
||||
`,
|
||||
});
|
||||
|
||||
expect(data).toBeNull();
|
||||
expect(errors).toBeDefined();
|
||||
expect(errors).toMatchSnapshot();
|
||||
},
|
||||
);
|
||||
});
|
||||
@ -0,0 +1,773 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`Create field metadata MULTI_SELECT tests suite Create should fail with an invalid default value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Default value for multi-select must be an array",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata MULTI_SELECT tests suite Create should fail with an unknown default value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Default value for multi-select must be an array",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata MULTI_SELECT tests suite Create should fail with comma in option label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Label must not contain a comma",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata MULTI_SELECT tests suite Create should fail with duplicated option ids 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Duplicated option id",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata MULTI_SELECT tests suite Create should fail with duplicated option positions 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Duplicated option position",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata MULTI_SELECT tests suite Create should fail with duplicated option values 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Duplicated option value",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata MULTI_SELECT tests suite Create should fail with duplicated trimmed option values 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Duplicated option value",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata MULTI_SELECT tests suite Create should fail with empty multi-select default values array 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "If defined default value must contain at least one value",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata MULTI_SELECT tests suite Create should fail with empty options 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Options are required for enum fields",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata MULTI_SELECT tests suite Create should fail with empty string defaultValue 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Default value for multi-select must be an array",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata MULTI_SELECT tests suite Create should fail with empty string id 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option id is invalid",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata MULTI_SELECT tests suite Create should fail with empty string label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option label "" is beneath 1 character",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata MULTI_SELECT tests suite Create should fail with empty string value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option value "" is beneath 1 character",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata MULTI_SELECT tests suite Create should fail with invalid multi-select default value format 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Default value should be as quoted string",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata MULTI_SELECT tests suite Create should fail with invalid option id 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option id is invalid",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata MULTI_SELECT tests suite Create should fail with invalid option value format 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Value must be in UPPER_CASE and follow snake_case "Option 1 and some other things, /"",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata MULTI_SELECT tests suite Create should fail with non stringified array default value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Default value for multi-select must be an array",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata MULTI_SELECT tests suite Create should fail with not a string defaultValue 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Default value for multi-select must be an array",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata MULTI_SELECT tests suite Create should fail with not a string id 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option id is invalid",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata MULTI_SELECT tests suite Create should fail with not a string label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "INTERNAL_SERVER_ERROR",
|
||||
"exceptionEventId": "mocked-exception-id",
|
||||
},
|
||||
"message": "label.includes is not a function",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata MULTI_SELECT tests suite Create should fail with not a string value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Value must be in UPPER_CASE and follow snake_case "22222"",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata MULTI_SELECT tests suite Create should fail with null id 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option id is required",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata MULTI_SELECT tests suite Create should fail with null label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option label is required",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata MULTI_SELECT tests suite Create should fail with null options 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Options are required for enum fields",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata MULTI_SELECT tests suite Create should fail with null value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option value is required",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata MULTI_SELECT tests suite Create should fail with only white spaces defaultValue 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Default value for multi-select must be an array",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata MULTI_SELECT tests suite Create should fail with only white spaces id 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option id is invalid",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata MULTI_SELECT tests suite Create should fail with only white spaces label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option label "" is beneath 1 character",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata MULTI_SELECT tests suite Create should fail with only white spaces value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option value "" is beneath 1 character",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata MULTI_SELECT tests suite Create should fail with too long defaultValue 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Default value for multi-select must be an array",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata MULTI_SELECT tests suite Create should fail with too long id 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option id is invalid",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata MULTI_SELECT tests suite Create should fail with too long label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option label "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" exceeds 63 characters",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata MULTI_SELECT tests suite Create should fail with too long value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option value "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" exceeds 63 characters",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata MULTI_SELECT tests suite Create should fail with undefined option label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option label is required",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata MULTI_SELECT tests suite Create should fail with undefined option value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option value is required",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata MULTI_SELECT tests suite Create should fail with undefined options 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Options are required for enum fields",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata MULTI_SELECT tests suite Create should fail with unknown multi-select default values 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Default value "'UNKNOWN_OPTION'" must be one of the option values",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata SELECT tests suite Create should fail with an invalid default value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Default value should be as quoted string",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata SELECT tests suite Create should fail with an unknown default value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Default value "'OPTION_424242'" must be one of the option values",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata SELECT tests suite Create should fail with comma in option label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Label must not contain a comma",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata SELECT tests suite Create should fail with duplicated option ids 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Duplicated option id",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata SELECT tests suite Create should fail with duplicated option positions 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Duplicated option position",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata SELECT tests suite Create should fail with duplicated option values 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Duplicated option value",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata SELECT tests suite Create should fail with duplicated trimmed option values 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Duplicated option value",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata SELECT tests suite Create should fail with empty options 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Options are required for enum fields",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata SELECT tests suite Create should fail with empty string defaultValue 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Default value should be as quoted string",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata SELECT tests suite Create should fail with empty string id 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option id is invalid",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata SELECT tests suite Create should fail with empty string label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option label "" is beneath 1 character",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata SELECT tests suite Create should fail with empty string value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option value "" is beneath 1 character",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata SELECT tests suite Create should fail with invalid option id 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option id is invalid",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata SELECT tests suite Create should fail with invalid option value format 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Value must be in UPPER_CASE and follow snake_case "Option 1 and some other things, /"",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata SELECT tests suite Create should fail with not a string defaultValue 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Default value for multi-select must be a stringified array",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata SELECT tests suite Create should fail with not a string id 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option id is invalid",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata SELECT tests suite Create should fail with not a string label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "INTERNAL_SERVER_ERROR",
|
||||
"exceptionEventId": "mocked-exception-id",
|
||||
},
|
||||
"message": "label.includes is not a function",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata SELECT tests suite Create should fail with not a string value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Value must be in UPPER_CASE and follow snake_case "22222"",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata SELECT tests suite Create should fail with null id 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option id is required",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata SELECT tests suite Create should fail with null label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option label is required",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata SELECT tests suite Create should fail with null options 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Options are required for enum fields",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata SELECT tests suite Create should fail with null value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option value is required",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata SELECT tests suite Create should fail with only white spaces defaultValue 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Default value should be as quoted string",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata SELECT tests suite Create should fail with only white spaces id 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option id is invalid",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata SELECT tests suite Create should fail with only white spaces label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option label "" is beneath 1 character",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata SELECT tests suite Create should fail with only white spaces value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option value "" is beneath 1 character",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata SELECT tests suite Create should fail with too long defaultValue 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Default value should be as quoted string",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata SELECT tests suite Create should fail with too long id 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option id is invalid",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata SELECT tests suite Create should fail with too long label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option label "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" exceeds 63 characters",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata SELECT tests suite Create should fail with too long value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option value "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" exceeds 63 characters",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata SELECT tests suite Create should fail with undefined option label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option label is required",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata SELECT tests suite Create should fail with undefined option value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option value is required",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Create field metadata SELECT tests suite Create should fail with undefined options 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Options are required for enum fields",
|
||||
},
|
||||
]
|
||||
`;
|
||||
@ -0,0 +1,751 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`Update field metadata MULTI_SELECT tests suite Update should fail with an invalid default value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Default value for multi-select must be an array",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata MULTI_SELECT tests suite Update should fail with an unknown default value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Default value for multi-select must be an array",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata MULTI_SELECT tests suite Update should fail with comma in option label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Label must not contain a comma",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata MULTI_SELECT tests suite Update should fail with duplicated option ids 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Duplicated option id",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata MULTI_SELECT tests suite Update should fail with duplicated option positions 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Duplicated option position",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata MULTI_SELECT tests suite Update should fail with duplicated option values 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Duplicated option value",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata MULTI_SELECT tests suite Update should fail with duplicated trimmed option values 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Duplicated option value",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata MULTI_SELECT tests suite Update should fail with empty multi-select default values array 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "If defined default value must contain at least one value",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata MULTI_SELECT tests suite Update should fail with empty options 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Options are required for enum fields",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata MULTI_SELECT tests suite Update should fail with empty string defaultValue 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Default value for multi-select must be an array",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata MULTI_SELECT tests suite Update should fail with empty string id 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option id is invalid",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata MULTI_SELECT tests suite Update should fail with empty string label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option label "" is beneath 1 character",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata MULTI_SELECT tests suite Update should fail with empty string value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option value "" is beneath 1 character",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata MULTI_SELECT tests suite Update should fail with invalid multi-select default value format 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Default value should be as quoted string",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata MULTI_SELECT tests suite Update should fail with invalid option id 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option id is invalid",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata MULTI_SELECT tests suite Update should fail with invalid option value format 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Value must be in UPPER_CASE and follow snake_case "Option 1 and some other things, /"",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata MULTI_SELECT tests suite Update should fail with non stringified array default value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Default value for multi-select must be an array",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata MULTI_SELECT tests suite Update should fail with not a string defaultValue 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Default value for multi-select must be an array",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata MULTI_SELECT tests suite Update should fail with not a string id 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option id is invalid",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata MULTI_SELECT tests suite Update should fail with not a string label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "INTERNAL_SERVER_ERROR",
|
||||
"exceptionEventId": "mocked-exception-id",
|
||||
},
|
||||
"message": "label.includes is not a function",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata MULTI_SELECT tests suite Update should fail with not a string value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Value must be in UPPER_CASE and follow snake_case "22222"",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata MULTI_SELECT tests suite Update should fail with null id 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option id is required",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata MULTI_SELECT tests suite Update should fail with null label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option label is required",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata MULTI_SELECT tests suite Update should fail with null value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option value is required",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata MULTI_SELECT tests suite Update should fail with only white spaces defaultValue 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Default value for multi-select must be an array",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata MULTI_SELECT tests suite Update should fail with only white spaces id 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option id is invalid",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata MULTI_SELECT tests suite Update should fail with only white spaces label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option label "" is beneath 1 character",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata MULTI_SELECT tests suite Update should fail with only white spaces value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option value "" is beneath 1 character",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata MULTI_SELECT tests suite Update should fail with too long defaultValue 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Default value for multi-select must be an array",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata MULTI_SELECT tests suite Update should fail with too long id 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option id is invalid",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata MULTI_SELECT tests suite Update should fail with too long label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option label "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" exceeds 63 characters",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata MULTI_SELECT tests suite Update should fail with too long value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option value "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" exceeds 63 characters",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata MULTI_SELECT tests suite Update should fail with undefined option label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option label is required",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata MULTI_SELECT tests suite Update should fail with undefined option value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option value is required",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata MULTI_SELECT tests suite Update should fail with unknown default value and no options 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Default value "'OPTION_42'" must be one of the option values",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata MULTI_SELECT tests suite Update should fail with unknown multi-select default values 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Default value "'UNKNOWN_OPTION'" must be one of the option values",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata SELECT tests suite Update should fail with an invalid default value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Default value should be as quoted string",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata SELECT tests suite Update should fail with an unknown default value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Default value "'OPTION_424242'" must be one of the option values",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata SELECT tests suite Update should fail with comma in option label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Label must not contain a comma",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata SELECT tests suite Update should fail with duplicated option ids 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Duplicated option id",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata SELECT tests suite Update should fail with duplicated option positions 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Duplicated option position",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata SELECT tests suite Update should fail with duplicated option values 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Duplicated option value",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata SELECT tests suite Update should fail with duplicated trimmed option values 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Duplicated option value",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata SELECT tests suite Update should fail with empty options 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Options are required for enum fields",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata SELECT tests suite Update should fail with empty string defaultValue 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Default value should be as quoted string",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata SELECT tests suite Update should fail with empty string id 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option id is invalid",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata SELECT tests suite Update should fail with empty string label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option label "" is beneath 1 character",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata SELECT tests suite Update should fail with empty string value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option value "" is beneath 1 character",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata SELECT tests suite Update should fail with invalid option id 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option id is invalid",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata SELECT tests suite Update should fail with invalid option value format 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Value must be in UPPER_CASE and follow snake_case "Option 1 and some other things, /"",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata SELECT tests suite Update should fail with not a string defaultValue 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Default value for multi-select must be a stringified array",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata SELECT tests suite Update should fail with not a string id 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option id is invalid",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata SELECT tests suite Update should fail with not a string label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "INTERNAL_SERVER_ERROR",
|
||||
"exceptionEventId": "mocked-exception-id",
|
||||
},
|
||||
"message": "label.includes is not a function",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata SELECT tests suite Update should fail with not a string value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Value must be in UPPER_CASE and follow snake_case "22222"",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata SELECT tests suite Update should fail with null id 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option id is required",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata SELECT tests suite Update should fail with null label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option label is required",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata SELECT tests suite Update should fail with null value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option value is required",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata SELECT tests suite Update should fail with only white spaces defaultValue 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Default value should be as quoted string",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata SELECT tests suite Update should fail with only white spaces id 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option id is invalid",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata SELECT tests suite Update should fail with only white spaces label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option label "" is beneath 1 character",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata SELECT tests suite Update should fail with only white spaces value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option value "" is beneath 1 character",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata SELECT tests suite Update should fail with too long defaultValue 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Default value should be as quoted string",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata SELECT tests suite Update should fail with too long id 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option id is invalid",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata SELECT tests suite Update should fail with too long label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option label "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" exceeds 63 characters",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata SELECT tests suite Update should fail with too long value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option value "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" exceeds 63 characters",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata SELECT tests suite Update should fail with undefined option label 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option label is required",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata SELECT tests suite Update should fail with undefined option value 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Option value is required",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`Update field metadata SELECT tests suite Update should fail with unknown default value and no options 1`] = `
|
||||
[
|
||||
{
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Default value "'OPTION_42'" must be one of the option values",
|
||||
},
|
||||
]
|
||||
`;
|
||||
@ -0,0 +1,98 @@
|
||||
import { SELECT_AND_MULTI_SELECT_OPERATION_AGNOSTIC_SUCCESSFUL_AND_FAILING_TEST_CASES } from 'test/integration/metadata/suites/field-metadata/enum/common/select-and-multi-select-operation-agnostic-tests-cases';
|
||||
import { FieldMetadataEnumSuccessfulAndFailingTestCases } from 'test/integration/metadata/suites/field-metadata/enum/types/fieldMetadataEnumSuccessfulAndFailingTestCases';
|
||||
|
||||
export const MUTLI_SELECT_OPERATION_AGNOSTIC_TEST_CASES: FieldMetadataEnumSuccessfulAndFailingTestCases =
|
||||
{
|
||||
successful: [
|
||||
...SELECT_AND_MULTI_SELECT_OPERATION_AGNOSTIC_SUCCESSFUL_AND_FAILING_TEST_CASES.successful,
|
||||
{
|
||||
title: 'should succeed with valid multi-select default values',
|
||||
context: {
|
||||
input: {
|
||||
defaultValue: ["'OPTION_1'", "'OPTION_2'"],
|
||||
options: [
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: 'OPTION_1',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
},
|
||||
{
|
||||
label: 'Option 2',
|
||||
value: 'OPTION_2',
|
||||
color: 'blue',
|
||||
position: 2,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
failing: [
|
||||
...SELECT_AND_MULTI_SELECT_OPERATION_AGNOSTIC_SUCCESSFUL_AND_FAILING_TEST_CASES.failing,
|
||||
{
|
||||
title: 'should fail with non stringified array default value',
|
||||
context: {
|
||||
input: {
|
||||
defaultValue: 'Option_1',
|
||||
options: [
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: 'OPTION_1',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'should fail with empty multi-select default values array',
|
||||
context: {
|
||||
input: {
|
||||
defaultValue: [],
|
||||
options: [
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: 'OPTION_1',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'should fail with unknown multi-select default values',
|
||||
context: {
|
||||
input: {
|
||||
defaultValue: ["'OPTION_1'", "'UNKNOWN_OPTION'"],
|
||||
options: [
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: 'OPTION_1',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'should fail with invalid multi-select default value format',
|
||||
context: {
|
||||
input: {
|
||||
defaultValue: ['invalid', 'format'],
|
||||
options: [
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: 'OPTION_1',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
@ -0,0 +1,354 @@
|
||||
import { v4 } from 'uuid';
|
||||
import { FieldMetadataEnumSuccessfulAndFailingTestCases } from 'test/integration/metadata/suites/field-metadata/enum/types/fieldMetadataEnumSuccessfulAndFailingTestCases';
|
||||
import { UpdateCreateFieldMetadataSelectTestCase } from 'test/integration/metadata/suites/field-metadata/enum/types/update-create-field-metadata-enum-test-case';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
import { FieldMetadataComplexOption } from 'src/engine/metadata-modules/field-metadata/dtos/options.input';
|
||||
|
||||
const basicFailingStringEdgeCaseInputs: {
|
||||
label: string;
|
||||
input: string | undefined | number | null;
|
||||
}[] = [
|
||||
{ input: ' ', label: 'only white spaces' },
|
||||
{ input: '', label: 'empty string' },
|
||||
{ input: null, label: 'null' },
|
||||
{ input: 22222, label: 'not a string' },
|
||||
{ input: 'a'.repeat(64), label: 'too long' },
|
||||
];
|
||||
|
||||
const stringFields: (keyof FieldMetadataComplexOption)[] = [
|
||||
'id',
|
||||
'label',
|
||||
'value',
|
||||
];
|
||||
const fuzzedOptionsStringFieldFailingTestCases: UpdateCreateFieldMetadataSelectTestCase[] =
|
||||
stringFields.flatMap((field) => {
|
||||
return basicFailingStringEdgeCaseInputs.map<UpdateCreateFieldMetadataSelectTestCase>(
|
||||
({ input, label }) => ({
|
||||
title: `should fail with ${label} ${field}`,
|
||||
context: {
|
||||
input: {
|
||||
options: [
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: 'OPTION_1',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
[field]: input,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
const fuzzedDefaultValueFailingTestCases: UpdateCreateFieldMetadataSelectTestCase[] =
|
||||
basicFailingStringEdgeCaseInputs
|
||||
.filter((el) => isDefined(el.input))
|
||||
.map(({ input, label }) => ({
|
||||
title: `should fail with ${label} defaultValue`,
|
||||
context: {
|
||||
input: {
|
||||
defaultValue: input,
|
||||
options: [
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: 'OPTION_1',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
||||
export const SELECT_AND_MULTI_SELECT_OPERATION_AGNOSTIC_SUCCESSFUL_AND_FAILING_TEST_CASES: FieldMetadataEnumSuccessfulAndFailingTestCases =
|
||||
{
|
||||
failing: [
|
||||
...fuzzedDefaultValueFailingTestCases,
|
||||
...fuzzedOptionsStringFieldFailingTestCases,
|
||||
{
|
||||
title: 'should fail with invalid option id',
|
||||
context: {
|
||||
input: {
|
||||
options: [
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: 'OPTION_1',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
id: 'not a uuid',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'should fail with empty options',
|
||||
context: {
|
||||
input: {
|
||||
options: [],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'should fail with invalid option value format',
|
||||
context: {
|
||||
input: {
|
||||
options: [
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: 'Option 1 and some other things, /',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'should fail with comma in option label',
|
||||
context: {
|
||||
input: {
|
||||
options: [
|
||||
{
|
||||
label: 'Option ,1',
|
||||
value: 'OPTION_1',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'should fail with duplicated option values',
|
||||
context: {
|
||||
input: {
|
||||
options: [
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: 'OPTION_1',
|
||||
color: 'green',
|
||||
position: 0,
|
||||
},
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: 'OPTION_1',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'should fail with duplicated option ids',
|
||||
context: {
|
||||
input: {
|
||||
options: [
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: 'OPTION_1',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
id: 'fd1f11fd-3f05-4a33-bddf-800c3412ce98',
|
||||
},
|
||||
{
|
||||
label: 'Option 2',
|
||||
value: 'OPTION_2',
|
||||
color: 'green',
|
||||
position: 2,
|
||||
id: 'fd1f11fd-3f05-4a33-bddf-800c3412ce98',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'should fail with duplicated option positions',
|
||||
context: {
|
||||
input: {
|
||||
options: [
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: 'OPTION_1',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
},
|
||||
{
|
||||
label: 'Option 2',
|
||||
value: 'OPTION_2',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'should fail with duplicated trimmed option values',
|
||||
context: {
|
||||
input: {
|
||||
options: [
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: ' OPTION_1 ',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
},
|
||||
{
|
||||
label: 'Option 2',
|
||||
value: ' OPTION_1 ',
|
||||
color: 'green',
|
||||
position: 2,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'should fail with undefined option label',
|
||||
context: {
|
||||
input: {
|
||||
options: [
|
||||
{
|
||||
label: undefined as unknown as string,
|
||||
value: 'OPTION_1',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'should fail with an invalid default value',
|
||||
context: {
|
||||
input: {
|
||||
defaultValue: 'invalid',
|
||||
options: [
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: 'OPTION_1',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'should fail with an unknown default value',
|
||||
context: {
|
||||
input: {
|
||||
defaultValue: "'OPTION_424242'",
|
||||
options: [
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: 'OPTION_1',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'should fail with undefined option value',
|
||||
context: {
|
||||
input: {
|
||||
options: [
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: undefined as unknown as string,
|
||||
color: 'green',
|
||||
position: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
successful: [
|
||||
{
|
||||
title: 'should succeed with provided option id',
|
||||
context: {
|
||||
input: {
|
||||
options: [
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: 'OPTION_1',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
id: '26c602c3-cba9-4d83-92d4-4ba7dbae2f31',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'should succeed with various options id',
|
||||
context: {
|
||||
input: {
|
||||
options: Array.from({ length: 42 }, (_value, index) => {
|
||||
const optionWithoutId: FieldMetadataComplexOption = {
|
||||
label: `Option ${index}`,
|
||||
value: `OPTION_${index}`,
|
||||
color: 'green',
|
||||
position: index,
|
||||
};
|
||||
|
||||
if (index % 2 === 0) {
|
||||
return {
|
||||
...optionWithoutId,
|
||||
id: v4(),
|
||||
};
|
||||
}
|
||||
|
||||
return optionWithoutId;
|
||||
}),
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'should succeed without option id',
|
||||
context: {
|
||||
input: {
|
||||
options: [
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: 'OPTION_1',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'should trim option values',
|
||||
context: {
|
||||
input: {
|
||||
options: [
|
||||
{
|
||||
label: ' Option 1 ',
|
||||
value: ' OPTION_1 ',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
expectedOptions: [
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: 'OPTION_1',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
@ -0,0 +1,46 @@
|
||||
import { SELECT_AND_MULTI_SELECT_OPERATION_AGNOSTIC_SUCCESSFUL_AND_FAILING_TEST_CASES } from 'test/integration/metadata/suites/field-metadata/enum/common/select-and-multi-select-operation-agnostic-tests-cases';
|
||||
import { FieldMetadataEnumSuccessfulAndFailingTestCases } from 'test/integration/metadata/suites/field-metadata/enum/types/fieldMetadataEnumSuccessfulAndFailingTestCases';
|
||||
|
||||
export const SELECT_OPERATION_AGNOSTIC_TEST_CASES: FieldMetadataEnumSuccessfulAndFailingTestCases =
|
||||
{
|
||||
failing: [
|
||||
...SELECT_AND_MULTI_SELECT_OPERATION_AGNOSTIC_SUCCESSFUL_AND_FAILING_TEST_CASES.failing,
|
||||
],
|
||||
successful: [
|
||||
...SELECT_AND_MULTI_SELECT_OPERATION_AGNOSTIC_SUCCESSFUL_AND_FAILING_TEST_CASES.successful,
|
||||
{
|
||||
title: 'should succeed with valid default value',
|
||||
context: {
|
||||
input: {
|
||||
defaultValue: "'OPTION_1'",
|
||||
options: [
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: 'OPTION_1',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
id: '26c602c3-cba9-4d83-92d4-4ba7dbae2f31',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'should succeed with null default value',
|
||||
context: {
|
||||
input: {
|
||||
defaultValue: null,
|
||||
options: [
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: 'OPTION_1',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
id: '26c602c3-cba9-4d83-92d4-4ba7dbae2f31',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
@ -0,0 +1,49 @@
|
||||
import { MUTLI_SELECT_OPERATION_AGNOSTIC_TEST_CASES } from 'test/integration/metadata/suites/field-metadata/enum/common/multi-select-operation-agnostic-test-cases';
|
||||
import { SELECT_OPERATION_AGNOSTIC_TEST_CASES } from 'test/integration/metadata/suites/field-metadata/enum/common/select-operation-agnostic-test-cases';
|
||||
import { FieldMetadataEnumSuccessfulAndFailingTestCases } from 'test/integration/metadata/suites/field-metadata/enum/types/fieldMetadataEnumSuccessfulAndFailingTestCases';
|
||||
import { UpdateCreateFieldMetadataSelectTestCase } from 'test/integration/metadata/suites/field-metadata/enum/types/update-create-field-metadata-enum-test-case';
|
||||
|
||||
import { FieldMetadataComplexOption } from 'src/engine/metadata-modules/field-metadata/dtos/options.input';
|
||||
import { EnumFieldMetadataUnionType } from 'src/engine/metadata-modules/field-metadata/utils/is-enum-field-metadata-type.util';
|
||||
|
||||
const fieldMetadataTypeAgnosticCreateFailingTestCases: UpdateCreateFieldMetadataSelectTestCase[] =
|
||||
[
|
||||
{
|
||||
title: 'should fail with null options',
|
||||
context: {
|
||||
input: {
|
||||
options: null as unknown as FieldMetadataComplexOption[],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'should fail with undefined options',
|
||||
context: {
|
||||
input: {
|
||||
options: undefined as unknown as FieldMetadataComplexOption[],
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export const CREATE_ENUM_FIELD_METADATA_TEST_CASES: Partial<
|
||||
Record<
|
||||
EnumFieldMetadataUnionType,
|
||||
FieldMetadataEnumSuccessfulAndFailingTestCases
|
||||
>
|
||||
> = {
|
||||
MULTI_SELECT: {
|
||||
failing: [
|
||||
...MUTLI_SELECT_OPERATION_AGNOSTIC_TEST_CASES.failing,
|
||||
...fieldMetadataTypeAgnosticCreateFailingTestCases,
|
||||
],
|
||||
successful: [...MUTLI_SELECT_OPERATION_AGNOSTIC_TEST_CASES.successful],
|
||||
},
|
||||
SELECT: {
|
||||
failing: [
|
||||
...SELECT_OPERATION_AGNOSTIC_TEST_CASES.failing,
|
||||
...fieldMetadataTypeAgnosticCreateFailingTestCases,
|
||||
],
|
||||
successful: [...SELECT_OPERATION_AGNOSTIC_TEST_CASES.successful],
|
||||
},
|
||||
};
|
||||
@ -0,0 +1,116 @@
|
||||
import { createOneFieldMetadata } from 'test/integration/metadata/suites/field-metadata/utils/create-one-field-metadata.util';
|
||||
import {
|
||||
LISTING_NAME_PLURAL,
|
||||
LISTING_NAME_SINGULAR,
|
||||
} from 'test/integration/metadata/suites/object-metadata/constants/test-object-names.constant';
|
||||
import { deleteOneObjectMetadata } from 'test/integration/metadata/suites/object-metadata/utils/delete-one-object-metadata.util';
|
||||
import { forceCreateOneObjectMetadata } from 'test/integration/metadata/suites/object-metadata/utils/force-create-one-object-metadata.util';
|
||||
import { CREATE_ENUM_FIELD_METADATA_TEST_CASES } from 'test/integration/metadata/suites/field-metadata/enum/create-enum-field-metadata-test-cases';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
import {
|
||||
FieldMetadataComplexOption,
|
||||
FieldMetadataDefaultOption,
|
||||
} from 'src/engine/metadata-modules/field-metadata/dtos/options.input';
|
||||
import { fieldMetadataEnumTypes } from 'src/engine/metadata-modules/field-metadata/utils/is-enum-field-metadata-type.util';
|
||||
|
||||
describe.each(fieldMetadataEnumTypes)(
|
||||
'Create field metadata %s tests suite',
|
||||
(testedFieldMetadataType) => {
|
||||
let createdObjectMetadataId: string;
|
||||
const testCases =
|
||||
CREATE_ENUM_FIELD_METADATA_TEST_CASES[testedFieldMetadataType];
|
||||
|
||||
if (!isDefined(testCases)) {
|
||||
return;
|
||||
}
|
||||
const { failing: failingTestCases, successful: successfulTestCases } =
|
||||
testCases;
|
||||
|
||||
beforeEach(async () => {
|
||||
const { data } = await forceCreateOneObjectMetadata({
|
||||
input: {
|
||||
labelSingular: LISTING_NAME_SINGULAR,
|
||||
labelPlural: LISTING_NAME_PLURAL,
|
||||
nameSingular: LISTING_NAME_SINGULAR,
|
||||
namePlural: LISTING_NAME_PLURAL,
|
||||
icon: 'IconBuildingSkyscraper',
|
||||
isLabelSyncedWithName: false,
|
||||
},
|
||||
});
|
||||
|
||||
createdObjectMetadataId = data.createOneObject.id;
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await deleteOneObjectMetadata({
|
||||
input: { idToDelete: createdObjectMetadataId },
|
||||
});
|
||||
});
|
||||
|
||||
test.each(successfulTestCases)(
|
||||
'Create $title',
|
||||
async ({ context: { input, expectedOptions } }) => {
|
||||
const { data, errors } = await createOneFieldMetadata({
|
||||
input: {
|
||||
objectMetadataId: createdObjectMetadataId,
|
||||
type: testedFieldMetadataType,
|
||||
name: 'testField',
|
||||
label: 'Test Field',
|
||||
isLabelSyncedWithName: false,
|
||||
...input,
|
||||
},
|
||||
gqlFields: `
|
||||
id
|
||||
options
|
||||
defaultValue
|
||||
type
|
||||
`,
|
||||
});
|
||||
|
||||
expect(data).not.toBeNull();
|
||||
expect(data.createOneField).toBeDefined();
|
||||
expect(data.createOneField.type).toEqual(testedFieldMetadataType);
|
||||
const createdOptions:
|
||||
| FieldMetadataDefaultOption[]
|
||||
| FieldMetadataComplexOption[] = data.createOneField.options;
|
||||
|
||||
const optionsToCompare = expectedOptions ?? input.options;
|
||||
|
||||
expect(errors).toBeUndefined();
|
||||
expect(createdOptions.length).toBe(optionsToCompare.length);
|
||||
createdOptions.forEach((option) => expect(option.id).toBeDefined());
|
||||
expect(createdOptions).toMatchObject(optionsToCompare);
|
||||
|
||||
if (isDefined(input.defaultValue)) {
|
||||
expect(data.createOneField.defaultValue).toEqual(input.defaultValue);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
test.each(failingTestCases)(
|
||||
'Create $title',
|
||||
async ({ context: { input } }) => {
|
||||
const { data, errors } = await createOneFieldMetadata({
|
||||
input: {
|
||||
objectMetadataId: createdObjectMetadataId,
|
||||
type: testedFieldMetadataType,
|
||||
name: 'testField',
|
||||
label: 'Test Field',
|
||||
isLabelSyncedWithName: false,
|
||||
...input,
|
||||
},
|
||||
gqlFields: `
|
||||
id
|
||||
options
|
||||
defaultValue
|
||||
`,
|
||||
});
|
||||
|
||||
expect(data).toBeNull();
|
||||
expect(errors).toBeDefined();
|
||||
expect(errors).toMatchSnapshot();
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
@ -0,0 +1,7 @@
|
||||
import { UpdateCreateFieldMetadataSelectTestCase } from 'test/integration/metadata/suites/field-metadata/enum/types/update-create-field-metadata-enum-test-case';
|
||||
import { SuccessfulAndFailingTestCases } from 'twenty-shared/testing';
|
||||
|
||||
export type FieldMetadataEnumSuccessfulAndFailingTestCases =
|
||||
SuccessfulAndFailingTestCases<
|
||||
UpdateCreateFieldMetadataSelectTestCase['context']
|
||||
>;
|
||||
@ -0,0 +1,10 @@
|
||||
import { CreateOneFieldFactoryInput } from 'test/integration/metadata/suites/field-metadata/utils/create-one-field-metadata-query-factory.util';
|
||||
import { EachTestingContext } from 'twenty-shared/testing';
|
||||
|
||||
import { FieldMetadataComplexOption } from 'src/engine/metadata-modules/field-metadata/dtos/options.input';
|
||||
|
||||
export type UpdateCreateFieldMetadataSelectTestCase = EachTestingContext<{
|
||||
input: Partial<Pick<CreateOneFieldFactoryInput, 'defaultValue'>> &
|
||||
Required<Pick<CreateOneFieldFactoryInput, 'options'>>;
|
||||
expectedOptions?: FieldMetadataComplexOption[];
|
||||
}>;
|
||||
@ -0,0 +1,94 @@
|
||||
import { MUTLI_SELECT_OPERATION_AGNOSTIC_TEST_CASES } from 'test/integration/metadata/suites/field-metadata/enum/common/multi-select-operation-agnostic-test-cases';
|
||||
import { SELECT_OPERATION_AGNOSTIC_TEST_CASES } from 'test/integration/metadata/suites/field-metadata/enum/common/select-operation-agnostic-test-cases';
|
||||
import { FieldMetadataEnumSuccessfulAndFailingTestCases } from 'test/integration/metadata/suites/field-metadata/enum/types/fieldMetadataEnumSuccessfulAndFailingTestCases';
|
||||
|
||||
import { FieldMetadataComplexOption } from 'src/engine/metadata-modules/field-metadata/dtos/options.input';
|
||||
import { EnumFieldMetadataUnionType } from 'src/engine/metadata-modules/field-metadata/utils/is-enum-field-metadata-type.util';
|
||||
|
||||
export const UPDATE_ENUM_FIELD_METADATA_TEST_CASES: Partial<
|
||||
Record<
|
||||
EnumFieldMetadataUnionType,
|
||||
FieldMetadataEnumSuccessfulAndFailingTestCases
|
||||
>
|
||||
> = {
|
||||
MULTI_SELECT: {
|
||||
failing: [
|
||||
...MUTLI_SELECT_OPERATION_AGNOSTIC_TEST_CASES.failing,
|
||||
{
|
||||
title: 'should fail with unknown default value and no options',
|
||||
context: {
|
||||
input: {
|
||||
defaultValue: ["'OPTION_42'"],
|
||||
options: undefined as unknown as FieldMetadataComplexOption[],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
successful: [
|
||||
...MUTLI_SELECT_OPERATION_AGNOSTIC_TEST_CASES.successful,
|
||||
{
|
||||
title: 'should succeed with default value and no options',
|
||||
context: {
|
||||
input: {
|
||||
defaultValue: ["'OPTION_2'"],
|
||||
options: undefined as unknown as FieldMetadataComplexOption[],
|
||||
},
|
||||
expectedOptions: [
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: 'OPTION_1',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
},
|
||||
{
|
||||
label: 'Option 2',
|
||||
value: 'OPTION_2',
|
||||
color: 'green',
|
||||
position: 2,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
SELECT: {
|
||||
failing: [
|
||||
...SELECT_OPERATION_AGNOSTIC_TEST_CASES.failing,
|
||||
{
|
||||
title: 'should fail with unknown default value and no options',
|
||||
context: {
|
||||
input: {
|
||||
defaultValue: "'OPTION_42'",
|
||||
options: undefined as unknown as FieldMetadataComplexOption[],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
successful: [
|
||||
...SELECT_OPERATION_AGNOSTIC_TEST_CASES.successful,
|
||||
{
|
||||
title: 'should succeed with default value and no options',
|
||||
context: {
|
||||
input: {
|
||||
defaultValue: "'OPTION_2'",
|
||||
options: undefined as unknown as FieldMetadataComplexOption[],
|
||||
},
|
||||
expectedOptions: [
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: 'OPTION_1',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
},
|
||||
{
|
||||
label: 'Option 2',
|
||||
value: 'OPTION_2',
|
||||
color: 'green',
|
||||
position: 2,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@ -0,0 +1,228 @@
|
||||
import { UPDATE_ENUM_FIELD_METADATA_TEST_CASES } from 'test/integration/metadata/suites/field-metadata/enum/update-enum-field-metadata-test-cases';
|
||||
import { CreateOneFieldFactoryInput } from 'test/integration/metadata/suites/field-metadata/utils/create-one-field-metadata-query-factory.util';
|
||||
import { createOneFieldMetadata } from 'test/integration/metadata/suites/field-metadata/utils/create-one-field-metadata.util';
|
||||
import { updateOneFieldMetadata } from 'test/integration/metadata/suites/field-metadata/utils/update-one-field-metadata.util';
|
||||
import {
|
||||
LISTING_NAME_PLURAL,
|
||||
LISTING_NAME_SINGULAR,
|
||||
} from 'test/integration/metadata/suites/object-metadata/constants/test-object-names.constant';
|
||||
import { createOneObjectMetadata } from 'test/integration/metadata/suites/object-metadata/utils/create-one-object-metadata.util';
|
||||
import { deleteOneObjectMetadata } from 'test/integration/metadata/suites/object-metadata/utils/delete-one-object-metadata.util';
|
||||
import { FieldMetadataType } from 'twenty-shared/types';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
import {
|
||||
FieldMetadataComplexOption,
|
||||
FieldMetadataDefaultOption,
|
||||
} from 'src/engine/metadata-modules/field-metadata/dtos/options.input';
|
||||
import { fieldMetadataEnumTypes } from 'src/engine/metadata-modules/field-metadata/utils/is-enum-field-metadata-type.util';
|
||||
|
||||
describe.each(fieldMetadataEnumTypes)(
|
||||
'Update field metadata %s tests suite',
|
||||
(testedFieldMetadataType) => {
|
||||
let createdObjectMetadataId: string;
|
||||
const testCases =
|
||||
UPDATE_ENUM_FIELD_METADATA_TEST_CASES[testedFieldMetadataType];
|
||||
|
||||
if (!isDefined(testCases)) {
|
||||
return;
|
||||
}
|
||||
const { failing: failingTestCases, successful: successfulTestCases } =
|
||||
testCases;
|
||||
const initialOptions: CreateOneFieldFactoryInput['options'] = [
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: 'OPTION_1',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
},
|
||||
{
|
||||
label: 'Option 2',
|
||||
value: 'OPTION_2',
|
||||
color: 'green',
|
||||
position: 2,
|
||||
},
|
||||
];
|
||||
|
||||
beforeEach(async () => {
|
||||
const { data } = await createOneObjectMetadata({
|
||||
input: {
|
||||
labelSingular: LISTING_NAME_SINGULAR,
|
||||
labelPlural: LISTING_NAME_PLURAL,
|
||||
nameSingular: LISTING_NAME_SINGULAR,
|
||||
namePlural: LISTING_NAME_PLURAL,
|
||||
icon: 'IconBuildingSkyscraper',
|
||||
isLabelSyncedWithName: false,
|
||||
},
|
||||
});
|
||||
|
||||
createdObjectMetadataId = data.createOneObject.id;
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await deleteOneObjectMetadata({
|
||||
input: { idToDelete: createdObjectMetadataId },
|
||||
});
|
||||
});
|
||||
|
||||
it('Should update default value to null even if it was set before', async () => {
|
||||
const {
|
||||
data: { createOneField },
|
||||
} = await createOneFieldMetadata({
|
||||
input: {
|
||||
objectMetadataId: createdObjectMetadataId,
|
||||
type: testedFieldMetadataType,
|
||||
name: 'testField',
|
||||
label: 'Test Field',
|
||||
isLabelSyncedWithName: false,
|
||||
options: initialOptions,
|
||||
},
|
||||
gqlFields: `
|
||||
id
|
||||
type
|
||||
`,
|
||||
});
|
||||
|
||||
const createdFieldMetadata = createOneField.id;
|
||||
const isMultiSelect =
|
||||
testedFieldMetadataType === FieldMetadataType.MULTI_SELECT;
|
||||
const rawDefaultValue = `'${initialOptions[0].value}'`;
|
||||
const expectedDefaultValue = isMultiSelect
|
||||
? [rawDefaultValue]
|
||||
: rawDefaultValue;
|
||||
|
||||
const { data: firstUpdate } = await updateOneFieldMetadata({
|
||||
input: {
|
||||
idToUpdate: createdFieldMetadata,
|
||||
updatePayload: {
|
||||
defaultValue: expectedDefaultValue,
|
||||
},
|
||||
},
|
||||
gqlFields: `
|
||||
id
|
||||
defaultValue
|
||||
`,
|
||||
});
|
||||
|
||||
expect(firstUpdate.updateOneField.defaultValue).toEqual(
|
||||
expectedDefaultValue,
|
||||
);
|
||||
|
||||
const updatedOptions = initialOptions.slice(1);
|
||||
const { data: secondUpdate, errors } = await updateOneFieldMetadata({
|
||||
input: {
|
||||
idToUpdate: createdFieldMetadata,
|
||||
updatePayload: {
|
||||
defaultValue: null,
|
||||
options: updatedOptions,
|
||||
},
|
||||
},
|
||||
gqlFields: `
|
||||
id
|
||||
options
|
||||
defaultValue
|
||||
`,
|
||||
});
|
||||
|
||||
expect(errors).toBeUndefined();
|
||||
expect(secondUpdate.updateOneField.defaultValue).toBeNull();
|
||||
expect(secondUpdate.updateOneField.options).toMatchObject(updatedOptions);
|
||||
});
|
||||
|
||||
test.each(successfulTestCases)(
|
||||
'Update $title',
|
||||
async ({ context: { input, expectedOptions } }) => {
|
||||
const {
|
||||
data: { createOneField },
|
||||
} = await createOneFieldMetadata({
|
||||
input: {
|
||||
objectMetadataId: createdObjectMetadataId,
|
||||
type: testedFieldMetadataType,
|
||||
name: 'testField',
|
||||
label: 'Test Field',
|
||||
isLabelSyncedWithName: false,
|
||||
options: initialOptions,
|
||||
},
|
||||
gqlFields: `
|
||||
id
|
||||
type
|
||||
`,
|
||||
});
|
||||
|
||||
const createdFieldMetadata = createOneField.id;
|
||||
|
||||
const { ...updatePayload } = input;
|
||||
|
||||
const { data, errors } = await updateOneFieldMetadata({
|
||||
input: {
|
||||
idToUpdate: createdFieldMetadata,
|
||||
updatePayload,
|
||||
},
|
||||
gqlFields: `
|
||||
id
|
||||
options
|
||||
defaultValue
|
||||
`,
|
||||
});
|
||||
|
||||
expect(data.updateOneField).toBeDefined();
|
||||
const updatedOptions:
|
||||
| FieldMetadataComplexOption[]
|
||||
| FieldMetadataDefaultOption[] = data.updateOneField.options;
|
||||
|
||||
expect(errors).toBeUndefined();
|
||||
updatedOptions.forEach((option) => expect(option.id).toBeDefined());
|
||||
|
||||
const optionsToCompare = expectedOptions ?? input.options;
|
||||
|
||||
expect(updatedOptions.length).toBe(optionsToCompare.length);
|
||||
expect(updatedOptions).toMatchObject(optionsToCompare);
|
||||
|
||||
if (isDefined(input.defaultValue)) {
|
||||
expect(data.updateOneField.defaultValue).toEqual(input.defaultValue);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
test.each(failingTestCases)(
|
||||
'Update $title',
|
||||
async ({ context: { input } }) => {
|
||||
const {
|
||||
data: { createOneField },
|
||||
} = await createOneFieldMetadata({
|
||||
input: {
|
||||
objectMetadataId: createdObjectMetadataId,
|
||||
type: testedFieldMetadataType,
|
||||
name: 'testField',
|
||||
label: 'Test Field',
|
||||
isLabelSyncedWithName: false,
|
||||
options: initialOptions,
|
||||
},
|
||||
gqlFields: `
|
||||
id
|
||||
type
|
||||
`,
|
||||
});
|
||||
|
||||
const createdFieldMetadata = createOneField.id;
|
||||
|
||||
const { ...updatePayload } = input;
|
||||
|
||||
const { data, errors } = await updateOneFieldMetadata({
|
||||
input: {
|
||||
idToUpdate: createdFieldMetadata,
|
||||
updatePayload,
|
||||
},
|
||||
gqlFields: `
|
||||
id
|
||||
options
|
||||
`,
|
||||
});
|
||||
|
||||
expect(data).toBeNull();
|
||||
expect(errors).toBeDefined();
|
||||
expect(errors).toMatchSnapshot();
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
@ -1,374 +0,0 @@
|
||||
import { CreateOneFieldFactoryInput } from 'test/integration/metadata/suites/field-metadata/utils/create-one-field-metadata-query-factory.util';
|
||||
import { EachTestingContext } from 'twenty-shared/testing';
|
||||
import { v4 } from 'uuid';
|
||||
|
||||
import { FieldMetadataComplexOption } from 'src/engine/metadata-modules/field-metadata/dtos/options.input';
|
||||
|
||||
export type UpdateCreateFieldMetadataSelectTestCase = EachTestingContext<{
|
||||
input: Partial<CreateOneFieldFactoryInput> &
|
||||
Required<Pick<CreateOneFieldFactoryInput, 'options'>>;
|
||||
expectedOptions?: FieldMetadataComplexOption[];
|
||||
}>;
|
||||
|
||||
const successfulTestCases: UpdateCreateFieldMetadataSelectTestCase[] = [
|
||||
{
|
||||
title: 'should succeed with provided option id',
|
||||
context: {
|
||||
input: {
|
||||
options: [
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: 'OPTION_1',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
id: '26c602c3-cba9-4d83-92d4-4ba7dbae2f31',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'should succeed with valid default value',
|
||||
context: {
|
||||
input: {
|
||||
defaultValue: "'OPTION_1'",
|
||||
options: [
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: 'OPTION_1',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
id: '26c602c3-cba9-4d83-92d4-4ba7dbae2f31',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'should succeed with various options id',
|
||||
context: {
|
||||
input: {
|
||||
options: Array.from({ length: 42 }, (_value, index) => {
|
||||
const optionWithoutId: FieldMetadataComplexOption = {
|
||||
label: `Option ${index}`,
|
||||
value: `OPTION_${index}`,
|
||||
color: 'green',
|
||||
position: index,
|
||||
};
|
||||
|
||||
if (index % 2 === 0) {
|
||||
return {
|
||||
...optionWithoutId,
|
||||
id: v4(),
|
||||
};
|
||||
}
|
||||
|
||||
return optionWithoutId;
|
||||
}),
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'should succeed without option id',
|
||||
context: {
|
||||
input: {
|
||||
options: [
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: 'OPTION_1',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'should trim option values',
|
||||
context: {
|
||||
input: {
|
||||
options: [
|
||||
{
|
||||
label: ' Option 1 ',
|
||||
value: ' OPTION_1 ',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
expectedOptions: [
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: 'OPTION_1',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'should succeed with null default value',
|
||||
context: {
|
||||
input: {
|
||||
defaultValue: null,
|
||||
options: [
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: 'OPTION_1',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
id: '26c602c3-cba9-4d83-92d4-4ba7dbae2f31',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const basicFailingStringEdgeCaseInputs: {
|
||||
label: string;
|
||||
input: string | undefined | number | null;
|
||||
}[] = [
|
||||
{ input: ' ', label: 'only white spaces' },
|
||||
{ input: '', label: 'empty string' },
|
||||
{ input: null, label: 'null' },
|
||||
{ input: 22222, label: 'not a string' },
|
||||
{ input: 'a'.repeat(64), label: 'too long' },
|
||||
];
|
||||
|
||||
const stringFields: (keyof FieldMetadataComplexOption)[] = [
|
||||
'id',
|
||||
'label',
|
||||
'value',
|
||||
];
|
||||
const autoGeneratedStringFailingTestsCases: UpdateCreateFieldMetadataSelectTestCase[] =
|
||||
stringFields.flatMap((field) => {
|
||||
return basicFailingStringEdgeCaseInputs.map<UpdateCreateFieldMetadataSelectTestCase>(
|
||||
({ input, label }) => ({
|
||||
title: `should fail with ${label} ${field}`,
|
||||
context: {
|
||||
input: {
|
||||
options: [
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: 'OPTION_1',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
[field]: input,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
});
|
||||
const failingTestCases: UpdateCreateFieldMetadataSelectTestCase[] = [
|
||||
...autoGeneratedStringFailingTestsCases,
|
||||
{
|
||||
title: 'should fail with invalid option id',
|
||||
context: {
|
||||
input: {
|
||||
options: [
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: 'OPTION_1',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
id: 'not a uuid',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'should fail with empty options',
|
||||
context: {
|
||||
input: {
|
||||
options: [],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'should fail with invalid option value format',
|
||||
context: {
|
||||
input: {
|
||||
options: [
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: 'Option 1 and some other things, /',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'should fail with comma in option label',
|
||||
context: {
|
||||
input: {
|
||||
options: [
|
||||
{
|
||||
label: 'Option ,1',
|
||||
value: 'OPTION_1',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'should fail with duplicated option values',
|
||||
context: {
|
||||
input: {
|
||||
options: [
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: 'OPTION_1',
|
||||
color: 'green',
|
||||
position: 0,
|
||||
},
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: 'OPTION_1',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'should fail with duplicated option ids',
|
||||
context: {
|
||||
input: {
|
||||
options: [
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: 'OPTION_1',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
id: 'fd1f11fd-3f05-4a33-bddf-800c3412ce98',
|
||||
},
|
||||
{
|
||||
label: 'Option 2',
|
||||
value: 'OPTION_2',
|
||||
color: 'green',
|
||||
position: 2,
|
||||
id: 'fd1f11fd-3f05-4a33-bddf-800c3412ce98',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'should fail with duplicated option positions',
|
||||
context: {
|
||||
input: {
|
||||
options: [
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: 'OPTION_1',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
},
|
||||
{
|
||||
label: 'Option 2',
|
||||
value: 'OPTION_2',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'should fail with duplicated trimmed option values',
|
||||
context: {
|
||||
input: {
|
||||
options: [
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: ' OPTION_1 ',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
},
|
||||
{
|
||||
label: 'Option 2',
|
||||
value: ' OPTION_1 ',
|
||||
color: 'green',
|
||||
position: 2,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'should fail with undefined option label',
|
||||
context: {
|
||||
input: {
|
||||
options: [
|
||||
{
|
||||
label: undefined as unknown as string,
|
||||
value: 'OPTION_1',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'should fail with an invalid default value',
|
||||
context: {
|
||||
input: {
|
||||
defaultValue: 'invalid',
|
||||
options: [
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: 'OPTION_1',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'should fail with an unknown default value',
|
||||
context: {
|
||||
input: {
|
||||
defaultValue: "'OPTION_424242'",
|
||||
options: [
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: 'OPTION_1',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'should fail with undefined option value',
|
||||
context: {
|
||||
input: {
|
||||
options: [
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: undefined as unknown as string,
|
||||
color: 'green',
|
||||
position: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export const UPDATE_CREATE_ONE_FIELD_METADATA_SELECT_TEST_CASES = {
|
||||
successfulTestCases,
|
||||
failingTestCases,
|
||||
};
|
||||
@ -1,202 +0,0 @@
|
||||
import {
|
||||
UPDATE_CREATE_ONE_FIELD_METADATA_SELECT_TEST_CASES,
|
||||
UpdateCreateFieldMetadataSelectTestCase,
|
||||
} from 'test/integration/metadata/suites/field-metadata/update-create-one-field-metadata-select-tests-cases';
|
||||
import { CreateOneFieldFactoryInput } from 'test/integration/metadata/suites/field-metadata/utils/create-one-field-metadata-query-factory.util';
|
||||
import { createOneFieldMetadata } from 'test/integration/metadata/suites/field-metadata/utils/create-one-field-metadata.util';
|
||||
import { updateOneFieldMetadata } from 'test/integration/metadata/suites/field-metadata/utils/update-one-field-metadata.util';
|
||||
import {
|
||||
LISTING_NAME_PLURAL,
|
||||
LISTING_NAME_SINGULAR,
|
||||
} from 'test/integration/metadata/suites/object-metadata/constants/test-object-names.constant';
|
||||
import { createOneObjectMetadata } from 'test/integration/metadata/suites/object-metadata/utils/create-one-object-metadata.util';
|
||||
import { deleteOneObjectMetadata } from 'test/integration/metadata/suites/object-metadata/utils/delete-one-object-metadata.util';
|
||||
import { FieldMetadataType } from 'twenty-shared/types';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
import {
|
||||
FieldMetadataComplexOption,
|
||||
FieldMetadataDefaultOption,
|
||||
} from 'src/engine/metadata-modules/field-metadata/dtos/options.input';
|
||||
|
||||
const { failingTestCases, successfulTestCases } =
|
||||
UPDATE_CREATE_ONE_FIELD_METADATA_SELECT_TEST_CASES;
|
||||
|
||||
describe('Field metadata select update tests group', () => {
|
||||
let createdObjectMetadataId: string;
|
||||
let createdFieldMetadata: string;
|
||||
const initialOptions: CreateOneFieldFactoryInput['options'] = [
|
||||
{
|
||||
label: 'Option 1',
|
||||
value: 'OPTION_1',
|
||||
color: 'green',
|
||||
position: 1,
|
||||
},
|
||||
{
|
||||
label: 'Option 2',
|
||||
value: 'OPTION_2',
|
||||
color: 'green',
|
||||
position: 2,
|
||||
},
|
||||
];
|
||||
|
||||
beforeEach(async () => {
|
||||
const { data } = await createOneObjectMetadata({
|
||||
input: {
|
||||
labelSingular: LISTING_NAME_SINGULAR,
|
||||
labelPlural: LISTING_NAME_PLURAL,
|
||||
nameSingular: LISTING_NAME_SINGULAR,
|
||||
namePlural: LISTING_NAME_PLURAL,
|
||||
icon: 'IconBuildingSkyscraper',
|
||||
isLabelSyncedWithName: false,
|
||||
},
|
||||
});
|
||||
|
||||
createdObjectMetadataId = data.createOneObject.id;
|
||||
|
||||
const {
|
||||
data: { createOneField },
|
||||
} = await createOneFieldMetadata({
|
||||
input: {
|
||||
objectMetadataId: createdObjectMetadataId,
|
||||
type: FieldMetadataType.SELECT,
|
||||
name: 'testField',
|
||||
label: 'Test Field',
|
||||
isLabelSyncedWithName: false,
|
||||
options: initialOptions,
|
||||
},
|
||||
gqlFields: `
|
||||
id
|
||||
`,
|
||||
});
|
||||
|
||||
createdFieldMetadata = createOneField.id;
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await deleteOneObjectMetadata({
|
||||
input: { idToDelete: createdObjectMetadataId },
|
||||
});
|
||||
});
|
||||
|
||||
it('Should update default value to null even if it was set before', async () => {
|
||||
const expectedDefaultValue = `'${initialOptions[0].value}'`;
|
||||
const { data: firstUdpate } = await updateOneFieldMetadata({
|
||||
input: {
|
||||
idToUpdate: createdFieldMetadata,
|
||||
updatePayload: {
|
||||
defaultValue: expectedDefaultValue,
|
||||
},
|
||||
},
|
||||
gqlFields: `
|
||||
id
|
||||
defaultValue
|
||||
`,
|
||||
});
|
||||
|
||||
expect(firstUdpate.updateOneField.defaultValue).toEqual(
|
||||
expectedDefaultValue,
|
||||
);
|
||||
|
||||
const updatedOptions = initialOptions.slice(1);
|
||||
const { data: secondUpdate, errors } = await updateOneFieldMetadata({
|
||||
input: {
|
||||
idToUpdate: createdFieldMetadata,
|
||||
updatePayload: {
|
||||
defaultValue: null,
|
||||
options: updatedOptions,
|
||||
},
|
||||
},
|
||||
gqlFields: `
|
||||
id
|
||||
options
|
||||
defaultValue
|
||||
`,
|
||||
});
|
||||
|
||||
expect(errors).toBeUndefined();
|
||||
expect(secondUpdate.updateOneField.defaultValue).toBeNull();
|
||||
expect(secondUpdate.updateOneField.options).toMatchObject(updatedOptions);
|
||||
});
|
||||
|
||||
const updateSpecificSuccessfulTestCases: UpdateCreateFieldMetadataSelectTestCase[] =
|
||||
[
|
||||
{
|
||||
title: 'should succeed with default value and no options',
|
||||
context: {
|
||||
input: {
|
||||
defaultValue: "'OPTION_2'",
|
||||
options: undefined as unknown as FieldMetadataComplexOption[],
|
||||
},
|
||||
expectedOptions: initialOptions,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
test.each([...successfulTestCases, ...updateSpecificSuccessfulTestCases])(
|
||||
'Update $title',
|
||||
async ({ context: { input, expectedOptions } }) => {
|
||||
const { data, errors } = await updateOneFieldMetadata({
|
||||
input: {
|
||||
idToUpdate: createdFieldMetadata,
|
||||
updatePayload: input,
|
||||
},
|
||||
gqlFields: `
|
||||
id
|
||||
options
|
||||
defaultValue
|
||||
`,
|
||||
});
|
||||
|
||||
expect(data.updateOneField).toBeDefined();
|
||||
const updatedOptions:
|
||||
| FieldMetadataComplexOption[]
|
||||
| FieldMetadataDefaultOption[] = data.updateOneField.options;
|
||||
|
||||
expect(errors).toBeUndefined();
|
||||
updatedOptions.forEach((option) => expect(option.id).toBeDefined());
|
||||
|
||||
const optionsToCompare = expectedOptions ?? input.options;
|
||||
|
||||
expect(updatedOptions.length).toBe(optionsToCompare.length);
|
||||
expect(updatedOptions).toMatchObject(optionsToCompare);
|
||||
|
||||
if (isDefined(input.defaultValue)) {
|
||||
expect(data.updateOneField.defaultValue).toEqual(input.defaultValue);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
const updateSpecificFailingTestCases: UpdateCreateFieldMetadataSelectTestCase[] =
|
||||
[
|
||||
{
|
||||
title: 'should fail with unknown default value and no options',
|
||||
context: {
|
||||
input: {
|
||||
defaultValue: "'OPTION_42'",
|
||||
options: undefined as unknown as FieldMetadataComplexOption[],
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
test.each([...updateSpecificFailingTestCases, ...failingTestCases])(
|
||||
'Update $title',
|
||||
async ({ context: { input } }) => {
|
||||
const { data, errors } = await updateOneFieldMetadata({
|
||||
input: {
|
||||
idToUpdate: createdFieldMetadata,
|
||||
updatePayload: input,
|
||||
},
|
||||
gqlFields: `
|
||||
id
|
||||
options
|
||||
`,
|
||||
});
|
||||
|
||||
expect(data).toBeNull();
|
||||
expect(errors).toBeDefined();
|
||||
expect(errors).toMatchSnapshot();
|
||||
},
|
||||
);
|
||||
});
|
||||
@ -164,7 +164,7 @@ describe('updateOne', () => {
|
||||
input: {
|
||||
idToUpdate: createdFieldMetadata.createOneField.id,
|
||||
updatePayload: {
|
||||
defaultValue: 'OPTION_2',
|
||||
defaultValue: "'OPTION_2'",
|
||||
},
|
||||
},
|
||||
gqlFields: `
|
||||
@ -182,7 +182,7 @@ describe('updateOne', () => {
|
||||
"extensions": {
|
||||
"code": "BAD_USER_INPUT",
|
||||
},
|
||||
"message": "Default value for existing options is invalid: OPTION_2",
|
||||
"message": "Default value "'OPTION_2'" must be one of the option values",
|
||||
},
|
||||
]
|
||||
`);
|
||||
|
||||
Reference in New Issue
Block a user