@unito/integration-debugger
Version:
The Unito Integration Debugger
67 lines (66 loc) • 2.87 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const crawler_1 = require("../crawler");
/**
* Check: Validate UpdateItem NotFound error code
*
* The Specification defines specific error codes that can be returned in case of failure for a given action
* This check will generate invalid UpdateItem request and expects to receive a 404 error code.
*
*/
const check = {
label: 'UpdateItem - NotFound',
prepareOnPreparedSteps: false,
validateOnError: true,
activatedByDefault: false,
prepare: async (stepResult, crawlerDriver) => {
const step = stepResult.step;
if (step.operation !== crawler_1.Operation.GetCollection || !step.schemaPath || !step.payloadOut) {
return [];
}
const schema = crawlerDriver.getRelationSchema(step.schemaPath);
if (schema && schema.canUpdateItem) {
// We assume passing an item with a attribute name as a function should be enough to result in a fail
const updatedItem = await crawlerDriver.generator.generate(schema.fields, { excludeReadOnly: true });
const itemSummaries = step.payloadOut.data;
const [path, params] = (itemSummaries[0]?.path ?? '').split('?');
return [
{
path: [`${path}NotAnItem42342309831`, params].filter(Boolean).join('?'),
requestSchema: undefined,
schemaPath: step.schemaPath,
parentOperation: step.operation,
parentPath: step.path,
operation: crawler_1.Operation.UpdateItem,
payloadIn: updatedItem,
headersIn: step.headersIn,
warnings: [],
errors: [],
},
];
}
return [];
},
validate: (step, _crawlerDriver) => {
if (!step.context || step.context.name !== 'UpdateItemNotFound') {
return;
}
const payload = step.payloadOut;
const isError = payload?.code && payload?.message;
// First clear original errors as they are expected, we want to validate that they had the right error code.
step.errors = [];
if (isError && payload?.code !== '404') {
step.errors.push({
keyword: 'unito',
message: `Return a '404' Not Found response when the Item to delete doesn't exist`,
detailedMessage: `Your integration was requested to update an unexisting item but responded with ${payload.code} instead of a '404' Not Found`,
instancePath: step.path,
schemaPath: step.schemaPath ?? '',
params: {
code: 'UNSUPPORTED_ERROR_CODE',
},
});
}
},
};
exports.default = check;
;