This commit is contained in:
@@ -145,6 +145,121 @@ describe('TwitterClient home timeline', () => {
|
||||
});
|
||||
|
||||
describe('pagination', () => {
|
||||
it('returns the next cursor when stopping before the end', async () => {
|
||||
mockFetch.mockResolvedValueOnce({
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
data: {
|
||||
home: {
|
||||
home_timeline_urt: {
|
||||
instructions: [
|
||||
{
|
||||
entries: [
|
||||
{
|
||||
content: {
|
||||
itemContent: {
|
||||
tweet_results: {
|
||||
result: {
|
||||
rest_id: 'tweet1',
|
||||
legacy: { full_text: 'First tweet', created_at: 'Mon Jan 06 00:00:00 +0000 2025' },
|
||||
core: {
|
||||
user_results: {
|
||||
result: { rest_id: 'u1', legacy: { screen_name: 'user1', name: 'User 1' } },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
content: {
|
||||
cursorType: 'Bottom',
|
||||
value: 'cursor123',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
const client = new TwitterClient({ relayBaseUrl: testRelayBaseUrl });
|
||||
const result = await client.getHomeTimeline(1);
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
expect(result.nextCursor).toBe('cursor123');
|
||||
});
|
||||
|
||||
it('resumes from a provided cursor', async () => {
|
||||
mockFetch.mockResolvedValueOnce({
|
||||
ok: true,
|
||||
json: async () => makeHomeTimelineResponse('tweet2', 'Second page tweet', 'user2'),
|
||||
});
|
||||
|
||||
const client = new TwitterClient({ relayBaseUrl: testRelayBaseUrl });
|
||||
const result = await client.getHomeLatestTimeline(1, { cursor: 'resume-cursor' });
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
const callUrl = String(mockFetch.mock.calls[0]?.[0]);
|
||||
const variables = JSON.parse(new URL(callUrl).searchParams.get('variables') ?? '{}') as { cursor?: string };
|
||||
expect(variables.cursor).toBe('resume-cursor');
|
||||
});
|
||||
|
||||
it('stops at maxPages and returns the cursor to resume', async () => {
|
||||
mockFetch.mockResolvedValueOnce({
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
data: {
|
||||
home: {
|
||||
home_timeline_urt: {
|
||||
instructions: [
|
||||
{
|
||||
entries: [
|
||||
{
|
||||
content: {
|
||||
itemContent: {
|
||||
tweet_results: {
|
||||
result: {
|
||||
rest_id: 'tweet1',
|
||||
legacy: { full_text: 'First tweet', created_at: 'Mon Jan 06 00:00:00 +0000 2025' },
|
||||
core: {
|
||||
user_results: {
|
||||
result: { rest_id: 'u1', legacy: { screen_name: 'user1', name: 'User 1' } },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
content: {
|
||||
cursorType: 'Bottom',
|
||||
value: 'cursor-page-2',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
const client = new TwitterClient({ relayBaseUrl: testRelayBaseUrl });
|
||||
const result = await client.getHomeTimeline(5, { maxPages: 1 });
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
expect(result.tweets).toHaveLength(1);
|
||||
expect(result.nextCursor).toBe('cursor-page-2');
|
||||
expect(mockFetch).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should deduplicate tweets across pages', async () => {
|
||||
// First page
|
||||
mockFetch.mockResolvedValueOnce({
|
||||
|
||||
Reference in New Issue
Block a user