test(cli): always print tweet URL
This commit is contained in:
+3
-2
@@ -21,6 +21,7 @@ import { extractTweetId } from './lib/extract-tweet-id.js';
|
||||
import { mentionsQueryFromUserOption, normalizeHandle } from './lib/normalize-handle.js';
|
||||
import {
|
||||
formatStatsLine,
|
||||
formatTweetUrlLine,
|
||||
labelPrefix,
|
||||
type OutputConfig,
|
||||
resolveOutputConfigFromArgv,
|
||||
@@ -403,7 +404,7 @@ program
|
||||
|
||||
if (result.success) {
|
||||
console.log(`${p('ok')}Tweet posted successfully!`);
|
||||
console.log(`${l('url')}https://x.com/i/status/${result.tweetId}`);
|
||||
console.log(formatTweetUrlLine(result.tweetId, output));
|
||||
} else {
|
||||
console.error(`${p('err')}Failed to post tweet: ${result.error}`);
|
||||
process.exit(1);
|
||||
@@ -464,7 +465,7 @@ program
|
||||
|
||||
if (result.success) {
|
||||
console.log(`${p('ok')}Reply posted successfully!`);
|
||||
console.log(`${l('url')}https://x.com/i/status/${result.tweetId}`);
|
||||
console.log(formatTweetUrlLine(result.tweetId, output));
|
||||
} else {
|
||||
console.error(`${p('err')}Failed to post reply: ${result.error}`);
|
||||
process.exit(1);
|
||||
|
||||
@@ -76,3 +76,11 @@ export function formatStatsLine(
|
||||
if (!cfg.emoji) return `Likes ${likeCount} Retweets ${retweetCount} Replies ${replyCount}`;
|
||||
return `❤️ ${likeCount} 🔁 ${retweetCount} 💬 ${replyCount}`;
|
||||
}
|
||||
|
||||
export function formatTweetUrl(tweetId: string): string {
|
||||
return `https://x.com/i/status/${tweetId}`;
|
||||
}
|
||||
|
||||
export function formatTweetUrlLine(tweetId: string, cfg: OutputConfig): string {
|
||||
return `${labelPrefix('url', cfg)}${formatTweetUrl(tweetId)}`;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
formatStatsLine,
|
||||
formatTweetUrlLine,
|
||||
labelPrefix,
|
||||
resolveOutputConfigFromArgv,
|
||||
resolveOutputConfigFromCommander,
|
||||
@@ -62,4 +63,13 @@ describe('output', () => {
|
||||
expect(formatStatsLine(stats, { plain: false, emoji: false, color: false })).toBe('Likes 0 Retweets 0 Replies 2');
|
||||
expect(formatStatsLine(stats, { plain: false, emoji: true, color: false })).toBe('❤️ 0 🔁 0 💬 2');
|
||||
});
|
||||
|
||||
it('always includes tweet URL in all modes', () => {
|
||||
const id = '1234567890';
|
||||
const url = `https://x.com/i/status/${id}`;
|
||||
|
||||
expect(formatTweetUrlLine(id, { plain: true, emoji: false, color: false })).toContain(url);
|
||||
expect(formatTweetUrlLine(id, { plain: false, emoji: false, color: false })).toContain(url);
|
||||
expect(formatTweetUrlLine(id, { plain: false, emoji: true, color: false })).toContain(url);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user