UNPKG

@unito/integration-debugger

Version:

The Unito Integration Debugger

64 lines (63 loc) 2.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const crawler_1 = require("../crawler"); /** * Check: Validate DeleteItem 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 DeleteItem request and expects to receive a 404 error code. * */ const check = { label: 'DeleteItem - Not Found', 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.canDeleteItem) { 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.DeleteItem, headersIn: step.headersIn, warnings: [], errors: [], }, ]; } return []; }, validate: (step, _crawlerDriver) => { if (!step.context || step.context.name !== 'DeleteItemNotFound') { 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 delete 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;