Intermediate commit
This commit is contained in:
parent
0e9e49df16
commit
3d4cfeff1a
65 changed files with 5507 additions and 333 deletions
|
|
@ -49,6 +49,35 @@ function buildRunsPayload(runs: ReturnType<typeof buildRun>[]) {
|
|||
};
|
||||
}
|
||||
|
||||
class FakeEventSource {
|
||||
static instances: FakeEventSource[] = [];
|
||||
|
||||
public readonly url: string;
|
||||
public closed = false;
|
||||
private listeners = new Map<string, Array<(event: { data: string }) => void>>();
|
||||
|
||||
constructor(url: string) {
|
||||
this.url = url;
|
||||
FakeEventSource.instances.push(this);
|
||||
}
|
||||
|
||||
addEventListener(eventType: string, callback: (event: { data: string }) => void): void {
|
||||
const existing = this.listeners.get(eventType) ?? [];
|
||||
this.listeners.set(eventType, [...existing, callback]);
|
||||
}
|
||||
|
||||
emit(eventType: string, payload: unknown): void {
|
||||
const callbacks = this.listeners.get(eventType) ?? [];
|
||||
for (const callback of callbacks) {
|
||||
callback({ data: JSON.stringify(payload) });
|
||||
}
|
||||
}
|
||||
|
||||
close(): void {
|
||||
this.closed = true;
|
||||
}
|
||||
}
|
||||
|
||||
describe("run status store", () => {
|
||||
const mockedListRuns = vi.mocked(listRuns);
|
||||
const mockedTriggerManualRun = vi.mocked(triggerManualRun);
|
||||
|
|
@ -309,4 +338,42 @@ describe("run status store", () => {
|
|||
|
||||
expect(store.latestRun?.new_publication_count).toBe(5);
|
||||
});
|
||||
|
||||
it("applies identifier_updated SSE events to live publications", () => {
|
||||
const previousEventSource = (globalThis as any).EventSource;
|
||||
FakeEventSource.instances = [];
|
||||
(globalThis as any).EventSource = FakeEventSource as any;
|
||||
try {
|
||||
const store = useRunStatusStore();
|
||||
store.setLatestRun(buildRun({ id: 314, status: "running", end_dt: null }));
|
||||
|
||||
const stream = FakeEventSource.instances[0];
|
||||
expect(stream).toBeDefined();
|
||||
stream.emit("publication_discovered", {
|
||||
publication_id: 22,
|
||||
scholar_profile_id: 7,
|
||||
scholar_label: "Ada Lovelace",
|
||||
title: "Optimization Notes",
|
||||
pub_url: null,
|
||||
first_seen_at: "2026-02-26T10:00:00Z",
|
||||
});
|
||||
expect(store.livePublications).toHaveLength(1);
|
||||
expect(store.livePublications[0].display_identifier).toBeNull();
|
||||
|
||||
stream.emit("identifier_updated", {
|
||||
publication_id: 22,
|
||||
display_identifier: {
|
||||
kind: "doi",
|
||||
value: "10.1000/xyz",
|
||||
label: "DOI: 10.1000/xyz",
|
||||
url: "https://doi.org/10.1000/xyz",
|
||||
confidence_score: 0.95,
|
||||
},
|
||||
});
|
||||
expect(store.livePublications[0].display_identifier?.kind).toBe("doi");
|
||||
expect(store.livePublications[0].display_identifier?.value).toBe("10.1000/xyz");
|
||||
} finally {
|
||||
(globalThis as any).EventSource = previousEventSource;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue