import { AxiosResponse, AxiosStatic } from "axios"; import { expect } from "chai"; import EventEmitter from "events"; import { BridgeConfigFeeds } from "../src/Config/Config"; import { ConnectionManager } from "../src/ConnectionManager"; import { IConnection } from "../src/Connections"; import { FeedReader } from "../src/feeds/FeedReader"; import { MessageQueue, MessageQueueMessage } from "../src/MessageQueue"; class MockConnectionManager extends EventEmitter { constructor( public connections: IConnection[] ) { super(); } getAllConnectionsOfType() { return this.connections; } } class MockMessageQueue extends EventEmitter implements MessageQueue { subscribe(eventGlob: string): void { this.emit('subscribed', eventGlob); } unsubscribe(eventGlob: string): void { this.emit('unsubscribed', eventGlob); } async push(data: MessageQueueMessage, single?: boolean): Promise { this.emit('pushed', data, single); } async pushWait(): Promise { throw new Error('Not yet implemented'); } } class MockHttpClient { constructor(public response: AxiosResponse) {} get(): Promise { return Promise.resolve(this.response); } } describe("FeedReader", () => { it("should correctly handle empty titles", async () => { const config = new BridgeConfigFeeds({ enabled: true, pollIntervalSeconds: 1, pollTimeoutSeconds: 1, }); const cm = new MockConnectionManager([{ feedUrl: 'http://test/' } as unknown as IConnection]) as unknown as ConnectionManager const mq = new MockMessageQueue(); const feedContents = ` test feedhttp://test/ Wed, 12 Apr 2023 09:53:00 GMT test item http://example.com/test/1681293180 http://example.com/test/1681293180 Wed, 12 Apr 2023 09:53:00 GMT `; const feedReader = new FeedReader( config, cm, mq, { getAccountData: () => Promise.resolve({ 'http://test/': [] } as unknown as T), setAccountData: () => Promise.resolve(), }, new MockHttpClient({ headers: {}, data: feedContents } as AxiosResponse) as unknown as AxiosStatic, ); const event: any = await new Promise((resolve) => { mq.on('pushed', (data) => { resolve(data); feedReader.stop() }); }); expect(event.eventName).to.equal('feed.entry'); expect(event.data.feed.title).to.equal(null); expect(event.data.title).to.equal(null); }); });