dorfteich/apps/api/src/search/search.provider.test.ts
Claude Fable 5 521ea514b4
Some checks failed
CI / Lint, typecheck, test (pull_request) Successful in 6m38s
CI / Build container images (pull_request) Successful in 4m14s
CI / Auth e2e pack (pull_request) Successful in 9m7s
CI / Import/export fidelity gate (pull_request) Successful in 1m6s
CD / Deploy to Test (push) Blocked by required conditions
CD / Smoke tests against Test (push) Blocked by required conditions
CD / Promote to Int (push) Blocked by required conditions
CI / Auth e2e pack (push) Blocked by required conditions
CI / Import/export fidelity gate (push) Blocked by required conditions
CI / Build container images (push) Blocked by required conditions
CD / Build and push images (push) Has been cancelled
CI / Lint, typecheck, test (push) Has been cancelled
#211: classification through feeds, public API, search and the no-JS shell
Feeds: classified entries carry a standard Atom <category>
(term=level, scheme=urn:dorfteich:classification, label=the fixed
wording); the feed document states the highest contained level once;
all-open feeds carry none. Public API: page representations (list+get)
gain the classification field, OpenAPI + public-api.md documented.
Search: every hit carries the level and the palette renders the marking
with the snippet (compact form of the banner, text token only). No-JS
shell: banner above and below the content, own markup for the separate
render path; unclassified pages unchanged everywhere. One test per
channel (feed categories + count, public API list/get with the switch
on, search hit levels, shell top+bottom).

Also: fidelity CI sidecars get per-job container names — the fixed
names collided across parallel runs on the shared host (run 547's red
fidelity job; a fixed-name cleanup could even kill a sibling's live
sidecars).

Co-Authored-By: Claude Fable 5 (1M context) <noreply@anthropic.com>
2026-07-31 07:23:53 +02:00

56 lines
1.7 KiB
TypeScript

import { SearchResultView } from '@dorfteich/shared';
import { Test } from '@nestjs/testing';
import { User } from '@prisma/client';
import { describe, expect, it, vi } from 'vitest';
import { AuthedRequest } from '../auth/auth.guard';
import { SearchController } from './search.controller';
import { SearchProvider } from './search.provider';
/**
* Proves the `SearchProvider` seam (ADR 0010 / issue #49): the controller
* depends on the abstract token, so a fake implementation can replace the
* PostgreSQL binding entirely in a test — which is exactly how an external
* engine would be swapped in.
*/
describe('SearchProvider DI seam (issue #49)', () => {
it('lets a fake provider replace the real binding', async () => {
const hit: SearchResultView = {
pageId: 'p1',
title: 'Hit',
slug: 'hit',
pondId: 'pond1',
pondSlug: 'pond',
pondName: 'Pond',
labelIds: [],
classification: 'unclassified',
snippet: 'a snippet',
};
const fake: SearchProvider = {
indexPage: vi.fn(),
removePage: vi.fn(),
removePond: vi.fn(),
reindexPond: vi.fn(),
reindexAll: vi.fn(),
search: vi.fn().mockResolvedValue([hit]),
};
const moduleRef = await Test.createTestingModule({
controllers: [SearchController],
providers: [{ provide: SearchProvider, useValue: fake }],
}).compile();
const controller = moduleRef.get(SearchController);
const user = { id: 'u1', isSiteAdmin: false } as User;
const result = await controller.query('hello', 'pond1', 'a,b', {
user,
} as AuthedRequest);
expect(result).toEqual([hit]);
expect(fake.search).toHaveBeenCalledWith(
{ q: 'hello', pondId: 'pond1', labels: ['a', 'b'] },
user,
);
});
});