@@ -14,6 +14,8 @@ describe('cli-args', () => {
|
||||
'bookmarks',
|
||||
'following',
|
||||
'followers',
|
||||
'user',
|
||||
'profiles',
|
||||
'likes',
|
||||
'help',
|
||||
'whoami',
|
||||
@@ -58,6 +60,11 @@ describe('cli-args', () => {
|
||||
expect(result.argv).toBeNull();
|
||||
});
|
||||
|
||||
it('does not rewrite numeric profile targets when profiles command is provided', () => {
|
||||
const result = resolveCliInvocation(['profiles', '@steipete', '25401953', '--json'], known);
|
||||
expect(result.argv).toBeNull();
|
||||
});
|
||||
|
||||
it('does not rewrite unknown commands', () => {
|
||||
const result = resolveCliInvocation(['https://example.com'], known);
|
||||
expect(result.argv).toBeNull();
|
||||
|
||||
@@ -209,4 +209,44 @@ describe('users commands', () => {
|
||||
expect(payload.nextCursor).toBeNull();
|
||||
expect(followingSpy).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it('prints a single profile as JSON', async () => {
|
||||
const program = new Command();
|
||||
registerUserCommands(program, baseCtx);
|
||||
const profileSpy = vi.spyOn(TwitterClient.prototype, 'getUserProfile').mockResolvedValue({
|
||||
success: true,
|
||||
profile: { id: '1', username: 'alpha', name: 'Alpha' },
|
||||
});
|
||||
|
||||
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => undefined);
|
||||
await program.parseAsync(['node', 'bird', 'user', '@alpha', '--json']);
|
||||
|
||||
expect(profileSpy).toHaveBeenCalledWith('@alpha');
|
||||
expect(JSON.parse(String(logSpy.mock.calls[0]?.[0]))).toMatchObject({
|
||||
id: '1',
|
||||
username: 'alpha',
|
||||
name: 'Alpha',
|
||||
});
|
||||
});
|
||||
|
||||
it('prints batch profiles with per-target errors as JSON', async () => {
|
||||
const program = new Command();
|
||||
registerUserCommands(program, baseCtx);
|
||||
const profilesSpy = vi.spyOn(TwitterClient.prototype, 'getUserProfiles').mockResolvedValue({
|
||||
success: true,
|
||||
results: [
|
||||
{ target: 'alpha', profile: { id: '1', username: 'alpha', name: 'Alpha' } },
|
||||
{ target: 'missing', error: 'not found' },
|
||||
],
|
||||
});
|
||||
|
||||
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => undefined);
|
||||
await program.parseAsync(['node', 'bird', 'profiles', 'alpha', 'missing', '--json']);
|
||||
|
||||
expect(profilesSpy).toHaveBeenCalledWith(['alpha', 'missing']);
|
||||
expect(JSON.parse(String(logSpy.mock.calls[0]?.[0]))).toEqual({
|
||||
users: [{ id: '1', username: 'alpha', name: 'Alpha' }],
|
||||
errors: [{ target: 'missing', error: 'not found' }],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -17,6 +17,8 @@ describe('root help output', () => {
|
||||
|
||||
expect(help).toContain('following');
|
||||
expect(help).toContain('followers');
|
||||
expect(help).toContain('user');
|
||||
expect(help).toContain('profiles');
|
||||
expect(help).toContain('likes');
|
||||
|
||||
expect(help).toContain('bird <tweet-id-or-url>');
|
||||
|
||||
@@ -163,4 +163,184 @@ describe('TwitterClient getUserIdByUsername', () => {
|
||||
expect(result.userId).toBe('99999');
|
||||
expect(mockFetch).toHaveBeenCalledTimes(3);
|
||||
});
|
||||
|
||||
it('resolves a rich profile by screen name', async () => {
|
||||
mockFetch.mockResolvedValueOnce({
|
||||
ok: true,
|
||||
status: 200,
|
||||
json: async () => ({
|
||||
data: {
|
||||
user: {
|
||||
result: {
|
||||
__typename: 'User',
|
||||
rest_id: '12345',
|
||||
is_blue_verified: true,
|
||||
verification_info: { reason: { verified_since_msec: '1700000000000' } },
|
||||
avatar: { image_url: 'https://pbs.twimg.com/profile_images/123/avatar_normal.jpg' },
|
||||
legacy: {
|
||||
screen_name: 'testuser',
|
||||
name: 'Test User',
|
||||
description: 'Building tools',
|
||||
location: 'Internet',
|
||||
url: 'https://t.co/site',
|
||||
created_at: 'Mon Jan 06 00:00:00 +0000 2025',
|
||||
verified: false,
|
||||
verified_type: 'Business',
|
||||
followers_count: 123,
|
||||
friends_count: 45,
|
||||
profile_image_url_https: 'https://pbs.twimg.com/profile_images/123/legacy_normal.jpg',
|
||||
entities: {
|
||||
url: {
|
||||
urls: [
|
||||
{
|
||||
url: 'https://t.co/site',
|
||||
expanded_url: 'https://example.com',
|
||||
display_url: 'example.com',
|
||||
},
|
||||
],
|
||||
},
|
||||
description: {
|
||||
urls: [
|
||||
{
|
||||
url: 'https://t.co/bio',
|
||||
expanded_url: 'https://bio.example',
|
||||
display_url: 'bio.example',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
affiliates_highlighted_label: {
|
||||
label: {
|
||||
description: 'Example Org',
|
||||
url: { url: 'https://x.com/example' },
|
||||
badge: { url: 'https://pbs.twimg.com/profile_images/org/badge.png' },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
const client = new TwitterClient({ relayBaseUrl: testRelayBaseUrl });
|
||||
const result = await client.getUserProfile('@testuser');
|
||||
|
||||
expect(result).toEqual({
|
||||
success: true,
|
||||
profile: expect.objectContaining({
|
||||
id: '12345',
|
||||
username: 'testuser',
|
||||
name: 'Test User',
|
||||
description: 'Building tools',
|
||||
location: 'Internet',
|
||||
url: 'https://example.com',
|
||||
verified: true,
|
||||
verifiedType: 'Business',
|
||||
followersCount: 123,
|
||||
followingCount: 45,
|
||||
profileImageUrl: 'https://pbs.twimg.com/profile_images/123/avatar_normal.jpg',
|
||||
entities: expect.objectContaining({
|
||||
url: expect.objectContaining({
|
||||
urls: [expect.objectContaining({ expanded_url: 'https://example.com' })],
|
||||
}),
|
||||
}),
|
||||
affiliation: {
|
||||
description: 'Example Org',
|
||||
url: 'https://x.com/example',
|
||||
badgeUrl: 'https://pbs.twimg.com/profile_images/org/badge.png',
|
||||
},
|
||||
raw: expect.any(Object),
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
it('resolves a rich profile by user id', async () => {
|
||||
mockFetch.mockResolvedValueOnce({
|
||||
ok: true,
|
||||
status: 200,
|
||||
json: async () => ({
|
||||
data: {
|
||||
user: {
|
||||
result: {
|
||||
__typename: 'User',
|
||||
rest_id: '42',
|
||||
core: {
|
||||
screen_name: 'byid',
|
||||
name: 'By Id',
|
||||
created_at: 'Tue Feb 01 00:00:00 +0000 2022',
|
||||
},
|
||||
location: {
|
||||
location: 'Vienna & London',
|
||||
},
|
||||
legacy: {
|
||||
description: 'Lookup by id',
|
||||
followers_count: 10,
|
||||
friends_count: 2,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
const client = new TwitterClient({ relayBaseUrl: testRelayBaseUrl });
|
||||
const result = await client.getUserProfile('42');
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
expect(result.profile).toMatchObject({
|
||||
id: '42',
|
||||
username: 'byid',
|
||||
name: 'By Id',
|
||||
description: 'Lookup by id',
|
||||
location: 'Vienna & London',
|
||||
createdAt: 'Tue Feb 01 00:00:00 +0000 2022',
|
||||
followersCount: 10,
|
||||
followingCount: 2,
|
||||
});
|
||||
expect(String(mockFetch.mock.calls[0]?.[0])).toContain('/UserByRestId?');
|
||||
});
|
||||
|
||||
it('resolves profile batches with per-target errors', async () => {
|
||||
mockFetch
|
||||
.mockResolvedValueOnce({
|
||||
ok: true,
|
||||
status: 200,
|
||||
json: async () => ({
|
||||
data: {
|
||||
user: {
|
||||
result: {
|
||||
__typename: 'User',
|
||||
rest_id: '1',
|
||||
legacy: { screen_name: 'alpha', name: 'Alpha' },
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
})
|
||||
.mockResolvedValueOnce({
|
||||
ok: true,
|
||||
status: 200,
|
||||
json: async () => ({
|
||||
data: {
|
||||
user: {
|
||||
result: {
|
||||
__typename: 'UserUnavailable',
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
const client = new TwitterClient({ relayBaseUrl: testRelayBaseUrl });
|
||||
const result = await client.getUserProfiles(['alpha', 'missing']);
|
||||
|
||||
expect(result).toEqual({
|
||||
success: true,
|
||||
results: [
|
||||
{ target: 'alpha', profile: expect.objectContaining({ id: '1', username: 'alpha' }) },
|
||||
{ target: 'missing', error: 'User @missing not found or unavailable' },
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user