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

62 lines
2.9 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 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('Config.get("customer_registration_webhook_url")');
expect(slackConfigSource).toContain('Config.set("customer_registration_webhook_url", 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"'
);
});
it("shows an unavailable state when the API release does not expose Slack config", () => {
expect(slackPageSource).toContain("module_config_unavailable");
expect(slackPageSource).toContain("[403, 404].includes(status)");
expect(slackPageSource).toContain('$t("configuration.slack.unavailable")');
});
});