UNPKG

@unito/integration-debugger

Version:

The Unito Integration Debugger

75 lines (74 loc) 2.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const crawler_1 = require("../crawler"); /** * Check: Create a valid item * * When `canCreateItem` is set to true, it is assumed one can `POST` new records to the relation's path. * It accepts a `Fields` object, and must return an `ItemSummary` on success with a `201` status code. * * This check seek to generate a **VALID** item and exercise the integration to validate that it can create * the corresponding Item successfully. * * @example * For the following item... * * ```json * { * "fields": {}, * "relations": [{ * "name": "foos", * "label": "Foos", * "path": "/foos", * "schema": { * "canCreateItem": true, * "fields": [{ * "name": "value", * "type": "string", * "readOnly": false * }] * } * }] * } * ``` * * ... we try a `POST /foos` with the following payload: * * ```json * { * "value": "<random string>" * } */ const check = { label: 'CreateItem - Valid Item', prepareOnPreparedSteps: false, validateOnError: false, activatedByDefault: false, prepare: async (stepResult, crawlerDriver) => { const step = stepResult.step; const preparedSteps = []; if (step.operation !== crawler_1.Operation.GetItem || !step.payloadOut) { return preparedSteps; } const { relations } = step.payloadOut; for (const relation of relations) { if (relation.schema.canCreateItem) { const newItem = await crawlerDriver.generator.generate(relation.schema.fields, { excludeReadOnly: true }); preparedSteps.push({ path: relation.path, requestSchema: undefined, schemaPath: (0, crawler_1.buildSchemaUniqueId)(step.path, relation.name), parentOperation: step.operation, parentPath: step.path, operation: crawler_1.Operation.CreateItem, payloadIn: newItem, headersIn: step.headersIn, warnings: [], errors: [], }); } } return preparedSteps; }, }; exports.default = check;