Files
twenty/packages/twenty-server/test/integration/graphql/suites/view/update-view.integration-spec.ts
T
Paul Rastoin 59fbe35a8c Move view in metadata-modules/ and create atomic folder + module for each view entity (#14990)
# Introduction
Preparing view-filter and view-group introduction in v2 core engine
Moving view from `core-modules` to `metadata-modules`

## What happened

### Created dedicated modules for each view entity:
- ViewFieldModule
- ViewFilterModule
- ViewFilterGroupModule
- ViewGroupModule
- ViewSortModule

### Each module is now completely independent with its own:
- Controller
- Resolver
- Service
- Entity

### Created dedicated abstraction metadata module folder for:
- flat-view-field
- flat-view

### Dependencies 
- Eleminated circular dep on ViewModule to all others ones
- Granular import not importing the whole viewModule anymore everywhere


close https://github.com/twentyhq/core-team-issues/issues/1703
2025-10-09 15:18:15 +02:00

103 lines
3.3 KiB
TypeScript

import { TEST_NOT_EXISTING_VIEW_ID } from 'test/integration/constants/test-view-ids.constants';
import {
assertGraphQLErrorResponseWithSnapshot,
assertGraphQLSuccessfulResponse,
} from 'test/integration/graphql/utils/graphql-test-assertions.util';
import { makeGraphqlAPIRequest } from 'test/integration/graphql/utils/make-graphql-api-request.util';
import { updateViewOperationFactory } from 'test/integration/graphql/utils/update-view-operation-factory.util';
import { updateViewData } from 'test/integration/graphql/utils/view-data-factory.util';
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 { updateOneObjectMetadata } from 'test/integration/metadata/suites/object-metadata/utils/update-one-object-metadata.util';
import { createOneCoreView } from 'test/integration/metadata/suites/view/utils/create-one-core-view.util';
import { cleanupViewRecords } from 'test/integration/utils/view-test.util';
import { ViewType } from 'src/engine/metadata-modules/view/enums/view-type.enum';
describe('Update core view', () => {
let testObjectMetadataId: string;
beforeAll(async () => {
const {
data: {
createOneObject: { id: objectMetadataId },
},
} = await createOneObjectMetadata({
expectToFail: false,
input: {
nameSingular: 'myViewTestObject',
namePlural: 'myViewTestObjects',
labelSingular: 'My View Test Object',
labelPlural: 'My View Test Objects',
icon: 'Icon123',
},
});
testObjectMetadataId = objectMetadataId;
});
afterAll(async () => {
await updateOneObjectMetadata({
expectToFail: false,
input: {
idToUpdate: testObjectMetadataId,
updatePayload: {
isActive: false,
},
},
});
await deleteOneObjectMetadata({
expectToFail: false,
input: { idToDelete: testObjectMetadataId },
});
await cleanupViewRecords();
});
beforeEach(async () => {
await cleanupViewRecords();
});
it('should update an existing view', async () => {
const {
data: { createCoreView: view },
} = await createOneCoreView({
input: {
icon: '123Icon',
name: 'Original View',
type: ViewType.TABLE,
isCompact: false,
objectMetadataId: testObjectMetadataId,
},
expectToFail: false,
});
const updateInput = updateViewData({
name: 'Updated View',
type: ViewType.KANBAN,
isCompact: true,
});
const operation = updateViewOperationFactory({
viewId: view.id,
data: updateInput,
});
const response = await makeGraphqlAPIRequest(operation);
assertGraphQLSuccessfulResponse(response);
expect(response.body.data.updateCoreView).toMatchObject({
id: view.id,
...updateInput,
});
});
it('should throw error when updating non-existent view', async () => {
const operation = updateViewOperationFactory({
viewId: TEST_NOT_EXISTING_VIEW_ID,
data: { name: 'Non-existent View' },
});
const response = await makeGraphqlAPIRequest(operation);
assertGraphQLErrorResponseWithSnapshot(response);
});
});