fix: parse verify credentials user id
This commit is contained in:
@@ -205,6 +205,10 @@ export function withUsers<TBase extends AbstractConstructor<TwitterClientBase>>(
|
|||||||
? data.user_id
|
? data.user_id
|
||||||
: typeof data?.user_id_str === 'string'
|
: typeof data?.user_id_str === 'string'
|
||||||
? data.user_id_str
|
? data.user_id_str
|
||||||
|
: typeof data?.id_str === 'string'
|
||||||
|
? data.id_str
|
||||||
|
: typeof data?.id === 'string'
|
||||||
|
? data.id
|
||||||
: typeof data?.user?.id_str === 'string'
|
: typeof data?.user?.id_str === 'string'
|
||||||
? data.user.id_str
|
? data.user.id_str
|
||||||
: typeof data?.user?.id === 'string'
|
: typeof data?.user?.id === 'string'
|
||||||
|
|||||||
@@ -107,6 +107,24 @@ describe('TwitterClient getCurrentUser', () => {
|
|||||||
expect(mockFetch).toHaveBeenCalledTimes(2);
|
expect(mockFetch).toHaveBeenCalledTimes(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('reads top-level id_str from verify_credentials responses', async () => {
|
||||||
|
mockFetch.mockResolvedValue({
|
||||||
|
ok: true,
|
||||||
|
status: 200,
|
||||||
|
json: async () => ({
|
||||||
|
id_str: '12345',
|
||||||
|
screen_name: 'tester',
|
||||||
|
name: 'Test User',
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
const client = new TwitterClient({ relayBaseUrl: testRelayBaseUrl });
|
||||||
|
const result = await client.getCurrentUser();
|
||||||
|
|
||||||
|
expect(result.success).toBe(true);
|
||||||
|
expect(result.user).toEqual({ id: '12345', username: 'tester', name: 'Test User' });
|
||||||
|
});
|
||||||
|
|
||||||
it('continues on fetch errors and still succeeds via later API endpoint', async () => {
|
it('continues on fetch errors and still succeeds via later API endpoint', async () => {
|
||||||
mockFetch
|
mockFetch
|
||||||
.mockRejectedValueOnce(new Error('boom'))
|
.mockRejectedValueOnce(new Error('boom'))
|
||||||
|
|||||||
Reference in New Issue
Block a user