Files
twenty/packages/twenty-server/test/integration/graphql/suites/view/update-view.integration-spec.ts
T
Paul Rastoin c19a799973 Fix view rest api in v2 (#15398)
# Introduction
Initially wanted to reactive the test introduced in
https://github.com/twentyhq/twenty/pull/15393, that was failing because
of direct data source access removing all views ( even seeded one )
which was making the test fail

While doing so discovered a lot of issue with the rest API:
- Rest api wasn't consuming the v2 at all
- Rest api wasn't prepared to handle v2 exceptions
- Rest api did not handled unknown exceptions ( timeout )

Refactored the cleanup of each test to follow black box pattern and
avoid test leakage
2025-10-29 15:07:08 +01:00

96 lines
2.9 KiB
TypeScript

import { expectOneNotInternalServerErrorSnapshot } from 'test/integration/graphql/utils/expect-one-not-internal-server-error-snapshot.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 { updateOneCoreView } from 'test/integration/metadata/suites/view/utils/update-one-core-view.util';
import { ViewType } from 'src/engine/metadata-modules/view/enums/view-type.enum';
const TEST_NOT_EXISTING_VIEW_ID = '20202020-0000-4000-8000-000000000000';
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 },
});
});
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 = {
id: view.id,
name: 'Updated View',
type: ViewType.KANBAN,
isCompact: true,
};
const { data, errors } = await updateOneCoreView({
viewId: view.id,
input: updateInput,
expectToFail: false,
});
expect(errors).toBeUndefined();
expect(data.updateCoreView).toMatchObject({
id: view.id,
name: 'Updated View',
type: ViewType.KANBAN,
isCompact: true,
});
});
it('should throw error when updating non-existent view', async () => {
const { errors } = await updateOneCoreView({
viewId: TEST_NOT_EXISTING_VIEW_ID,
input: { id: TEST_NOT_EXISTING_VIEW_ID, name: 'Non-existent View' },
expectToFail: true,
});
expectOneNotInternalServerErrorSnapshot({ errors });
});
});