"use strict";
var import_vitest = require("vitest");
var import_integration_body = require("../api/integration-body");
var import_integration_linter = require("./integration-linter");
var import_sdk = require("@botpress/sdk");
const EMPTY_STRING = "";
const TRUTHY_STRING = "truthy";
const ACTION_NAME = "actionName";
const EVENT_NAME = "eventName";
const CONFIG_NAME = "configName";
const PARAM_NAME = "paramName";
const TAG_NAME = "tagName";
const CHANNEL_NAME = "channelName";
const STATE_NAME = "stateName";
const MESSAGE_TYPE = "text";
const SECRET_NAME = "SECRET_NAME";
const VALID_INTEGRATION = {
  name: TRUTHY_STRING,
  title: TRUTHY_STRING,
  description: TRUTHY_STRING,
  version: TRUTHY_STRING,
  readme: TRUTHY_STRING,
  icon: TRUTHY_STRING,
  actions: {
    [ACTION_NAME]: {
      title: TRUTHY_STRING,
      description: TRUTHY_STRING,
      input: {
        schema: import_sdk.z.object({
          [PARAM_NAME]: import_sdk.z.string().title(TRUTHY_STRING).describe(TRUTHY_STRING)
        }).title(TRUTHY_STRING).describe(TRUTHY_STRING)
      },
      output: {
        schema: import_sdk.z.object({
          [PARAM_NAME]: import_sdk.z.string().title(TRUTHY_STRING).describe(TRUTHY_STRING)
        }).title(TRUTHY_STRING).describe(TRUTHY_STRING)
      }
    }
  },
  events: {
    [EVENT_NAME]: {
      title: TRUTHY_STRING,
      description: TRUTHY_STRING,
      schema: import_sdk.z.object({
        [PARAM_NAME]: import_sdk.z.string().title(TRUTHY_STRING).describe(TRUTHY_STRING)
      }).title(TRUTHY_STRING).describe(TRUTHY_STRING)
    }
  },
  configuration: {
    schema: import_sdk.z.object({
      [PARAM_NAME]: import_sdk.z.string().title(TRUTHY_STRING).describe(TRUTHY_STRING)
    }).title(TRUTHY_STRING).describe(TRUTHY_STRING)
  },
  configurations: {
    [CONFIG_NAME]: {
      title: TRUTHY_STRING,
      description: TRUTHY_STRING,
      schema: import_sdk.z.object({
        [PARAM_NAME]: import_sdk.z.string().title(TRUTHY_STRING).describe(TRUTHY_STRING)
      }).title(TRUTHY_STRING).describe(TRUTHY_STRING)
    }
  },
  user: {
    tags: {
      [TAG_NAME]: {
        title: TRUTHY_STRING,
        description: TRUTHY_STRING
      }
    }
  },
  channels: {
    [CHANNEL_NAME]: {
      title: TRUTHY_STRING,
      description: TRUTHY_STRING,
      messages: {
        [MESSAGE_TYPE]: {
          schema: import_sdk.z.object({
            [PARAM_NAME]: import_sdk.z.string().title(TRUTHY_STRING).describe(TRUTHY_STRING)
          }).title(TRUTHY_STRING).describe(TRUTHY_STRING)
        }
      },
      message: {
        tags: {
          [TAG_NAME]: {
            title: TRUTHY_STRING,
            description: TRUTHY_STRING
          }
        }
      },
      conversation: {
        tags: {
          [TAG_NAME]: {
            title: TRUTHY_STRING,
            description: TRUTHY_STRING
          }
        }
      }
    }
  },
  states: {
    [STATE_NAME]: {
      type: "integration",
      schema: import_sdk.z.object({
        [PARAM_NAME]: import_sdk.z.string().title(TRUTHY_STRING).describe(TRUTHY_STRING)
      }).title(TRUTHY_STRING).describe(TRUTHY_STRING)
    }
  },
  secrets: {
    [SECRET_NAME]: {
      description: TRUTHY_STRING
    }
  }
};
const mockLogger = {
  log: import_vitest.vi.fn((message) => void message),
  warn: import_vitest.vi.fn((message) => void message),
  error: import_vitest.vi.fn((message) => void message),
  debug: import_vitest.vi.fn((message) => void message)
};
const lintDefinition = async (definition) => {
  const integrationDefinition = new import_sdk.IntegrationDefinition(definition);
  const integrationBody = await (0, import_integration_body.prepareCreateIntegrationBody)(integrationDefinition);
  const linter = new import_integration_linter.IntegrationLinter({
    ...integrationBody,
    readme: integrationDefinition.readme,
    icon: integrationDefinition.icon,
    secrets: integrationDefinition.secrets
  });
  await linter.lint();
  return linter;
};
const lintDefinitionAndReturnResults = async (definition) => {
  const linter = await lintDefinition(definition);
  return linter.getSortedResults();
};
const lintDefinitionAndLogResults = async (definition) => {
  const linter = await lintDefinition(definition);
  linter.logResults(mockLogger);
};
import_vitest.describe.concurrent("Integration Linter", () => {
  (0, import_vitest.test)("should lint a valid definition without giving errors", async () => {
    const definition = VALID_INTEGRATION;
    const results = await lintDefinitionAndReturnResults(definition);
    (0, import_vitest.expect)(results).toEqual([]);
  });
  (0, import_vitest.test)("should report an error when missing required fields", async () => {
    const definition = {
      ...VALID_INTEGRATION,
      title: EMPTY_STRING
    };
    const results = await lintDefinitionAndReturnResults(definition);
    (0, import_vitest.expect)(results[0]?.message).toContain("title");
  });
  (0, import_vitest.test)("should report an error when missing a title in an action input schema", async () => {
    const definition = {
      ...VALID_INTEGRATION,
      actions: {
        [ACTION_NAME]: {
          ...VALID_INTEGRATION.actions[ACTION_NAME],
          input: {
            schema: import_sdk.z.object({
              [PARAM_NAME]: import_sdk.z.string().describe(TRUTHY_STRING)
            })
          }
        }
      }
    };
    const results = await lintDefinitionAndReturnResults(definition);
    (0, import_vitest.expect)(results[0]?.message).toContain("title");
  });
  (0, import_vitest.test)("should log as an error when severity is 0", async () => {
    const definition = {
      ...VALID_INTEGRATION,
      title: EMPTY_STRING
    };
    await lintDefinitionAndLogResults(definition);
    (0, import_vitest.expect)(mockLogger.error).toHaveBeenCalled();
  });
  (0, import_vitest.test)("should log as a warning when severity is 1", async () => {
    const definition = {
      ...VALID_INTEGRATION,
      user: {
        tags: {
          [TAG_NAME]: {}
        }
      }
    };
    await lintDefinitionAndLogResults(definition);
    (0, import_vitest.expect)(mockLogger.warn).toHaveBeenCalled();
  });
});
//# sourceMappingURL=base-linter.test.js.map
