fix(following): fallback to internal API
This commit is contained in:
@@ -201,6 +201,46 @@ describe('TwitterClient following/followers', () => {
|
||||
expect(mockFetch).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it('falls back to REST following list after repeated 404s', async () => {
|
||||
mockFetch
|
||||
.mockResolvedValueOnce({ ok: false, status: 404, text: async () => 'nope' })
|
||||
.mockResolvedValueOnce({ ok: false, status: 404, text: async () => 'still nope' })
|
||||
.mockResolvedValueOnce({
|
||||
ok: true,
|
||||
status: 200,
|
||||
json: async () => ({
|
||||
users: [
|
||||
{
|
||||
id_str: '1',
|
||||
screen_name: 'alpha',
|
||||
name: 'Alpha',
|
||||
description: 'bio-1',
|
||||
followers_count: 10,
|
||||
friends_count: 5,
|
||||
verified: true,
|
||||
profile_image_url_https: 'https://example.com/1.jpg',
|
||||
created_at: '2024-01-01T00:00:00Z',
|
||||
},
|
||||
],
|
||||
}),
|
||||
});
|
||||
|
||||
const client = new TwitterClient({ cookies: validCookies });
|
||||
const clientPrivate = client as unknown as TwitterClient & { getFollowingQueryIds: () => Promise<string[]> };
|
||||
clientPrivate.getFollowingQueryIds = async () => ['test'];
|
||||
|
||||
const result = await client.getFollowing('123', 1);
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
expect(result.users?.[0].username).toBe('alpha');
|
||||
expect(mockFetch).toHaveBeenCalledTimes(3);
|
||||
|
||||
const urls = mockFetch.mock.calls.map((call) => String(call[0]));
|
||||
expect(urls[0]).toContain('/Following?');
|
||||
expect(urls[1]).toContain('/Following?');
|
||||
expect(urls[2]).toContain('/friends/list.json?');
|
||||
});
|
||||
|
||||
it('falls back to REST followers list after repeated 404s', async () => {
|
||||
mockFetch
|
||||
.mockResolvedValueOnce({ ok: false, status: 404, text: async () => 'nope' })
|
||||
|
||||
Reference in New Issue
Block a user