91 lines
3.8 KiB
TypeScript
91 lines
3.8 KiB
TypeScript
import { describe, expect, test, vi } from "vitest";
|
|
|
|
vi.mock("./db/appConfiguration.db.server", () => ({
|
|
getAppConfiguration: vi.fn(),
|
|
}));
|
|
|
|
vi.mock("~/locale/i18n", async (importOriginal) => ({
|
|
...(await importOriginal<typeof import("~/locale/i18n")>()),
|
|
i18nConfig: { supportedLngs: ["en"], fallbackLng: "en" },
|
|
}));
|
|
|
|
vi.mock("~/modules/knowledgeBase/service/KnowledgeBaseService.server", () => ({
|
|
default: {
|
|
getAll: vi.fn(),
|
|
getCategories: vi.fn(),
|
|
getArticles: vi.fn(),
|
|
},
|
|
}));
|
|
|
|
vi.mock("~/modules/knowledgeBase/utils/KnowledgeBaseUtils", () => ({
|
|
default: {
|
|
getKbUrl: vi.fn(),
|
|
getCategoryUrl: vi.fn(),
|
|
getArticleUrl: vi.fn(),
|
|
},
|
|
}));
|
|
|
|
vi.mock("~/modules/knowledgeBase/services/publicKnowledgeBaseRls.server", () => ({
|
|
withPublicKnowledgeBaseRlsContext: vi.fn(async (_slug: string, operation: () => Promise<unknown>) => operation()),
|
|
}));
|
|
|
|
import KnowledgeBaseServiceServer from "~/modules/knowledgeBase/service/KnowledgeBaseService.server";
|
|
import { withPublicKnowledgeBaseRlsContext } from "~/modules/knowledgeBase/services/publicKnowledgeBaseRls.server";
|
|
import KnowledgeBaseUtils from "~/modules/knowledgeBase/utils/KnowledgeBaseUtils";
|
|
import { getAppConfiguration } from "./db/appConfiguration.db.server";
|
|
import { getSitemapDomainUrl, getSitemapXml, isAdminHostSitemapRoute, shouldSkipSitemapRouteId } from "./sitemap.server";
|
|
|
|
describe("getSitemapDomainUrl", () => {
|
|
test("uses canonical routing config instead of request hosts", () => {
|
|
expect(
|
|
getSitemapDomainUrl({
|
|
appBaseDomain: "example.test",
|
|
webAppHost: "app.example.test",
|
|
adminAppHost: "admin.example.test",
|
|
apiHost: "api.example.test",
|
|
protocol: "https",
|
|
})
|
|
).toBe("https://app.example.test");
|
|
});
|
|
|
|
test("skips host clone route ids", () => {
|
|
expect(shouldSkipSitemapRouteId("routes/admin/settings.__host")).toBe(true);
|
|
expect(shouldSkipSitemapRouteId("routes/admin/settings")).toBe(true);
|
|
});
|
|
|
|
test("detects admin-host sitemap routes that must not be emitted on the app host", () => {
|
|
expect(isAdminHostSitemapRoute("/dashboard")).toBe(true);
|
|
expect(isAdminHostSitemapRoute("/settings")).toBe(true);
|
|
expect(isAdminHostSitemapRoute("/acme/dashboard")).toBe(false);
|
|
expect(isAdminHostSitemapRoute("/login")).toBe(false);
|
|
});
|
|
|
|
test("enumerates only resolver-approved public knowledge bases and scopes their descendants", async () => {
|
|
vi.mocked(getAppConfiguration).mockResolvedValue({ subscription: { allowSignUpBeforeSubscribe: true } } as never);
|
|
vi.mocked(KnowledgeBaseServiceServer.getAll).mockResolvedValue([
|
|
{
|
|
id: "kb-public",
|
|
slug: "docs",
|
|
createdAt: new Date("2026-07-14T00:00:00.000Z"),
|
|
updatedAt: null,
|
|
defaultLanguage: "de",
|
|
} as never,
|
|
]);
|
|
vi.mocked(KnowledgeBaseServiceServer.getCategories).mockResolvedValue([{ id: "category-public" } as never]);
|
|
vi.mocked(KnowledgeBaseServiceServer.getArticles).mockResolvedValue([{ id: "article-public", updatedAt: null, createdAt: new Date() } as never]);
|
|
vi.mocked(KnowledgeBaseUtils.getKbUrl).mockReturnValue("/docs");
|
|
vi.mocked(KnowledgeBaseUtils.getCategoryUrl).mockReturnValue("/docs/categories/public");
|
|
vi.mocked(KnowledgeBaseUtils.getArticleUrl).mockReturnValue("/docs/articles/public");
|
|
|
|
const xml = await getSitemapXml(new Request("https://app.example.test/sitemap.xml"), {
|
|
routeModules: {},
|
|
manifest: { routes: {} },
|
|
} as never);
|
|
|
|
expect(KnowledgeBaseServiceServer.getAll).toHaveBeenCalledWith(expect.objectContaining({ enabled: true, publicOnly: true }));
|
|
expect(withPublicKnowledgeBaseRlsContext).toHaveBeenCalledWith("docs", expect.any(Function));
|
|
expect(xml).toContain("/docs/categories/public");
|
|
expect(xml).toContain("/docs/articles/public");
|
|
});
|
|
});
|