import { cleanupViewFieldTest, setupViewFieldTest, type ViewFieldTestSetup, } from 'test/integration/graphql/suites/view/utils/setup-view-field-test.util'; import { destroyOneViewField } from 'test/integration/metadata/suites/view-field/utils/destroy-one-view-field.util'; import { extractRecordIdsAndDatesAsExpectAny } from 'test/utils/extract-record-ids-and-dates-as-expect-any'; import { eachTestingContextFilter, type EachTestingContext, } from 'twenty-shared/testing'; import { type DestroyViewFieldInput } from 'src/engine/metadata-modules/view-field/dtos/inputs/destroy-view-field.input'; const TEST_NOT_EXISTING_VIEW_FIELD_ID = '20202020-0000-4000-8000-000000000001'; describe('View Field Resolver - Failing Destroy Operation', () => { let testSetup: ViewFieldTestSetup; beforeAll(async () => { testSetup = await setupViewFieldTest(); }); afterAll(async () => { await cleanupViewFieldTest(testSetup.testObjectMetadataId); }); type DestroyViewFieldTestCase = { input: DestroyViewFieldInput; }; const destroyViewFieldTestCases: EachTestingContext[] = [ { title: 'non-existent view field', context: { input: { id: TEST_NOT_EXISTING_VIEW_FIELD_ID, }, }, }, ]; it.each(eachTestingContextFilter(destroyViewFieldTestCases))( 'should fail to destroy view field when $title', async ({ context }) => { const response = await destroyOneViewField({ input: context.input, expectToFail: true, }); expect(response.errors).toBeDefined(); expect(response.errors.length).toBe(1); const [firstError] = response.errors; expect(firstError).toMatchSnapshot( extractRecordIdsAndDatesAsExpectAny(firstError), ); }, ); });