Skip to content

Commit

Permalink
fix: optimized query and updated test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
aashishmalik committed Apr 16, 2024
1 parent 4952bd2 commit 0be561f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
17 changes: 9 additions & 8 deletions src/v0/destinations/monday/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
};
Expand Down Expand Up @@ -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;
};

Expand Down
10 changes: 5 additions & 5 deletions test/integrations/destinations/monday/processor/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
Expand Down Expand Up @@ -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: {},
Expand Down Expand Up @@ -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\\":\\"[email protected]\\",\\"text\\":\\"emailId\\"}}") {id}}',
'mutation { create_item (board_id: 339283933, item_name: "Task 1", column_values: "{\\"status\\":{\\"label\\":\\"Done\\"},\\"email\\":{\\"email\\":\\"[email protected]\\",\\"text\\":\\"emailId\\"}}") {id}}',
},
JSON_ARRAY: {},
XML: {},
Expand Down Expand Up @@ -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\\":\\"[email protected]\\",\\"text\\":\\"emailId\\"}}") {id}}',
'mutation { create_item (board_id: 339283933, item_name: "Task 1", column_values: "{\\"status\\":{\\"label\\":\\"Done\\"},\\"email\\":{\\"email\\":\\"[email protected]\\",\\"text\\":\\"emailId\\"}}", group_id: "group_title") {id}}',
},
JSON_ARRAY: {},
XML: {},
Expand Down Expand Up @@ -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\\":\\"[email protected]\\",\\"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\\":\\"[email protected]\\",\\"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: {},
Expand Down
4 changes: 2 additions & 2 deletions test/integrations/destinations/monday/router/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
Expand Down Expand Up @@ -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\\":\\"[email protected]\\",\\"text\\":\\"emailId\\"}}") {id}}',
'mutation { create_item (board_id: 339283933, item_name: "Task 1", column_values: "{\\"status\\":{\\"label\\":\\"Done\\"},\\"email\\":{\\"email\\":\\"[email protected]\\",\\"text\\":\\"emailId\\"}}", group_id: "group_title") {id}}',
},
JSON_ARRAY: {},
XML: {},
Expand Down

0 comments on commit 0be561f

Please sign in to comment.