The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
fix(rest): forward flatIndexMaps to the merge query runner (#26063)
Charles Bochet644cf2426c50
diff --git a/packages/twenty-server/src/engine/api/rest/core/handlers/rest-api-merge-many.handler.ts b/packages/twenty-server/src/engine/api/rest/core/handlers/rest-api-merge-many.handler.tsindex ea555b85fd3..354883ef7a2 100644--- a/packages/twenty-server/src/engine/api/rest/core/handlers/rest-api-merge-many.handler.ts+++ b/packages/twenty-server/src/engine/api/rest/core/handlers/rest-api-merge-many.handler.ts@@ -25,6 +25,7 @@ export class RestApiMergeManyHandler extends RestApiBaseHandler {flatObjectMetadata,flatObjectMetadataMaps,flatFieldMetadataMaps,+ flatIndexMaps,objectIdByNameSingular,} = await this.buildCommonOptions(request);@@ -44,6 +45,7 @@ export class RestApiMergeManyHandler extends RestApiBaseHandler {flatObjectMetadata,flatObjectMetadataMaps,flatFieldMetadataMaps,+ flatIndexMaps,objectIdByNameSingular,},);diff --git a/packages/twenty-server/test/integration/rest/suites/rest-api-core-merge.integration-spec.ts b/packages/twenty-server/test/integration/rest/suites/rest-api-core-merge.integration-spec.tsnew file mode 100644index 00000000000..361e7ce5f7a--- /dev/null+++ b/packages/twenty-server/test/integration/rest/suites/rest-api-core-merge.integration-spec.ts@@ -0,0 +1,65 @@+import {+ TEST_PERSON_1_ID,+ TEST_PERSON_2_ID,+} from 'test/integration/constants/test-person-ids.constants';+import { makeRestAPIRequest } from 'test/integration/rest/utils/make-rest-api-request.util';+import { deleteAllRecords } from 'test/integration/utils/delete-all-records';++describe('Core REST API Merge endpoint', () => {+ beforeEach(async () => {+ await deleteAllRecords('person');+ await makeRestAPIRequest({+ method: 'post',+ path: '/batch/people',+ body: [{ id: TEST_PERSON_1_ID }, { id: TEST_PERSON_2_ID }],+ });+ });++ it('should merge many people into the priority record', async () => {+ await makeRestAPIRequest({+ method: 'patch',+ path: '/people/merge',+ body: {+ ids: [TEST_PERSON_1_ID, TEST_PERSON_2_ID],+ conflictPriorityIndex: 0,+ dryRun: false,+ },+ })+ .expect(200)+ .expect((res) => {+ expect(res.body.data.mergePerson.id).toBe(TEST_PERSON_1_ID);+ });++ await makeRestAPIRequest({+ method: 'get',+ path: `/people/${TEST_PERSON_1_ID}`,+ }).expect(200);++ await makeRestAPIRequest({+ method: 'get',+ path: `/people/${TEST_PERSON_2_ID}`,+ }).expect(404);+ });++ it('should not delete records on a dry run merge', async () => {+ await makeRestAPIRequest({+ method: 'patch',+ path: '/people/merge',+ body: {+ ids: [TEST_PERSON_1_ID, TEST_PERSON_2_ID],+ conflictPriorityIndex: 0,+ dryRun: true,+ },+ }).expect(200);++ await makeRestAPIRequest({+ method: 'get',+ path: `/people/${TEST_PERSON_1_ID}`,+ }).expect(200);++ await makeRestAPIRequest({+ method: 'get',+ path: `/people/${TEST_PERSON_2_ID}`,+ }).expect(200);+ });+});