From 0be561fb6c5638802a5d284eb61fd9b3a832ec46 Mon Sep 17 00:00:00 2001 From: AASHISH MALIK Date: Tue, 16 Apr 2024 19:27:41 +0530 Subject: [PATCH] fix: optimized query and updated test cases --- src/v0/destinations/monday/util.js | 17 +++++++++-------- .../destinations/monday/processor/data.ts | 10 +++++----- .../destinations/monday/router/data.ts | 4 ++-- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/v0/destinations/monday/util.js b/src/v0/destinations/monday/util.js index 76d1e4df23..0694028eb2 100644 --- a/src/v0/destinations/monday/util.js +++ b/src/v0/destinations/monday/util.js @@ -27,7 +27,7 @@ const getGroupId = (groupTitle, board) => { } }); if (groupId) { - return groupId; + return JSON.stringify(groupId); } throw new ConfigurationError(`Group ${groupTitle} doesn't exist in the board`); }; @@ -239,19 +239,20 @@ const populatePayload = (message, Config, boardDeatailsResponse) => { columnToPropertyMapping, boardDeatailsResponse.response?.data, ); + const items = [ + `board_id: ${boardId}`, + `item_name: ${JSON.stringify(message.properties?.name)}`, + `column_values: ${JSON.stringify(columnValues)}`, + ]; if (groupTitle) { if (!message.properties?.name) { throw new InstrumentationError('Item name is required to create an item'); } const groupId = getGroupId(groupTitle, boardDeatailsResponse.response?.data); - payload.query = `mutation { create_item (board_id: ${boardId}, group_id: ${JSON.stringify(groupId)}, item_name: ${JSON.stringify( - message.properties?.name, - )}, column_values: ${JSON.stringify(columnValues)}) {id}}`; - } else { - payload.query = `mutation { create_item (board_id: ${boardId}, item_name: ${JSON.stringify( - message.properties?.name, - )}, column_values: ${JSON.stringify(columnValues)}) {id}}`; + items.push(`group_id: ${groupId}`); } + const itemsQuery = items.join(', '); + payload.query = `mutation { create_item (${itemsQuery}) {id}}`; return payload; }; diff --git a/test/integrations/destinations/monday/processor/data.ts b/test/integrations/destinations/monday/processor/data.ts index 9a63ea6ae6..082ff822fd 100644 --- a/test/integrations/destinations/monday/processor/data.ts +++ b/test/integrations/destinations/monday/processor/data.ts @@ -74,7 +74,7 @@ export const data = [ FORM: {}, JSON: { query: - 'mutation { create_item (board_id: 339283933, item_name: "Task 1", column_values: "{}") {id}}', + 'mutation { create_item (board_id: 339283933, item_name: "Task 1", column_values: "{}") {id}}', }, JSON_ARRAY: {}, XML: {}, @@ -172,7 +172,7 @@ export const data = [ FORM: {}, JSON: { query: - 'mutation { create_item (board_id: 339283933, item_name: "Task 1", column_values: "{}") {id}}', + 'mutation { create_item (board_id: 339283933, item_name: "Task 1", column_values: "{}") {id}}', }, JSON_ARRAY: {}, XML: {}, @@ -716,7 +716,7 @@ export const data = [ body: { JSON: { query: - 'mutation { create_item (board_id: 339283933, item_name: "Task 1", column_values: "{\\"status\\":{\\"label\\":\\"Done\\"},\\"email\\":{\\"email\\":\\"abc@email.com\\",\\"text\\":\\"emailId\\"}}") {id}}', + 'mutation { create_item (board_id: 339283933, item_name: "Task 1", column_values: "{\\"status\\":{\\"label\\":\\"Done\\"},\\"email\\":{\\"email\\":\\"abc@email.com\\",\\"text\\":\\"emailId\\"}}") {id}}', }, JSON_ARRAY: {}, XML: {}, @@ -827,7 +827,7 @@ export const data = [ body: { JSON: { query: - 'mutation { create_item (board_id: 339283933, group_id: "group_title", item_name: "Task 1", column_values: "{\\"status\\":{\\"label\\":\\"Done\\"},\\"email\\":{\\"email\\":\\"abc@email.com\\",\\"text\\":\\"emailId\\"}}") {id}}', + 'mutation { create_item (board_id: 339283933, item_name: "Task 1", column_values: "{\\"status\\":{\\"label\\":\\"Done\\"},\\"email\\":{\\"email\\":\\"abc@email.com\\",\\"text\\":\\"emailId\\"}}", group_id: "group_title") {id}}', }, JSON_ARRAY: {}, XML: {}, @@ -1188,7 +1188,7 @@ export const data = [ body: { JSON: { query: - 'mutation { create_item (board_id: 339283933, group_id: "group_title", item_name: "Task 1", column_values: "{\\"status\\":{\\"label\\":\\"Done\\"},\\"email\\":{\\"email\\":\\"abc@email.com\\",\\"text\\":\\"emailId\\"},\\"checkbox\\":{\\"checked\\":true},\\"numbers\\":\\"45\\",\\"text\\":\\"texting\\",\\"country\\":{\\"countryName\\":\\"Unites States\\",\\"countryCode\\":\\"US\\"},\\"location\\":{\\"address\\":\\"New York\\",\\"lat\\":\\"51.23\\",\\"lng\\":\\"35.3\\"},\\"phone\\":{\\"phone\\":\\"2626277272\\",\\"countryShortName\\":\\"US\\"},\\"rating\\":3,\\"link\\":{\\"url\\":\\"demo.com\\",\\"text\\":\\"websiteLink\\"},\\"long_text\\":{\\"text\\":\\"property description\\"},\\"world_clock\\":{\\"timezone\\":\\"America/New_York\\"}}") {id}}', + 'mutation { create_item (board_id: 339283933, item_name: "Task 1", column_values: "{\\"status\\":{\\"label\\":\\"Done\\"},\\"email\\":{\\"email\\":\\"abc@email.com\\",\\"text\\":\\"emailId\\"},\\"checkbox\\":{\\"checked\\":true},\\"numbers\\":\\"45\\",\\"text\\":\\"texting\\",\\"country\\":{\\"countryName\\":\\"Unites States\\",\\"countryCode\\":\\"US\\"},\\"location\\":{\\"address\\":\\"New York\\",\\"lat\\":\\"51.23\\",\\"lng\\":\\"35.3\\"},\\"phone\\":{\\"phone\\":\\"2626277272\\",\\"countryShortName\\":\\"US\\"},\\"rating\\":3,\\"link\\":{\\"url\\":\\"demo.com\\",\\"text\\":\\"websiteLink\\"},\\"long_text\\":{\\"text\\":\\"property description\\"},\\"world_clock\\":{\\"timezone\\":\\"America/New_York\\"}}", group_id: "group_title") {id}}', }, JSON_ARRAY: {}, XML: {}, diff --git a/test/integrations/destinations/monday/router/data.ts b/test/integrations/destinations/monday/router/data.ts index df9e5a50a5..abd649d805 100644 --- a/test/integrations/destinations/monday/router/data.ts +++ b/test/integrations/destinations/monday/router/data.ts @@ -113,7 +113,7 @@ export const data = [ FORM: {}, JSON: { query: - 'mutation { create_item (board_id: 339283933, item_name: "Task 1", column_values: "{}") {id}}', + 'mutation { create_item (board_id: 339283933, item_name: "Task 1", column_values: "{}") {id}}', }, JSON_ARRAY: {}, XML: {}, @@ -159,7 +159,7 @@ export const data = [ body: { JSON: { query: - 'mutation { create_item (board_id: 339283933, group_id: "group_title", item_name: "Task 1", column_values: "{\\"status\\":{\\"label\\":\\"Done\\"},\\"email\\":{\\"email\\":\\"abc@email.com\\",\\"text\\":\\"emailId\\"}}") {id}}', + 'mutation { create_item (board_id: 339283933, item_name: "Task 1", column_values: "{\\"status\\":{\\"label\\":\\"Done\\"},\\"email\\":{\\"email\\":\\"abc@email.com\\",\\"text\\":\\"emailId\\"}}", group_id: "group_title") {id}}', }, JSON_ARRAY: {}, XML: {},