Skip to content

Commit

Permalink
fix(AWS Rekognition Node): Fix all different action type (#6136)
Browse files Browse the repository at this point in the history
* Fix broken logic with type action

* Unit test base

* Add unit test using only nock

* Fix failing test

* remove console log

---------

Co-authored-by: Marcus <marcus@n8n.io>
  • Loading branch information
2 people authored and netroy committed May 15, 2023
1 parent a7f3b81 commit b8a4512
Show file tree
Hide file tree
Showing 3 changed files with 698 additions and 49 deletions.
96 changes: 47 additions & 49 deletions packages/nodes-base/nodes/Aws/Rekognition/AwsRekognition.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,64 +389,62 @@ export class AwsRekognition implements INodeType {

if (type === 'detectText') {
action = 'RekognitionService.DetectText';
}
body.Filters = {};

body.Filters = {};

const box =
((additionalFields.regionsOfInterestUi as IDataObject)
?.regionsOfInterestValues as IDataObject[]) || [];
const box =
((additionalFields.regionsOfInterestUi as IDataObject)
?.regionsOfInterestValues as IDataObject[]) || [];

if (box.length !== 0) {
//@ts-ignore
body.Filters.RegionsOfInterest = box.map((entry: IDataObject) => {
return { BoundingBox: keysTPascalCase(entry) };
});
}
if (box.length !== 0) {
//@ts-ignore
body.Filters.RegionsOfInterest = box.map((entry: IDataObject) => {
return { BoundingBox: keysTPascalCase(entry) };
});
}

const wordFilter = (additionalFields.wordFilterUi as IDataObject) || {};
if (Object.keys(wordFilter).length !== 0) {
//@ts-ignore
body.Filters.WordFilter = keysTPascalCase(wordFilter);
}
const wordFilter = (additionalFields.wordFilterUi as IDataObject) || {};
if (Object.keys(wordFilter).length !== 0) {
//@ts-ignore
body.Filters.WordFilter = keysTPascalCase(wordFilter);
}

const isBinaryData = this.getNodeParameter('binaryData', i);
if (isBinaryData) {
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
const binaryPropertyData = this.helpers.assertBinaryData(i, binaryPropertyName);
Object.assign(body, {
Image: {
Bytes: binaryPropertyData.data,
},
});
} else {
const bucket = this.getNodeParameter('bucket', i) as string;
const name = this.getNodeParameter('name', i) as string;
const isBinaryData = this.getNodeParameter('binaryData', i);
if (isBinaryData) {
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
const binaryPropertyData = this.helpers.assertBinaryData(i, binaryPropertyName);
Object.assign(body, {
Image: {
Bytes: binaryPropertyData.data,
},
});
} else {
const bucket = this.getNodeParameter('bucket', i) as string;
const name = this.getNodeParameter('name', i) as string;

Object.assign(body, {
Image: {
S3Object: {
Bucket: bucket,
Name: name,
},
Object.assign(body, {
Image: {
S3Object: {
Bucket: bucket,
Name: name,
},
});
},
});

if (additionalFields.version) {
//@ts-ignore
body.Image.S3Object.Version = additionalFields.version as string;
}
if (additionalFields.version) {
//@ts-ignore
body.Image.S3Object.Version = additionalFields.version as string;
}

responseData = await awsApiRequestREST.call(
this,
'rekognition',
'POST',
'',
JSON.stringify(body),
{},
{ 'X-Amz-Target': action, 'Content-Type': 'application/x-amz-json-1.1' },
);
}
responseData = await awsApiRequestREST.call(
this,
'rekognition',
'POST',
'',
JSON.stringify(body),
{},
{ 'X-Amz-Target': action, 'Content-Type': 'application/x-amz-json-1.1' },
);
}
}

Expand Down
Loading

0 comments on commit b8a4512

Please sign in to comment.