Skip to content

Commit

Permalink
performBulk result item should have outputData OR error
Browse files Browse the repository at this point in the history
  • Loading branch information
eliangcs committed May 15, 2024
1 parent 01ced32 commit a4080da
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
13 changes: 9 additions & 4 deletions packages/core/src/checks/perform-bulk-return-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,24 @@ const performBulkEchoesIds = {
let missingIdsStr = missingIds.slice(0, LIMIT).join(', ');
const remainingCount = missingIds.length - LIMIT;
if (remainingCount > 0) {
// No want to flood the user with too many IDs
// Don't want to flood the user with too many IDs
missingIdsStr += `, and ${remainingCount} more`;
}
return [`Result object is missing these IDs as keys: ${missingIdsStr}`];
}

const errors = [];
for (const [id, item] of Object.entries(results)) {
for (const id of inputIds) {
const item = results[id];

if (!_.isPlainObject(item)) {
errors.push(`Result object member with ID '${id}' must be an object`);
} else if (!_.isPlainObject(item.outputData)) {
} else if (
!_.isPlainObject(item.outputData) &&
typeof item.error !== 'string'
) {
errors.push(
`Result object member with ID '${id}' must have 'outputData' object`
`Result object member with ID '${id}' must have 'outputData' object or 'error' string`
);
}

Expand Down
23 changes: 17 additions & 6 deletions packages/core/test/checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,22 @@ describe('checks', () => {
});

it('should check performBulk object shape', () => {
const results = { one: {}, two: {} };
const results = {
one: 'not an object',
two: { error: 123 },
three: { outputData: {} },
four: { error: 'test' },
five: {
outputData: 'this one should pass because it is not in the input',
},
};
const bundle = {
bulk: [{ meta: { id: 'one' } }, { meta: { id: 'two' } }],
bulk: [
{ meta: { id: 'one' } },
{ meta: { id: 'two' } },
{ meta: { id: 'three' } },
{ meta: { id: 'four' } },
],
};
const errors = checks.performBulkReturnType.run(
'creates.blah.operation.performBulk',
Expand All @@ -287,11 +300,9 @@ describe('checks', () => {
bundle
);
errors.length.should.eql(2);
errors[0].should.match(
/member with ID 'one' must have 'outputData' object/
);
errors[0].should.match(/member with ID 'one' must be an object/);
errors[1].should.match(
/member with ID 'two' must have 'outputData' object/
/member with ID 'two' must have 'outputData' object or 'error' string/
);
});

Expand Down

0 comments on commit a4080da

Please sign in to comment.