Skip to content

Instantly share code, notes, and snippets.

@YonatanKra
Created December 21, 2024 04:23
Show Gist options
  • Save YonatanKra/45834eff4b77819ff7fb87f493161447 to your computer and use it in GitHub Desktop.
Save YonatanKra/45834eff4b77819ff7fb87f493161447 to your computer and use it in GitHub Desktop.
it('should stream posts with done set to false when cursor is truthy', async () => {
const spy = vi.fn();
queueAgentFeedResponse(fullFeedResponse);
queueAgentFeedResponse(fullFeedResponse);
queueAgentFeedResponse(fullFeedLastResponse);
await bot.streamPosts(handle, spy);
expect(spy.mock.calls[0][0])
.toEqual({result: fullFeedResponse.data.feed, done: false});
expect(spy.mock.calls[1][0])
.toEqual({result: fullFeedResponse.data.feed, done: false});
expect(spy.mock.calls[2][0])
.toEqual({result: fullFeedLastResponse.data.feed, done: true});
});
it('should send done true to callback when response cursor is empty', async () => {
const spy = vi.fn();
queueAgentFeedResponse(fullFeedLastResponse);
await bot.streamPosts(handle, spy);
expect(spy.mock.calls[0][0])
.toEqual({result: fullFeedLastResponse.data.feed, done: true});
});
it('should send done true to callback when feed returns empty', async () => {
const spy = vi.fn();
queueAgentFeedResponse(emptyFeedResponse);
await bot.streamPosts(handle, spy);
expect(spy.mock.calls[0][0]).toEqual({ done: true });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment