Files
pleno-vue/tests/unit/slack-module.spec.js
T

136 lines
7.8 KiB
JavaScript

import { readFileSync } from "node:fs";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
const root = process.cwd();
const slackModuleSource = readFileSync(
join(root, "src/components/session/token/superUser/modules/slack/Slack.vue"),
"utf8"
);
const slackConfigSource = readFileSync(
join(root, "src/components/session/token/superUser/modules/slack/Config.vue"),
"utf8"
);
const slackPageSource = readFileSync(
join(root, "src/views/dashboards/superUserDashboard/configuration/ConfigurationSlack.vue"),
"utf8"
);
const configurationMultiSelectSource = readFileSync(
join(root, "src/components/displays/superuser/configuration/ConfigurationMultiSelect.vue"),
"utf8"
);
const superUserObjectSource = readFileSync(join(root, "src/components/session/token/superUserObject.vue"), "utf8");
const routerSource = readFileSync(join(root, "src/router.js"), "utf8");
const navigationSource = readFileSync(
join(root, "src/views/dashboards/superUserDashboard/configuration/SuperUserDashboardConfigurationNavigation.vue"),
"utf8"
);
describe("slack module contract", () => {
it("defines module metadata and config endpoint", () => {
expect(slackModuleSource).toContain('title: "Slack"');
expect(slackModuleSource).toContain('endpoint: "/slack/config"');
expect(slackModuleSource).toContain('config_endpoint: "/configuration/slack"');
});
it("uses Slack config endpoints and customer registration variable", () => {
expect(slackConfigSource).toContain('"/slack/config?variable=" + variable');
expect(slackConfigSource).toContain('"/slack/config"');
expect(slackConfigSource).toContain('"/slack/config/test"');
expect(slackConfigSource).toContain('"/slack/config/internal-department-goal-progress"');
expect(slackConfigSource).toContain('"/slack/config/internal-department-goal-progress/test"');
expect(slackConfigSource).toContain("test_customer_registration_webhook");
expect(slackConfigSource).toContain("test_internal_department_goal_progress_webhook");
expect(slackConfigSource).toContain("get_internal_department_goal_progress");
expect(slackConfigSource).toContain("set_internal_department_goal_progress");
expect(slackConfigSource).toContain('Config.get("customer_registration_webhook_url")');
expect(slackConfigSource).toContain('Config.set("customer_registration_webhook_url", value)');
expect(slackConfigSource).toContain('Config.get("internal_department_goal_progress_webhook_url")');
expect(slackConfigSource).toContain('Config.set("internal_department_ids", value)');
});
it("exposes the Slack configuration route and navigation tab", () => {
expect(superUserObjectSource).toContain("get slack()");
expect(superUserObjectSource).toContain("return Slack;");
expect(routerSource).toContain("ConfigurationSlack");
expect(routerSource).toContain("path: '/superuser/configuration/slack'");
expect(navigationSource).toContain('{ name: "Slack", path: "/superuser/configuration/slack" }');
});
it("binds the customer registration webhook control to the Slack config key", () => {
expect(slackPageSource).toContain("$t('configuration.slack.title')");
expect(slackPageSource).toContain("$t('configuration.slack.customer_registration_webhook_url')");
expect(slackPageSource).toContain("getModuleConfigValue('customer_registration_webhook_url')");
expect(slackPageSource).toContain(
':on-save="SessionUser.superUser.modules.slack.config.keys.customer_registration_webhook_url.set"'
);
expect(slackPageSource).toContain("testCustomerRegistrationWebhook");
expect(slackPageSource).toContain(
"SessionUser.superUser.modules.slack.config.test_customer_registration_webhook()"
);
expect(slackPageSource).toContain('data-testid="slack-test-customer-registration-webhook-button"');
expect(slackPageSource).toContain(":class=\"{ 'is-loading': is_testing_customer_registration_webhook }\"");
expect(slackPageSource).toContain(':disabled="is_testing_customer_registration_webhook"');
expect(slackPageSource).toContain("$t('configuration.slack.test_customer_registration_webhook')");
expect(slackPageSource).toContain('t("configuration.slack.test_webhook_sent")');
expect(slackPageSource).toContain('t("configuration.slack.test_webhook_sent_success")');
expect(slackPageSource).toContain('t("configuration.slack.test_webhook_not_configured")');
expect(slackPageSource).toContain('t("configuration.slack.test_webhook_error")');
});
it("binds internal department goal progress settings to the Slack config endpoint", () => {
expect(slackPageSource).toContain("ConfigurationMultiSelect");
expect(slackPageSource).toContain("getInternalDepartmentGoalProgressConfig");
expect(slackPageSource).toContain("saveInternalDepartmentGoalProgressConfig");
expect(slackPageSource).toContain("saveInternalDepartmentGoalProgressWebhookUrl");
expect(slackPageSource).toContain("testInternalDepartmentGoalProgressWebhook");
expect(slackPageSource).toContain("getDepartmentsFallback");
expect(slackPageSource).toContain(".get_internal_department_goal_progress()");
expect(slackPageSource).toContain(".test_internal_department_goal_progress_webhook()");
expect(slackPageSource).toContain("set_internal_department_goal_progress");
expect(slackPageSource).toContain("$t('configuration.slack.internal_department_goal_progress_webhook_url')");
expect(slackPageSource).toContain("$t('configuration.slack.internal_department_goal_progress_webhook_url_desc')");
expect(slackPageSource).toContain("$t('configuration.slack.internal_departments')");
expect(slackPageSource).toContain('data-testid="slack-internal-departments-selector"');
expect(slackPageSource).toContain("$t('configuration.slack.internal_departments_empty')");
expect(slackPageSource).toContain('data-testid="slack-save-internal-departments-button"');
expect(slackPageSource).toContain('data-testid="slack-test-internal-department-goal-progress-webhook-button"');
expect(slackPageSource).toContain('$t("configuration.slack.save_internal_departments")');
expect(slackPageSource).toContain(
't("configuration.slack.test_internal_department_goal_progress_webhook_sent_success")'
);
expect(slackPageSource).toContain(
't("configuration.slack.test_internal_department_goal_progress_webhook_not_configured")'
);
});
it("provides a reusable multi-select with checkmark options and empty-state feedback", () => {
expect(configurationMultiSelectSource).toContain('defineEmits(["update:modelValue", "change"])');
expect(configurationMultiSelectSource).toContain('class="button configuration-multi-select-option"');
expect(configurationMultiSelectSource).toContain('class="fas fa-check"');
expect(configurationMultiSelectSource).toContain("filteredOptions.length === 0");
expect(configurationMultiSelectSource).toContain('t("messages.no_results")');
});
it("lets configuration inputs expose reusable inline action buttons", () => {
const configurationInputSource = readFileSync(
join(root, "src/components/displays/superuser/configuration/ConfigurationInput.vue"),
"utf8"
);
expect(configurationInputSource).toContain('<slot name="actions"></slot>');
});
it("shows an unavailable state when the API release does not expose Slack config", () => {
expect(slackPageSource).toContain("module_config_unavailable");
expect(slackPageSource).toContain("status === 404");
expect(slackPageSource).toContain('$t("configuration.slack.unavailable")');
});
it("keeps Slack config permission errors separate from API release availability", () => {
expect(slackPageSource).toContain("module_config_forbidden");
expect(slackPageSource).toContain("status === 403");
expect(slackPageSource).toContain('$t("errors.forbidden")');
});
});