@@ -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' }],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user