Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(AWS Comprehend Node): Add paired item support #10015

Merged
merged 3 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions packages/nodes-base/nodes/Aws/Comprehend/AwsComprehend.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export class AwsComprehend implements INodeType {

async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
const returnData: IDataObject[] = [];
const returnData: INodeExecutionData[] = [];
let responseData;
const resource = this.getNodeParameter('resource', 0);
const operation = this.getNodeParameter('operation', 0);
Expand Down Expand Up @@ -270,19 +270,23 @@ export class AwsComprehend implements INodeType {
}
}

if (Array.isArray(responseData)) {
returnData.push.apply(returnData, responseData as IDataObject[]);
} else {
returnData.push(responseData as IDataObject);
}
const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData),
{ itemData: { item: i } },
);
returnData.push(...executionData);
} catch (error) {
if (this.continueOnFail(error)) {
returnData.push({ error: error.message });
const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray({ error: error.message }),
{ itemData: { item: i } },
);
returnData.push(...executionData);
continue;
}
throw error;
}
}
return [this.helpers.returnJsonArray(returnData)];
return [returnData];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import nock from 'nock';
import { getWorkflowFilenames, initBinaryDataService, testWorkflows } from '@test/nodes/Helpers';

const workflows = getWorkflowFilenames(__dirname);

describe('Test AWS Comprehend Node', () => {
describe('Detect Language', () => {
let mock: nock.Scope;
const now = 1683028800000;
const response = {
Languages: [
{
LanguageCode: 'en',
Score: 0.9774383902549744,
},
{
LanguageCode: 'de',
Score: 0.010717987082898617,
},
],
};
beforeAll(async () => {
jest.useFakeTimers({ doNotFake: ['nextTick'], now });

await initBinaryDataService();

nock.disableNetConnect();
const baseUrl = 'https://comprehend.eu-central-1.amazonaws.com';

mock = nock(baseUrl);
});

beforeEach(async () => {
mock.post('/').reply(200, response);
});
afterAll(() => {
nock.restore();
});

testWorkflows(workflows);
});
ShireenMissi marked this conversation as resolved.
Show resolved Hide resolved
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
{
"name": "node-aws-comprehend",
"nodes": [
{
"parameters": {},
"id": "53b6020d-5aa2-435f-9ee1-407111c0e3ee",
"name": "When clicking ‘Test workflow’",
"type": "n8n-nodes-base.manualTrigger",
"position": [
680,
380
],
"typeVersion": 1
},
{
"parameters": {
"assignments": {
"assignments": [
{
"id": "51b7eee5-8cc9-4e09-a2f4-65ffb3cc17f6",
"name": "text",
"value": "This is a test.",
"type": "string"
}
]
},
"options": {}
},
"id": "b3beaf43-fe4c-43e1-a8cb-5a0740050611",
"name": "Edit Fields",
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
900,
380
]
},
{
"parameters": {
"text": "={{ $json.text }}"
},
"id": "a6a8a24c-0e58-40e7-8bf4-13a56edc6264",
"name": "AWS Comprehend",
"type": "n8n-nodes-base.awsComprehend",
"typeVersion": 1,
"position": [
1100,
380
],
"credentials": {
"aws": {
"id": "TyNATsPCTvPF0tvG",
"name": "AWS account"
}
}
},
{
"parameters": {},
"id": "bfc4b84d-8cf1-4650-bf3c-2b1cdc677afc",
"name": "No Operation, do nothing",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
1320,
380
]
}
],
"pinData": {
"No Operation, do nothing": [
{
"json": {
"de": 0.010717987082898617,
"en": 0.9774383902549744
}
}
]
},
"connections": {
"Edit Fields": {
"main": [
[
{
"node": "AWS Comprehend",
"type": "main",
"index": 0
}
]
]
},
"When clicking ‘Test workflow’": {
"main": [
[
{
"node": "Edit Fields",
"type": "main",
"index": 0
}
]
]
},
"AWS Comprehend": {
"main": [
[
{
"node": "No Operation, do nothing",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1"
},
"versionId": "eae3c601-56b8-42ec-a0b7-14df8d697043",
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd"
},
"id": "fuOmKcLPWAxKi0bn",
"tags": []
}
Loading