test: cover about command
This commit is contained in:
@@ -9,6 +9,7 @@ const baseCtx = {
|
|||||||
resolveRelayBaseUrlFromOptions: () => 'https://relay.example',
|
resolveRelayBaseUrlFromOptions: () => 'https://relay.example',
|
||||||
resolveProfileNameFromOptions: () => undefined,
|
resolveProfileNameFromOptions: () => undefined,
|
||||||
p: () => '',
|
p: () => '',
|
||||||
|
l: () => '',
|
||||||
printTweets: () => undefined,
|
printTweets: () => undefined,
|
||||||
} as unknown as CliContext;
|
} as unknown as CliContext;
|
||||||
|
|
||||||
@@ -209,4 +210,54 @@ describe('users commands', () => {
|
|||||||
expect(payload.nextCursor).toBeNull();
|
expect(payload.nextCursor).toBeNull();
|
||||||
expect(followingSpy).toHaveBeenCalledTimes(2);
|
expect(followingSpy).toHaveBeenCalledTimes(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('prints account info JSON for about command', async () => {
|
||||||
|
const program = new Command();
|
||||||
|
registerUserCommands(program, baseCtx);
|
||||||
|
vi.spyOn(TwitterClient.prototype, 'getUserAboutAccount').mockResolvedValue({
|
||||||
|
success: true,
|
||||||
|
aboutProfile: {
|
||||||
|
accountBasedIn: 'Spain',
|
||||||
|
source: 'Spain App Store',
|
||||||
|
createdCountryAccurate: true,
|
||||||
|
locationAccurate: false,
|
||||||
|
learnMoreUrl: 'https://help.twitter.com/profile',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => undefined);
|
||||||
|
await program.parseAsync(['node', 'bird', 'about', 'pablotovar_', '--json']);
|
||||||
|
|
||||||
|
const payload = JSON.parse(String(logSpy.mock.calls[0]?.[0]));
|
||||||
|
expect(payload).toEqual({
|
||||||
|
accountBasedIn: 'Spain',
|
||||||
|
source: 'Spain App Store',
|
||||||
|
createdCountryAccurate: true,
|
||||||
|
locationAccurate: false,
|
||||||
|
learnMoreUrl: 'https://help.twitter.com/profile',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('exits on about command failure', async () => {
|
||||||
|
const program = new Command();
|
||||||
|
registerUserCommands(program, baseCtx);
|
||||||
|
const exitSpy = vi.spyOn(process, 'exit').mockImplementation(((code?: number) => {
|
||||||
|
throw new Error(`exit ${code}`);
|
||||||
|
}) as never);
|
||||||
|
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => undefined);
|
||||||
|
vi.spyOn(TwitterClient.prototype, 'getUserAboutAccount').mockResolvedValue({
|
||||||
|
success: false,
|
||||||
|
error: 'Missing about_profile in response',
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
await expect(program.parseAsync(['node', 'bird', 'about', 'pablotovar__'])).rejects.toThrow('exit 1');
|
||||||
|
expect(errorSpy).toHaveBeenCalledWith(
|
||||||
|
expect.stringContaining('Failed to fetch account information: Missing about_profile in response'),
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
exitSpy.mockRestore();
|
||||||
|
errorSpy.mockRestore();
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user