# test.deploy/core/steps/search.step.test.ts

> 46 lines of code and 0 definitions.

Tree: Codebase Testing
Language: typescript
Canonical: https://banes-lab.com/anatomy/testing#file-testing-test-deploy-core-steps-search-step-test-ts
Source text: https://banes-lab.com/source/testing/test.deploy/core/steps/search.step.test.ts.txt

Listed in [test.deploy/core/steps](https://banes-lab.com/api/source/testing/test.deploy/core/steps.md), after [test.deploy/core/steps/remote.step.test.ts](https://banes-lab.com/source/testing/test.deploy/core/steps/remote.step.test.ts.md) and before [test.deploy/core/steps/setup.step.test.ts](https://banes-lab.com/source/testing/test.deploy/core/steps/setup.step.test.ts.md).

## Contained in

- [test.deploy/core/steps](https://banes-lab.com/anatomy/testing/folder-testing-test-deploy-core-steps.md)

## Source

```typescript
import { PING_SKIPPED, pingAccepted, pingRefused } from "@banes-lab/deploy/configuration/strings/deployment.strings.ts";
import { describe, expect, it } from "vitest";
import type { SearchPing } from "@banes-lab/deploy/types/deployment.types.ts";
import { fakeJournal } from "./shell.fixture.ts";
import { pingSearch } from "@banes-lab/deploy/core/steps/search.step.ts";

const SITE = "https://x.test";
const KEY = "abcd1234";
const BEFORE = "<urlset><url><loc>https://x.test/</loc><lastmod>2026-10-01</lastmod></url></urlset>";
const AFTER = "<urlset><url><loc>https://x.test/</loc><lastmod>2026-10-07</lastmod></url></urlset>";

const poster = function poster(status: number): {
    readonly post: (endpoint: string, ping: SearchPing) => Promise<number>;
    readonly sent: readonly SearchPing[];
} {
    const sent: SearchPing[] = [];
    return {
        post: async (_endpoint, ping) => {
            sent.push(ping);
            return Promise.resolve(status);
        },
        sent,
    };
};

describe("pingSearch", () => {
    it("pings the changed pages with the key and its location, and journals the count", async () => {
        const journal = fakeJournal();
        const { post, sent } = poster(200);
        await expect(pingSearch(journal, SITE, KEY, { after: AFTER, before: BEFORE }, post)).resolves.toBe(1);
        expect(sent).toStrictEqual([
            { host: "x.test", key: KEY, keyLocation: "https://x.test/indexnow-key.txt", urlList: ["https://x.test/"] },
        ]);
        expect(journal.lines).toContain(pingAccepted(1));
    });

    it("sends nothing when no page changed", async () => {
        const journal = fakeJournal();
        const { post, sent } = poster(200);
        await expect(pingSearch(journal, SITE, KEY, { after: AFTER, before: AFTER }, post)).resolves.toBe(0);
        expect(sent).toStrictEqual([]);
        expect(journal.lines).toContain(PING_SKIPPED);
    });

    it("fails on a status the endpoint does not accept", async () => {
        const { post } = poster(403);
        await expect(pingSearch(fakeJournal(), SITE, KEY, { after: AFTER, before: null }, post)).rejects.toThrow(
            pingRefused(403),
        );
    });
});
```
