Files
pleno-vue/tests/unit/weatherapi-module.spec.js
Jeppe Bundgaard b39b458f4f Add .prettierrc.json and refactor test files for improved formatting consistency:
- Introduced `.prettierrc.json` to enforce consistent code formatting across the project.
- Updated unit and e2e test files to address formatting issues, improve readability, and ensure alignment with the new Prettier configuration.
2026-04-13 09:13:27 +02:00

62 lines
2.6 KiB
JavaScript

import { readFileSync } from "node:fs";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
const root = process.cwd();
const weatherModuleSource = readFileSync(
join(root, "src/components/session/token/superUser/modules/weatherapi/WeatherAPI.vue"),
"utf8"
);
const weatherConfigSource = readFileSync(
join(root, "src/components/session/token/superUser/modules/weatherapi/Config.vue"),
"utf8"
);
const weatherPageSource = readFileSync(
join(root, "src/views/dashboards/superUserDashboard/configuration/ConfigurationWeatherAPI.vue"),
"utf8"
);
describe("weatherapi module contract", () => {
it("defines module metadata and config endpoint", () => {
expect(weatherModuleSource).toContain('title: "WeatherAPI"');
expect(weatherModuleSource).toContain('endpoint: "/modules/weatherapi"');
expect(weatherModuleSource).toContain('config_endpoint: "/configuration/weatherapi"');
});
it("uses openapi weather module endpoints", () => {
expect(weatherModuleSource).toContain('"/modules/weatherapi/current?q="');
expect(weatherModuleSource).toContain('"/modules/weatherapi/forecast?q="');
expect(weatherModuleSource).toContain('"/modules/weatherapi/search?q="');
expect(weatherModuleSource).toContain("encodeURIComponent(query)");
});
it("supports optional forecast days parameter", () => {
expect(weatherModuleSource).toContain("Number.isInteger(days)");
expect(weatherModuleSource).toContain('"&days=" + days');
});
});
describe("weatherapi config contract", () => {
it("uses weatherapi config endpoints", () => {
expect(weatherConfigSource).toContain('"/weatherapi/config?variable=" + variable');
expect(weatherConfigSource).toContain('"/weatherapi/config"');
});
it("supports openapi config variables", () => {
expect(weatherConfigSource).toContain('Config.get("enabled")');
expect(weatherConfigSource).toContain('Config.get("secret_key")');
expect(weatherConfigSource).toContain('Config.set("enabled", enabled)');
expect(weatherConfigSource).toContain('Config.set("secret_key", value)');
});
it("exposes page controls for enabled and secret_key", () => {
expect(weatherPageSource).toContain("Enable WeatherAPI");
expect(weatherPageSource).toContain("getModuleConfigValue('enabled') === true");
expect(weatherPageSource).toContain("getModuleConfigValue('secret_key') !== ''");
expect(weatherPageSource).toContain(':on-switch="SessionUser.superUser.modules.weatherapi.config.enabled.set"');
expect(weatherPageSource).toContain(
':on-save="SessionUser.superUser.modules.weatherapi.config.keys.secret_key.set"'
);
});
});