test.deploy/core/converters/search.converter.test.ts

test.deploy/core/converters/search.converter.test.ts is a file in Codebase Testing. 40 lines of code and 0 definitions.

import { changedLocations, stampsOf } from "@banes-lab/deploy/core/converters/search.converter.ts";
import { describe, expect, it } from "vitest";

const HOME = "https://x.test/";
const TERMS = "https://x.test/terms";
const ABOUT = "https://x.test/about";
const FIRST = "2026-10-01";
const LATER = "2026-10-07";

const sitemapOf = function sitemapOf(rows: readonly (readonly [string, string | null])[]): string {
    const urls = rows.map(([loc, lastmod]) =>
        lastmod === null ? `<url><loc>${loc}</loc></url>` : `<url><loc>${loc}</loc><lastmod>${lastmod}</lastmod></url>`,
    );
    return `<?xml version="1.0"?><urlset>${urls.join("")}</urlset>`;
};

describe("stampsOf", () => {
    it("reads each location with its last modification day, and none where the entry has no day", () => {
        const stamps = stampsOf(sitemapOf([[HOME, FIRST], [TERMS, null]]));
        expect([...stamps]).toStrictEqual([
            [HOME, FIRST],
            [TERMS, null],
        ]);
    });
});

describe("changedLocations", () => {
    const before = sitemapOf([
        [HOME, FIRST],
        [TERMS, FIRST],
    ]);

    it("names a location whose day moved and a location the live sitemap lacks, and none that held", () => {
        const after = sitemapOf([
            [HOME, LATER],
            [TERMS, FIRST],
            [ABOUT, LATER],
        ]);
        expect(changedLocations(before, after)).toStrictEqual([HOME, ABOUT]);
        expect(changedLocations(before, before)).toStrictEqual([]);
    });

    it("names every location when no live sitemap was read", () => {
        expect(changedLocations(null, before)).toStrictEqual([HOME, TERMS]);
    });
});