## Context - Removing search* integration tests instead of fixing them because they will be replaced by global search very soon - Fixed billing + add missing seeds to make them work - Fixed integration tests not using consistently the correct "test" db - Fixed ci not running the with-db-reset configuration due to nx configuration being used twice for different level of the command - Enriched .env.test - Fixed parts where exceptions were not thrown properly and not caught by exception handler to convert to 400 when needed - Refactored feature flag service that had 2 different implementations in lab and admin panel + added tests - Fixed race condition when migrations are created at the same timestamp and doing the same type of operation, in this case object deletion could break because table could be deleted earlier than its relations - Fixed many integration tests that were not up to date since the CI has been broken for a while --------- Co-authored-by: Charles Bochet <charlesBochet@users.noreply.github.com>
106 lines
3.2 KiB
TypeScript
106 lines
3.2 KiB
TypeScript
import { createOneFieldMetadataFactory } from 'test/integration/metadata/suites/field-metadata/utils/create-one-field-metadata-factory.util';
|
|
import { createListingCustomObject } from 'test/integration/metadata/suites/object-metadata/utils/create-test-object-metadata.util';
|
|
import { deleteOneObjectMetadataItem } from 'test/integration/metadata/suites/object-metadata/utils/delete-one-object-metadata.util';
|
|
import { makeMetadataAPIRequest } from 'test/integration/metadata/suites/utils/make-metadata-api-request.util';
|
|
import { FieldMetadataType } from 'twenty-shared';
|
|
|
|
describe('createOne', () => {
|
|
describe('FieldMetadataService name/label sync', () => {
|
|
let listingObjectId = '';
|
|
|
|
beforeEach(async () => {
|
|
const { objectMetadataId: createdObjectId } =
|
|
await createListingCustomObject();
|
|
|
|
listingObjectId = createdObjectId;
|
|
});
|
|
afterEach(async () => {
|
|
await deleteOneObjectMetadataItem(listingObjectId);
|
|
});
|
|
it('should create a field when name and label are synced correctly', async () => {
|
|
// Arrange
|
|
const FIELD_NAME = 'testField';
|
|
const createFieldInput = {
|
|
name: FIELD_NAME,
|
|
label: 'Test Field',
|
|
type: FieldMetadataType.TEXT,
|
|
objectMetadataId: listingObjectId,
|
|
isLabelSyncedWithName: true,
|
|
};
|
|
|
|
// Act
|
|
const graphqlOperation = createOneFieldMetadataFactory({
|
|
input: { field: createFieldInput },
|
|
gqlFields: `
|
|
id
|
|
name
|
|
label
|
|
isLabelSyncedWithName
|
|
`,
|
|
});
|
|
|
|
const response = await makeMetadataAPIRequest(graphqlOperation);
|
|
|
|
// Assert
|
|
expect(response.body.data.createOneField.name).toBe(FIELD_NAME);
|
|
});
|
|
|
|
it('should set isLabelSyncWithName to false if not in input', async () => {
|
|
// Arrange
|
|
const createFieldInput = {
|
|
name: 'testField',
|
|
label: 'Test Field',
|
|
type: FieldMetadataType.TEXT,
|
|
objectMetadataId: listingObjectId,
|
|
};
|
|
|
|
// Act
|
|
const graphqlOperation = createOneFieldMetadataFactory({
|
|
input: { field: createFieldInput },
|
|
gqlFields: `
|
|
id
|
|
name
|
|
label
|
|
isLabelSyncedWithName
|
|
`,
|
|
});
|
|
|
|
const response = await makeMetadataAPIRequest(graphqlOperation);
|
|
|
|
// Assert
|
|
expect(response.body.data.createOneField.isLabelSyncedWithName).toBe(
|
|
false,
|
|
);
|
|
});
|
|
|
|
it('should return an error when name and label are not synced but isLabelSyncedWithName is true', async () => {
|
|
// Arrange
|
|
const createFieldInput = {
|
|
name: 'testField',
|
|
label: 'Different Label',
|
|
type: FieldMetadataType.TEXT,
|
|
objectMetadataId: listingObjectId,
|
|
isLabelSyncedWithName: true,
|
|
};
|
|
|
|
const graphqlOperation = createOneFieldMetadataFactory({
|
|
input: { field: createFieldInput },
|
|
gqlFields: `
|
|
id
|
|
name
|
|
label
|
|
isLabelSyncedWithName
|
|
`,
|
|
});
|
|
|
|
// Act
|
|
const response = await makeMetadataAPIRequest(graphqlOperation);
|
|
|
|
// Assert
|
|
expect(response.body.errors[0].message).toBe(
|
|
'Name is not synced with label. Expected name: "differentLabel", got testField',
|
|
);
|
|
});
|
|
});
|
|
});
|