@unito/integration-debugger
Version:
The Unito Integration Debugger
60 lines (59 loc) • 2.38 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const crawler_1 = require("../crawler");
/**
* Check: Validate GetItem 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 GetItem request and expects to receive a 404 error code.
*
*/
const check = {
label: 'GetItem - 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 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.GetItem,
headersIn: step.headersIn,
warnings: [],
errors: [],
},
];
},
validate: (step, _crawlerDriver) => {
if (!step.context || step.context.name !== 'ItemNotFound') {
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 requested Item doesn't exist`,
detailedMessage: `Your integration was requested a unexisting item but did not respond with a '404' Not Found but with ${payload.code} instead`,
instancePath: step.path,
schemaPath: step.schemaPath ?? '',
params: {
code: 'UNSUPPORTED_ERROR_CODE',
},
});
}
},
};
exports.default = check;
;