fix: parse verify credentials user id
CI / test (push) Successful in 9m59s
Publish npm package / publish (push) Failing after 5m12s

This commit is contained in:
2026-06-24 16:33:43 +09:00
parent ea7e5191b2
commit 7a036e244d
2 changed files with 27 additions and 5 deletions
+9 -5
View File
@@ -205,11 +205,15 @@ 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?.user?.id_str === 'string' : typeof data?.id_str === 'string'
? data.user.id_str ? data.id_str
: typeof data?.user?.id === 'string' : typeof data?.id === 'string'
? data.user.id ? data.id
: null; : typeof data?.user?.id_str === 'string'
? data.user.id_str
: typeof data?.user?.id === 'string'
? data.user.id
: null;
if (username && userId) { if (username && userId) {
this.clientUserId = userId; this.clientUserId = userId;
+18
View File
@@ -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'))