@jackwener/opencli 1.7.22 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -194
- package/README.zh-CN.md +42 -260
- package/cli-manifest.json +8160 -4392
- package/clis/12306/me.js +73 -0
- package/clis/12306/orders.js +96 -0
- package/clis/12306/passengers.js +90 -0
- package/clis/12306/price.js +166 -0
- package/clis/12306/stations.js +66 -0
- package/clis/12306/train.js +91 -0
- package/clis/12306/trains.js +119 -0
- package/clis/12306/utils.js +272 -0
- package/clis/12306/utils.test.js +331 -0
- package/clis/36kr/article.js +6 -3
- package/clis/36kr/article.test.js +46 -0
- package/clis/_atlassian/shared.js +577 -0
- package/clis/_atlassian/shared.test.js +170 -0
- package/clis/apple-podcasts/commands.test.js +20 -0
- package/clis/apple-podcasts/search.js +2 -2
- package/clis/barchart/greeks.js +144 -56
- package/clis/barchart/greeks.test.js +138 -0
- package/clis/bilibili/comment.js +125 -0
- package/clis/bilibili/comment.test.js +153 -0
- package/clis/bilibili/comments.js +116 -21
- package/clis/bilibili/comments.test.js +77 -18
- package/clis/bilibili/subtitle.js +76 -31
- package/clis/bilibili/subtitle.test.js +156 -9
- package/clis/bilibili/summary.js +167 -0
- package/clis/bilibili/summary.test.js +210 -0
- package/clis/bilibili/utils.js +63 -5
- package/clis/bilibili/utils.test.js +45 -1
- package/clis/booking/booking.test.js +356 -0
- package/clis/booking/search.js +351 -0
- package/clis/chatgpt/envelope.test.js +108 -0
- package/clis/chatgpt/image.js +2 -2
- package/clis/chatgpt/image.test.js +6 -0
- package/clis/chatgpt/utils.js +148 -41
- package/clis/chatgpt/utils.test.js +92 -2
- package/clis/chess/analyze.js +35 -0
- package/clis/chess/analyze.test.js +79 -0
- package/clis/chess/game.js +114 -0
- package/clis/chess/game.test.js +178 -0
- package/clis/chess/games.js +67 -0
- package/clis/chess/games.test.js +164 -0
- package/clis/chess/stats.js +32 -0
- package/clis/chess/stats.test.js +79 -0
- package/clis/chess/utils.js +170 -0
- package/clis/chess/utils.test.js +230 -0
- package/clis/confluence/commands.test.js +195 -0
- package/clis/confluence/create.js +39 -0
- package/clis/confluence/page.js +23 -0
- package/clis/confluence/search.js +34 -0
- package/clis/confluence/shared.js +173 -0
- package/clis/confluence/update.js +38 -0
- package/clis/douyin/_shared/browser-fetch.js +44 -20
- package/clis/douyin/_shared/browser-fetch.test.js +22 -1
- package/clis/douyin/_shared/evaluate-result.js +16 -0
- package/clis/douyin/_shared/tos-upload.js +105 -69
- package/clis/douyin/_shared/vod-upload.js +212 -0
- package/clis/douyin/_shared/vod-upload.test.js +38 -0
- package/clis/douyin/delete.js +137 -4
- package/clis/douyin/delete.test.js +90 -1
- package/clis/douyin/hashtag.js +84 -23
- package/clis/douyin/hashtag.test.js +113 -0
- package/clis/douyin/publish-upload-id.test.js +170 -0
- package/clis/douyin/publish.js +88 -42
- package/clis/douyin/user-videos.js +9 -2
- package/clis/douyin/user-videos.test.js +43 -0
- package/clis/flomo/memos.js +228 -0
- package/clis/flomo/memos.test.js +144 -0
- package/clis/geogebra/add-circle.js +46 -0
- package/clis/geogebra/add-line.js +35 -0
- package/clis/geogebra/add-point.js +27 -0
- package/clis/geogebra/add-polygon.js +25 -0
- package/clis/geogebra/eval.js +35 -0
- package/clis/geogebra/geogebra.test.js +175 -0
- package/clis/geogebra/hexagon.js +62 -0
- package/clis/geogebra/info.js +72 -0
- package/clis/geogebra/list.js +35 -0
- package/clis/geogebra/triangle.js +60 -0
- package/clis/geogebra/utils.js +271 -0
- package/clis/gitee/search.js +2 -2
- package/clis/gitee/search.test.js +65 -0
- package/clis/jike/post.js +27 -17
- package/clis/jike/read.test.js +86 -0
- package/clis/jike/topic.js +32 -19
- package/clis/jike/user.js +33 -20
- package/clis/jira/attachments.js +28 -0
- package/clis/jira/commands.test.js +287 -0
- package/clis/jira/comments.js +28 -0
- package/clis/jira/issue.js +28 -0
- package/clis/jira/links.js +28 -0
- package/clis/jira/search.js +47 -0
- package/clis/jira/shared.js +256 -0
- package/clis/lesswrong/comments.js +1 -1
- package/clis/lesswrong/curated.js +1 -1
- package/clis/lesswrong/frontpage.js +1 -1
- package/clis/lesswrong/frontpage.test.js +37 -0
- package/clis/lesswrong/new.js +1 -1
- package/clis/lesswrong/read.js +1 -1
- package/clis/lesswrong/sequences.js +1 -1
- package/clis/lesswrong/shortform.js +1 -1
- package/clis/lesswrong/tag.js +1 -1
- package/clis/lesswrong/top-month.js +1 -1
- package/clis/lesswrong/top-week.js +1 -1
- package/clis/lesswrong/top-year.js +1 -1
- package/clis/lesswrong/top.js +1 -1
- package/clis/linkedin/connect.js +401 -0
- package/clis/linkedin/connect.test.js +213 -0
- package/clis/linkedin/inbox.js +234 -0
- package/clis/linkedin/inbox.test.js +152 -0
- package/clis/linkedin/job-detail.js +167 -0
- package/clis/linkedin/job-detail.test.js +38 -0
- package/clis/linkedin/jobs-preferences.js +113 -0
- package/clis/linkedin/jobs-preferences.test.js +43 -0
- package/clis/linkedin/people-search.js +262 -0
- package/clis/linkedin/people-search.test.js +216 -0
- package/clis/linkedin/post-analytics.js +74 -0
- package/clis/linkedin/post-analytics.test.js +40 -0
- package/clis/linkedin/posts-core.js +241 -0
- package/clis/linkedin/posts.js +22 -0
- package/clis/linkedin/posts.test.js +40 -0
- package/clis/linkedin/profile-analytics.js +104 -0
- package/clis/linkedin/profile-analytics.test.js +67 -0
- package/clis/linkedin/profile-experience.js +671 -0
- package/clis/linkedin/profile-experience.test.js +152 -0
- package/clis/linkedin/profile-projects.js +311 -0
- package/clis/linkedin/profile-projects.test.js +111 -0
- package/clis/linkedin/profile-read.js +148 -0
- package/clis/linkedin/profile-read.test.js +77 -0
- package/clis/linkedin/safe-send.js +357 -0
- package/clis/linkedin/safe-send.test.js +204 -0
- package/clis/linkedin/salesnav-inbox.js +210 -0
- package/clis/linkedin/salesnav-inbox.test.js +113 -0
- package/clis/linkedin/salesnav-message.js +360 -0
- package/clis/linkedin/salesnav-message.test.js +172 -0
- package/clis/linkedin/salesnav-search.js +186 -0
- package/clis/linkedin/salesnav-search.test.js +76 -0
- package/clis/linkedin/salesnav-thread.js +212 -0
- package/clis/linkedin/salesnav-thread.test.js +79 -0
- package/clis/linkedin/sent-invitations.js +92 -0
- package/clis/linkedin/sent-invitations.test.js +62 -0
- package/clis/linkedin/services-read.js +213 -0
- package/clis/linkedin/services-read.test.js +105 -0
- package/clis/linkedin/shared.js +124 -0
- package/clis/linkedin/thread-snapshot.js +214 -0
- package/clis/linkedin/thread-snapshot.test.js +89 -0
- package/clis/linkedin/timeline.js +14 -7
- package/clis/linkedin-learning/course.js +138 -0
- package/clis/linkedin-learning/course.test.js +114 -0
- package/clis/linkedin-learning/search.js +155 -0
- package/clis/linkedin-learning/search.test.js +144 -0
- package/clis/linkedin-learning/trending.js +133 -0
- package/clis/linkedin-learning/trending.test.js +123 -0
- package/clis/notebooklm/add-source.js +269 -0
- package/clis/notebooklm/add-source.test.js +97 -0
- package/clis/notebooklm/create.js +76 -0
- package/clis/notebooklm/create.test.js +58 -0
- package/clis/notebooklm/generate-audio.js +91 -0
- package/clis/notebooklm/generate-audio.test.js +63 -0
- package/clis/notebooklm/generate-slides.js +106 -0
- package/clis/notebooklm/generate-slides.test.js +75 -0
- package/clis/notebooklm/open.test.js +10 -10
- package/clis/notebooklm/rpc.js +20 -6
- package/clis/notebooklm/rpc.test.js +27 -1
- package/clis/notebooklm/utils.js +100 -24
- package/clis/notebooklm/utils.test.js +60 -1
- package/clis/notebooklm/write-note.js +103 -0
- package/clis/notebooklm/write-note.test.js +70 -0
- package/clis/pixiv/detail.js +41 -34
- package/clis/pixiv/detail.test.js +93 -0
- package/clis/pixiv/user.js +36 -31
- package/clis/pixiv/user.test.js +100 -0
- package/clis/pixiv/utils.js +56 -7
- package/clis/powerchina/search.js +3 -3
- package/clis/powerchina/search.test.js +27 -1
- package/clis/reddit/extract-media.test.js +149 -0
- package/clis/reddit/frontpage.js +47 -9
- package/clis/reddit/frontpage.test.js +34 -0
- package/clis/reddit/home.js +31 -1
- package/clis/reddit/home.test.js +46 -3
- package/clis/reddit/hot.js +32 -1
- package/clis/reddit/hot.test.js +15 -1
- package/clis/reddit/popular.js +39 -1
- package/clis/reddit/popular.test.js +26 -0
- package/clis/reddit/saved.js +1 -1
- package/clis/reddit/search.js +38 -1
- package/clis/reddit/search.test.js +26 -0
- package/clis/reddit/subreddit.js +52 -7
- package/clis/reddit/subreddit.test.js +31 -0
- package/clis/reddit/subscribed.js +165 -0
- package/clis/reddit/subscribed.test.js +168 -0
- package/clis/reddit/upvoted.js +1 -1
- package/clis/suno/commands.test.js +188 -0
- package/clis/suno/download.js +140 -0
- package/clis/suno/download.test.js +151 -0
- package/clis/suno/generate.js +231 -0
- package/clis/suno/generate.test.js +252 -0
- package/clis/suno/list.js +79 -0
- package/clis/suno/status.js +63 -0
- package/clis/suno/utils.js +549 -0
- package/clis/suno/utils.test.js +329 -0
- package/clis/twitter/device-follow.js +193 -0
- package/clis/twitter/device-follow.test.js +287 -0
- package/clis/twitter/download.js +443 -73
- package/clis/twitter/download.test.js +457 -0
- package/clis/twitter/followers.js +6 -2
- package/clis/twitter/followers.test.js +19 -1
- package/clis/twitter/following.js +14 -5
- package/clis/twitter/following.test.js +29 -0
- package/clis/twitter/likes.js +12 -4
- package/clis/twitter/likes.test.js +26 -1
- package/clis/twitter/list-add.js +1 -1
- package/clis/twitter/list-create.js +155 -0
- package/clis/twitter/list-create.test.js +169 -0
- package/clis/twitter/list-remove.js +13 -6
- package/clis/twitter/list-remove.test.js +74 -0
- package/clis/twitter/list-tweets.js +6 -2
- package/clis/twitter/list-tweets.test.js +41 -1
- package/clis/twitter/lists.js +31 -4
- package/clis/twitter/lists.test.js +152 -16
- package/clis/twitter/notifications.js +4 -4
- package/clis/twitter/post.js +62 -4
- package/clis/twitter/post.test.js +35 -3
- package/clis/twitter/profile.js +81 -28
- package/clis/twitter/profile.test.js +113 -2
- package/clis/twitter/quote.js +9 -4
- package/clis/twitter/reply.js +13 -10
- package/clis/twitter/reply.test.js +41 -0
- package/clis/twitter/search.js +7 -3
- package/clis/twitter/search.test.js +41 -0
- package/clis/twitter/shared.js +155 -0
- package/clis/twitter/shared.test.js +465 -1
- package/clis/twitter/thread.js +10 -2
- package/clis/twitter/thread.test.js +58 -0
- package/clis/twitter/timeline.js +6 -2
- package/clis/twitter/timeline.test.js +2 -0
- package/clis/twitter/tweets.js +3 -2
- package/clis/twitter/tweets.test.js +1 -1
- package/clis/twitter/utils.js +53 -16
- package/clis/upwork/detail.js +132 -0
- package/clis/upwork/feed.js +109 -0
- package/clis/upwork/search.js +115 -0
- package/clis/upwork/upwork.test.js +566 -0
- package/clis/upwork/utils.js +323 -0
- package/clis/weibo/delete.js +172 -0
- package/clis/weibo/delete.test.js +94 -0
- package/clis/weibo/publish.js +37 -14
- package/clis/weibo/publish.test.js +14 -5
- package/clis/weibo/user-posts.js +234 -0
- package/clis/weibo/user-posts.test.js +92 -0
- package/clis/weread/book-search.js +438 -0
- package/clis/weread/book-search.test.js +242 -0
- package/clis/weread/search-regression.test.js +98 -11
- package/clis/weread/search.js +32 -9
- package/clis/weread-official/book.js +135 -0
- package/clis/weread-official/commands.test.js +385 -0
- package/clis/weread-official/discover.js +107 -0
- package/clis/weread-official/list-apis.js +95 -0
- package/clis/weread-official/notes.js +171 -0
- package/clis/weread-official/readdata.js +158 -0
- package/clis/weread-official/review.js +93 -0
- package/clis/weread-official/search.js +106 -0
- package/clis/weread-official/shelf.js +97 -0
- package/clis/weread-official/utils.js +293 -0
- package/clis/weread-official/utils.test.js +242 -0
- package/clis/wikipedia/trending.js +7 -3
- package/clis/wikipedia/trending.test.js +57 -0
- package/clis/xianyu/chat.js +24 -109
- package/clis/xianyu/chat.test.js +5 -0
- package/clis/xianyu/im.js +322 -0
- package/clis/xianyu/im.test.js +253 -0
- package/clis/xianyu/inbox.js +96 -0
- package/clis/xianyu/messages.js +91 -0
- package/clis/xianyu/reply.js +82 -0
- package/clis/xiaohongshu/creator-note-detail.js +166 -28
- package/clis/xiaohongshu/creator-note-detail.test.js +196 -36
- package/clis/xiaohongshu/creator-notes-summary.js +2 -1
- package/clis/xiaohongshu/creator-notes-summary.test.js +7 -0
- package/clis/xiaohongshu/creator-notes.js +252 -2
- package/clis/xiaohongshu/creator-notes.test.js +90 -1
- package/clis/xiaohongshu/creator-stats.js +2 -1
- package/clis/xiaohongshu/creator-stats.test.js +24 -0
- package/clis/xiaohongshu/delete-note.js +260 -0
- package/clis/xiaohongshu/delete-note.test.js +172 -0
- package/clis/xiaohongshu/download.js +97 -39
- package/clis/xiaohongshu/download.test.js +201 -0
- package/clis/xiaohongshu/publish.js +48 -8
- package/clis/xiaohongshu/publish.test.js +65 -10
- package/clis/xiaohongshu/user-helpers.test.js +41 -0
- package/clis/xiaohongshu/user.js +27 -4
- package/clis/xiaoyuzhou/download.js +1 -1
- package/clis/xiaoyuzhou/transcript.js +1 -1
- package/clis/youdao/note.js +258 -0
- package/clis/youdao/note.test.js +99 -0
- package/clis/youtube/transcript.js +397 -24
- package/clis/youtube/transcript.test.js +196 -6
- package/clis/zhihu/answer-comments.js +280 -0
- package/clis/zhihu/answer-comments.test.js +287 -0
- package/clis/zhihu/answer-detail.js +2 -19
- package/clis/zhihu/answer-detail.test.js +8 -0
- package/clis/zhihu/collection.js +17 -16
- package/clis/zhihu/collection.test.js +50 -3
- package/clis/zhihu/download.js +1 -1
- package/clis/zhihu/question.js +42 -17
- package/clis/zhihu/question.test.js +113 -11
- package/clis/zhihu/search.js +195 -43
- package/clis/zhihu/search.test.js +198 -0
- package/clis/zhihu/text.js +29 -0
- package/clis/zhihu/text.test.js +24 -0
- package/dist/src/browser/errors.js +4 -2
- package/dist/src/browser/errors.test.js +6 -0
- package/dist/src/browser/network-cache.js +13 -1
- package/dist/src/browser/network-cache.test.js +17 -0
- package/dist/src/browser/page.js +30 -4
- package/dist/src/browser/page.test.js +42 -0
- package/dist/src/browser/utils.d.ts +1 -1
- package/dist/src/cli-argv-preprocess.d.ts +26 -0
- package/dist/src/cli-argv-preprocess.js +138 -0
- package/dist/src/cli-argv-preprocess.test.js +79 -0
- package/dist/src/convention-audit.js +15 -8
- package/dist/src/convention-audit.test.js +21 -0
- package/dist/src/download/index.js +13 -1
- package/dist/src/download/index.test.js +23 -1
- package/dist/src/download/media-download.js +15 -2
- package/dist/src/download/media-download.test.d.ts +1 -0
- package/dist/src/download/media-download.test.js +112 -0
- package/dist/src/download/progress.js +2 -2
- package/dist/src/download/progress.test.js +12 -1
- package/dist/src/electron-apps.js +1 -1
- package/dist/src/electron-apps.test.js +7 -2
- package/dist/src/errors.d.ts +17 -0
- package/dist/src/errors.js +22 -0
- package/dist/src/external-clis.yaml +8 -0
- package/dist/src/main.js +14 -2
- package/dist/src/output.js +11 -1
- package/dist/src/output.test.js +6 -0
- package/dist/src/registry.js +1 -0
- package/dist/src/registry.test.js +11 -0
- package/dist/src/utils.d.ts +43 -0
- package/dist/src/utils.js +97 -0
- package/dist/src/utils.test.d.ts +1 -0
- package/dist/src/utils.test.js +155 -0
- package/package.json +8 -2
- package/scripts/silent-column-drop-baseline.json +0 -52
- package/scripts/typed-error-lint-baseline.json +28 -380
- package/clis/slock/_utils.js +0 -12
|
@@ -0,0 +1,566 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
ArgumentError,
|
|
4
|
+
AuthRequiredError,
|
|
5
|
+
CommandExecutionError,
|
|
6
|
+
EmptyResultError,
|
|
7
|
+
} from '@jackwener/opencli/errors';
|
|
8
|
+
import { getRegistry } from '@jackwener/opencli/registry';
|
|
9
|
+
import {
|
|
10
|
+
UPWORK_ORIGIN,
|
|
11
|
+
LIST_COLUMNS,
|
|
12
|
+
DETAIL_COLUMNS,
|
|
13
|
+
requireQuery,
|
|
14
|
+
requirePositiveInt,
|
|
15
|
+
requireBoundedInt,
|
|
16
|
+
requireCiphertext,
|
|
17
|
+
requireFeedTab,
|
|
18
|
+
requireSort,
|
|
19
|
+
buildSearchUrl,
|
|
20
|
+
buildFeedUrl,
|
|
21
|
+
feedStateKey,
|
|
22
|
+
buildJobUrl,
|
|
23
|
+
stripHighlight,
|
|
24
|
+
decodeExperienceLevel,
|
|
25
|
+
decodeWorkload,
|
|
26
|
+
decodeProposalsTier,
|
|
27
|
+
formatBudget,
|
|
28
|
+
formatBudgetFromDetail,
|
|
29
|
+
jobType,
|
|
30
|
+
formatSkills,
|
|
31
|
+
jobToListRow,
|
|
32
|
+
} from './utils.js';
|
|
33
|
+
import './search.js';
|
|
34
|
+
import './feed.js';
|
|
35
|
+
import './detail.js';
|
|
36
|
+
|
|
37
|
+
function createPageMock(evaluateResult) {
|
|
38
|
+
const evaluate = typeof evaluateResult === 'function'
|
|
39
|
+
? vi.fn(evaluateResult)
|
|
40
|
+
: vi.fn().mockResolvedValue(evaluateResult);
|
|
41
|
+
return {
|
|
42
|
+
goto: vi.fn().mockResolvedValue(undefined),
|
|
43
|
+
wait: vi.fn().mockResolvedValue(undefined),
|
|
44
|
+
evaluate,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
describe('upwork adapter — registration', () => {
|
|
49
|
+
it('registers search/feed/detail with the expected shape', () => {
|
|
50
|
+
const search = getRegistry().get('upwork/search');
|
|
51
|
+
const feed = getRegistry().get('upwork/feed');
|
|
52
|
+
const detail = getRegistry().get('upwork/detail');
|
|
53
|
+
|
|
54
|
+
expect(search).toBeDefined();
|
|
55
|
+
expect(search.browser).toBe(true);
|
|
56
|
+
expect(search.strategy).toBe('cookie');
|
|
57
|
+
expect(search.navigateBefore).toBe(false);
|
|
58
|
+
expect(search.columns).toEqual(LIST_COLUMNS);
|
|
59
|
+
|
|
60
|
+
expect(feed).toBeDefined();
|
|
61
|
+
expect(feed.browser).toBe(true);
|
|
62
|
+
expect(feed.strategy).toBe('cookie');
|
|
63
|
+
expect(feed.columns).toEqual(LIST_COLUMNS);
|
|
64
|
+
expect(feed.aliases).toContain('best-matches');
|
|
65
|
+
|
|
66
|
+
expect(detail).toBeDefined();
|
|
67
|
+
expect(detail.browser).toBe(true);
|
|
68
|
+
expect(detail.strategy).toBe('cookie');
|
|
69
|
+
expect(detail.columns).toEqual(DETAIL_COLUMNS);
|
|
70
|
+
expect(detail.aliases).toContain('job');
|
|
71
|
+
expect(detail.aliases).toContain('view');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('shares list columns between search and feed but not detail', () => {
|
|
75
|
+
expect(LIST_COLUMNS).toContain('rank');
|
|
76
|
+
expect(LIST_COLUMNS).toContain('proposalsTier');
|
|
77
|
+
expect(DETAIL_COLUMNS).toContain('description');
|
|
78
|
+
expect(DETAIL_COLUMNS).not.toContain('rank');
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe('upwork adapter — argument validators', () => {
|
|
83
|
+
it('requireQuery trims and rejects empty', () => {
|
|
84
|
+
expect(requireQuery(' python ')).toBe('python');
|
|
85
|
+
expect(() => requireQuery('')).toThrow(ArgumentError);
|
|
86
|
+
expect(() => requireQuery(' ')).toThrow(ArgumentError);
|
|
87
|
+
expect(() => requireQuery(null)).toThrow(ArgumentError);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('requirePositiveInt rejects zero / negative / floats', () => {
|
|
91
|
+
expect(requirePositiveInt(1, 1, 'page')).toBe(1);
|
|
92
|
+
expect(requirePositiveInt('5', 1, 'page')).toBe(5);
|
|
93
|
+
expect(() => requirePositiveInt(0, 1, 'page')).toThrow(/positive integer/);
|
|
94
|
+
expect(() => requirePositiveInt(-1, 1, 'page')).toThrow(/positive integer/);
|
|
95
|
+
expect(() => requirePositiveInt(1.5, 1, 'page')).toThrow(/positive integer/);
|
|
96
|
+
expect(() => requirePositiveInt('abc', 1, 'page')).toThrow(/positive integer/);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('requireBoundedInt enforces both bounds (no silent clamp)', () => {
|
|
100
|
+
expect(requireBoundedInt(20, 20, 1, 50, 'limit')).toBe(20);
|
|
101
|
+
expect(requireBoundedInt('50', 20, 1, 50, 'limit')).toBe(50);
|
|
102
|
+
expect(() => requireBoundedInt(0, 20, 1, 50, 'limit')).toThrow(/positive integer/);
|
|
103
|
+
expect(() => requireBoundedInt(100, 20, 1, 50, 'limit')).toThrow(/<= 50/);
|
|
104
|
+
expect(() => requireBoundedInt(0, 20, 10, 50, 'per_page')).toThrow(/positive integer/);
|
|
105
|
+
expect(() => requireBoundedInt(5, 20, 10, 50, 'per_page')).toThrow(/>= 10/);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('requireCiphertext accepts ~01/~02 forms and rejects garbage', () => {
|
|
109
|
+
expect(requireCiphertext('~022054964136512093518')).toBe('~022054964136512093518');
|
|
110
|
+
expect(requireCiphertext('~012055605504980235850')).toBe('~012055605504980235850');
|
|
111
|
+
expect(requireCiphertext('https://www.upwork.com/jobs/~022054964136512093518')).toBe('~022054964136512093518');
|
|
112
|
+
expect(requireCiphertext(' ~022054964136512093518 ')).toBe('~022054964136512093518');
|
|
113
|
+
expect(() => requireCiphertext('')).toThrow(ArgumentError);
|
|
114
|
+
expect(() => requireCiphertext('~03abc')).toThrow(/valid ciphertext/);
|
|
115
|
+
expect(() => requireCiphertext('not-a-job-id')).toThrow(ArgumentError);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('requireFeedTab validates the small enum', () => {
|
|
119
|
+
expect(requireFeedTab('best-matches')).toBe('best-matches');
|
|
120
|
+
expect(requireFeedTab('MOST-RECENT')).toBe('most-recent');
|
|
121
|
+
expect(requireFeedTab(undefined)).toBe('best-matches');
|
|
122
|
+
expect(() => requireFeedTab('saved')).toThrow(/best-matches/);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('requireSort validates the small enum', () => {
|
|
126
|
+
expect(requireSort('recency')).toBe('recency');
|
|
127
|
+
expect(requireSort('RELEVANCE')).toBe('relevance');
|
|
128
|
+
expect(requireSort(undefined)).toBe('recency');
|
|
129
|
+
expect(() => requireSort('best')).toThrow(/recency/);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
describe('upwork adapter — URL builders', () => {
|
|
134
|
+
it('buildSearchUrl emits a canonical, round-trippable URL', () => {
|
|
135
|
+
expect(buildSearchUrl({ query: 'python', sort: 'recency', page: 1, perPage: 10 }))
|
|
136
|
+
.toBe(`${UPWORK_ORIGIN}/nx/search/jobs/?q=python`);
|
|
137
|
+
expect(buildSearchUrl({ query: 'python developer', location: 'United States', sort: 'relevance', page: 2, perPage: 25 }))
|
|
138
|
+
.toBe(`${UPWORK_ORIGIN}/nx/search/jobs/?q=python+developer&location=United+States&sort=relevance&per_page=25&page=2`);
|
|
139
|
+
expect(buildSearchUrl({ query: 'react', category: 'web-development', sort: 'recency', page: 1, perPage: 10 }))
|
|
140
|
+
.toBe(`${UPWORK_ORIGIN}/nx/search/jobs/?q=react&category2_uid=web-development`);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('buildFeedUrl returns the right path per tab', () => {
|
|
144
|
+
expect(buildFeedUrl('best-matches')).toBe(`${UPWORK_ORIGIN}/nx/find-work/best-matches`);
|
|
145
|
+
expect(buildFeedUrl('most-recent')).toBe(`${UPWORK_ORIGIN}/nx/find-work/most-recent`);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it('feedStateKey maps tab → Nuxt state slot', () => {
|
|
149
|
+
expect(feedStateKey('best-matches')).toBe('feedBestMatch');
|
|
150
|
+
expect(feedStateKey('most-recent')).toBe('feedMostRecent');
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it('buildJobUrl prepends the origin', () => {
|
|
154
|
+
expect(buildJobUrl('~022054964136512093518')).toBe(`${UPWORK_ORIGIN}/jobs/~022054964136512093518`);
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
describe('upwork adapter — text + field normalizers', () => {
|
|
159
|
+
it('stripHighlight removes Upwork query-highlight markup and collapses whitespace', () => {
|
|
160
|
+
expect(stripHighlight('Software <span class="highlight">Developer</span> (Client-Facing)'))
|
|
161
|
+
.toBe('Software Developer (Client-Facing)');
|
|
162
|
+
expect(stripHighlight(' multi\n\nline ')).toBe('multi line');
|
|
163
|
+
expect(stripHighlight(null)).toBe('');
|
|
164
|
+
expect(stripHighlight(undefined)).toBe('');
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('decodeExperienceLevel handles i18n keys, rendered labels, and numeric tiers', () => {
|
|
168
|
+
expect(decodeExperienceLevel('jsn_Entry_205')).toBe('entry');
|
|
169
|
+
expect(decodeExperienceLevel('jsn_Intermediate_206')).toBe('intermediate');
|
|
170
|
+
expect(decodeExperienceLevel('jsn_Expert_207')).toBe('expert');
|
|
171
|
+
expect(decodeExperienceLevel('Entry level')).toBe('entry');
|
|
172
|
+
expect(decodeExperienceLevel('Intermediate')).toBe('intermediate');
|
|
173
|
+
expect(decodeExperienceLevel('Expert')).toBe('expert');
|
|
174
|
+
expect(decodeExperienceLevel(1)).toBe('entry');
|
|
175
|
+
expect(decodeExperienceLevel(2)).toBe('intermediate');
|
|
176
|
+
expect(decodeExperienceLevel(3)).toBe('expert');
|
|
177
|
+
expect(decodeExperienceLevel(null)).toBe('');
|
|
178
|
+
expect(decodeExperienceLevel('')).toBe('');
|
|
179
|
+
expect(decodeExperienceLevel('Mystery_999')).toBe('');
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it('decodeWorkload extracts engagement suffix and normalizes', () => {
|
|
183
|
+
expect(decodeWorkload('usnuxt_Engagement_421.fullTime')).toBe('full-time');
|
|
184
|
+
expect(decodeWorkload('usnuxt_Engagement_421.partTime')).toBe('part-time');
|
|
185
|
+
expect(decodeWorkload('More than 30 hrs/week')).toBe('More than 30 hrs/week');
|
|
186
|
+
expect(decodeWorkload(null)).toBe('');
|
|
187
|
+
expect(decodeWorkload('')).toBe('');
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it('decodeProposalsTier maps both i18n-keyed and rendered buckets', () => {
|
|
191
|
+
expect(decodeProposalsTier('usnuxt_JobProposalTier_418.lessThan5')).toBe('<5');
|
|
192
|
+
expect(decodeProposalsTier('usnuxt_JobProposalTier_418.5to10')).toBe('5-10');
|
|
193
|
+
expect(decodeProposalsTier('usnuxt_JobProposalTier_418.10to15')).toBe('10-15');
|
|
194
|
+
expect(decodeProposalsTier('usnuxt_JobProposalTier_418.20to50')).toBe('20-50');
|
|
195
|
+
expect(decodeProposalsTier('usnuxt_JobProposalTier_418.50Plus')).toBe('50+');
|
|
196
|
+
expect(decodeProposalsTier('15 to 20')).toBe('15-20');
|
|
197
|
+
expect(decodeProposalsTier('5 to 10')).toBe('5-10');
|
|
198
|
+
expect(decodeProposalsTier(null)).toBe('');
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it('formatBudget handles hourly ranges, single bounds, fixed, and missing', () => {
|
|
202
|
+
expect(formatBudget({ type: 2, hourlyBudget: { min: 40, max: 70 } })).toBe('$40-$70/hr');
|
|
203
|
+
expect(formatBudget({ type: 2, hourlyBudget: { min: 30, max: 30 } })).toBe('$30/hr');
|
|
204
|
+
expect(formatBudget({ type: 2, hourlyBudget: { min: 0, max: 50 } })).toBe('$50/hr');
|
|
205
|
+
expect(formatBudget({ type: 2, hourlyBudget: { min: 25, max: 0 } })).toBe('$25/hr');
|
|
206
|
+
expect(formatBudget({ type: 2, hourlyBudget: { min: 0, max: 0 } })).toBe('');
|
|
207
|
+
expect(formatBudget({ type: 1, amount: { amount: 200 } })).toBe('$200');
|
|
208
|
+
expect(formatBudget({ type: 1, amount: { amount: 0 } })).toBe('');
|
|
209
|
+
expect(formatBudget({ type: null })).toBe('');
|
|
210
|
+
expect(formatBudget(null)).toBe('');
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it('formatBudgetFromDetail reads extendedBudgetInfo and budget.amount', () => {
|
|
214
|
+
expect(formatBudgetFromDetail({ type: 2, extendedBudgetInfo: { hourlyBudgetMin: 40, hourlyBudgetMax: 70 } })).toBe('$40-$70/hr');
|
|
215
|
+
expect(formatBudgetFromDetail({ type: 1, budget: { amount: 500 } })).toBe('$500');
|
|
216
|
+
expect(formatBudgetFromDetail({ type: 2, extendedBudgetInfo: { hourlyBudgetMin: 0, hourlyBudgetMax: 0 } })).toBe('');
|
|
217
|
+
expect(formatBudgetFromDetail({ type: 1, budget: { amount: 0 } })).toBe('');
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it('jobType returns stable labels', () => {
|
|
221
|
+
expect(jobType(1)).toBe('fixed');
|
|
222
|
+
expect(jobType(2)).toBe('hourly');
|
|
223
|
+
expect(jobType(0)).toBe('');
|
|
224
|
+
expect(jobType(null)).toBe('');
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it('formatSkills dedupes across attrs / skills / ontologySkills', () => {
|
|
228
|
+
expect(formatSkills({ attrs: [{ prettyName: 'Python' }, { prettyName: 'JavaScript' }, { prettyName: 'Python' }] }))
|
|
229
|
+
.toBe('Python, JavaScript');
|
|
230
|
+
expect(formatSkills({ skills: [{ prefLabel: 'Android' }, { prefLabel: 'QA Testing' }] }))
|
|
231
|
+
.toBe('Android, QA Testing');
|
|
232
|
+
expect(formatSkills({ ontologySkills: [{ name: 'React' }] })).toBe('React');
|
|
233
|
+
expect(formatSkills({})).toBe('');
|
|
234
|
+
expect(formatSkills(null)).toBe('');
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
describe('upwork adapter — jobToListRow', () => {
|
|
239
|
+
it('produces a row matching LIST_COLUMNS keys and order', () => {
|
|
240
|
+
const job = {
|
|
241
|
+
ciphertext: '~022054964136512093518',
|
|
242
|
+
title: 'Software <span class="highlight">Developer</span>',
|
|
243
|
+
type: 2,
|
|
244
|
+
hourlyBudget: { min: 40, max: 70 },
|
|
245
|
+
tierText: 'jsn_Intermediate_206',
|
|
246
|
+
proposalsTier: 'usnuxt_JobProposalTier_418.50Plus',
|
|
247
|
+
attrs: [{ prettyName: 'Python' }, { prettyName: 'SQL' }],
|
|
248
|
+
client: { location: { country: 'United States' }, totalFeedback: 4.87 },
|
|
249
|
+
publishedOn: '2026-05-14T16:37:43.507Z',
|
|
250
|
+
};
|
|
251
|
+
const row = jobToListRow(job, 3);
|
|
252
|
+
expect(Object.keys(row)).toEqual(LIST_COLUMNS);
|
|
253
|
+
expect(row).toEqual({
|
|
254
|
+
rank: 3,
|
|
255
|
+
id: '~022054964136512093518',
|
|
256
|
+
title: 'Software Developer',
|
|
257
|
+
type: 'hourly',
|
|
258
|
+
budget: '$40-$70/hr',
|
|
259
|
+
experienceLevel: 'intermediate',
|
|
260
|
+
proposalsTier: '50+',
|
|
261
|
+
skills: 'Python, SQL',
|
|
262
|
+
clientCountry: 'United States',
|
|
263
|
+
clientRating: 4.87,
|
|
264
|
+
publishedOn: '2026-05-14T16:37:43.507Z',
|
|
265
|
+
url: 'https://www.upwork.com/jobs/~022054964136512093518',
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it('drops zero / NaN client rating to null, never silently labels 0 as a real score', () => {
|
|
270
|
+
const job = { ciphertext: '~022054964136512093518', client: { totalFeedback: 0 } };
|
|
271
|
+
expect(jobToListRow(job, 1).clientRating).toBeNull();
|
|
272
|
+
const job2 = { ciphertext: '~022054964136512093518', client: { totalFeedback: null } };
|
|
273
|
+
expect(jobToListRow(job2, 1).clientRating).toBeNull();
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
it('falls back to createdOn when publishedOn is missing', () => {
|
|
277
|
+
const job = {
|
|
278
|
+
ciphertext: '~022054964136512093518',
|
|
279
|
+
type: 2,
|
|
280
|
+
hourlyBudget: { min: 0, max: 0 },
|
|
281
|
+
createdOn: '2026-01-01T00:00:00.000Z',
|
|
282
|
+
};
|
|
283
|
+
expect(jobToListRow(job, 1).publishedOn).toBe('2026-01-01T00:00:00.000Z');
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
it('returns null instead of non-round-trippable rows when ciphertext is missing or malformed', () => {
|
|
287
|
+
expect(jobToListRow({ ciphertext: '', title: 'missing id' }, 1)).toBeNull();
|
|
288
|
+
expect(jobToListRow({ ciphertext: '12345', title: 'bad id' }, 1)).toBeNull();
|
|
289
|
+
expect(jobToListRow({ title: 'no id' }, 1)).toBeNull();
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
describe('upwork search — func behavior', () => {
|
|
294
|
+
const cmd = () => getRegistry().get('upwork/search');
|
|
295
|
+
|
|
296
|
+
it('returns rows on a populated state', async () => {
|
|
297
|
+
const page = createPageMock({
|
|
298
|
+
ready: true,
|
|
299
|
+
onLogin: false,
|
|
300
|
+
challenge: false,
|
|
301
|
+
jobsPresent: true,
|
|
302
|
+
jobs: [
|
|
303
|
+
{ ciphertext: '~022054964136512093518', title: 'A', type: 2, hourlyBudget: { min: 10, max: 20 }, attrs: [], client: {} },
|
|
304
|
+
{ ciphertext: '~022055605504980235850', title: 'B', type: 1, amount: { amount: 100 }, attrs: [], client: {} },
|
|
305
|
+
],
|
|
306
|
+
paging: { total: 2, offset: 0, count: 2 },
|
|
307
|
+
});
|
|
308
|
+
const rows = await cmd().func(page, { query: 'python', page: 1, per_page: 10 });
|
|
309
|
+
expect(rows).toHaveLength(2);
|
|
310
|
+
expect(rows[0].rank).toBe(1);
|
|
311
|
+
expect(rows[0].type).toBe('hourly');
|
|
312
|
+
expect(rows[1].rank).toBe(2);
|
|
313
|
+
expect(rows[1].type).toBe('fixed');
|
|
314
|
+
expect(page.goto).toHaveBeenCalledWith(expect.stringContaining('/nx/search/jobs/?q=python'));
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
it('uses pageNum/perPage to compute the starting rank', async () => {
|
|
318
|
+
const page = createPageMock({
|
|
319
|
+
ready: true, onLogin: false, challenge: false,
|
|
320
|
+
jobsPresent: true,
|
|
321
|
+
jobs: [{ ciphertext: '~022054964136512093518', title: 'A', type: 2, attrs: [], client: {} }],
|
|
322
|
+
});
|
|
323
|
+
const rows = await cmd().func(page, { query: 'python', page: 3, per_page: 10 });
|
|
324
|
+
expect(rows[0].rank).toBe(21);
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
it('throws AuthRequiredError when redirected to login', async () => {
|
|
328
|
+
const page = createPageMock({ ready: false, onLogin: true, challenge: false, jobs: [] });
|
|
329
|
+
await expect(cmd().func(page, { query: 'python' })).rejects.toBeInstanceOf(AuthRequiredError);
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
it('throws CommandExecutionError on Cloudflare challenge', async () => {
|
|
333
|
+
const page = createPageMock({ ready: false, onLogin: false, challenge: true, jobs: [] });
|
|
334
|
+
await expect(cmd().func(page, { query: 'python' })).rejects.toBeInstanceOf(CommandExecutionError);
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
it('throws CommandExecutionError when state never hydrates', async () => {
|
|
338
|
+
const page = createPageMock({ ready: false, onLogin: false, challenge: false, jobs: [] });
|
|
339
|
+
await expect(cmd().func(page, { query: 'python' })).rejects.toThrow(/was not present/);
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
it('throws EmptyResultError when the search returns zero jobs', async () => {
|
|
343
|
+
const page = createPageMock({ ready: true, onLogin: false, challenge: false, jobsPresent: true, jobs: [], paging: { total: 0 } });
|
|
344
|
+
await expect(cmd().func(page, { query: 'asdfqwerzxcv' })).rejects.toBeInstanceOf(EmptyResultError);
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
it('unwraps Browser Bridge envelopes at the evaluate boundary', async () => {
|
|
348
|
+
const page = createPageMock({
|
|
349
|
+
session: 'site:upwork',
|
|
350
|
+
data: {
|
|
351
|
+
ready: true,
|
|
352
|
+
onLogin: false,
|
|
353
|
+
challenge: false,
|
|
354
|
+
jobsPresent: true,
|
|
355
|
+
jobs: [{ ciphertext: '~022054964136512093518', title: 'A', type: 2, attrs: [], client: {} }],
|
|
356
|
+
},
|
|
357
|
+
});
|
|
358
|
+
const rows = await cmd().func(page, { query: 'python' });
|
|
359
|
+
expect(rows).toHaveLength(1);
|
|
360
|
+
expect(rows[0].id).toBe('~022054964136512093518');
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
it('treats missing or malformed jobs state as parser drift, not legal empty', async () => {
|
|
364
|
+
await expect(cmd().func(createPageMock({ ready: true, onLogin: false, challenge: false }), { query: 'python' }))
|
|
365
|
+
.rejects.toBeInstanceOf(CommandExecutionError);
|
|
366
|
+
await expect(cmd().func(createPageMock({ ready: true, onLogin: false, challenge: false, jobsPresent: true, jobs: {} }), { query: 'python' }))
|
|
367
|
+
.rejects.toBeInstanceOf(CommandExecutionError);
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
it('fails closed when any search result lacks a round-trippable job id', async () => {
|
|
371
|
+
const page = createPageMock({
|
|
372
|
+
ready: true,
|
|
373
|
+
onLogin: false,
|
|
374
|
+
challenge: false,
|
|
375
|
+
jobsPresent: true,
|
|
376
|
+
jobs: [{ ciphertext: '~022054964136512093518', title: 'A' }, { ciphertext: '12345', title: 'B' }],
|
|
377
|
+
});
|
|
378
|
+
await expect(cmd().func(page, { query: 'python' })).rejects.toBeInstanceOf(CommandExecutionError);
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
it('rejects empty query before opening the page', async () => {
|
|
382
|
+
const page = createPageMock({ ready: true, jobs: [] });
|
|
383
|
+
await expect(cmd().func(page, { query: '' })).rejects.toBeInstanceOf(ArgumentError);
|
|
384
|
+
expect(page.goto).not.toHaveBeenCalled();
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
describe('upwork feed — func behavior', () => {
|
|
389
|
+
const cmd = () => getRegistry().get('upwork/feed');
|
|
390
|
+
|
|
391
|
+
it('hits the best-matches URL by default', async () => {
|
|
392
|
+
const page = createPageMock({
|
|
393
|
+
ready: true, onLogin: false, challenge: false,
|
|
394
|
+
jobsPresent: true,
|
|
395
|
+
jobs: [{ ciphertext: '~022054964136512093518', title: 'A', type: 2, attrs: [], client: {} }],
|
|
396
|
+
});
|
|
397
|
+
const rows = await cmd().func(page, { tab: 'best-matches', limit: 5 });
|
|
398
|
+
expect(rows).toHaveLength(1);
|
|
399
|
+
expect(page.goto).toHaveBeenCalledWith('https://www.upwork.com/nx/find-work/best-matches');
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
it('switches URL for the most-recent tab', async () => {
|
|
403
|
+
const page = createPageMock({
|
|
404
|
+
ready: true, onLogin: false, challenge: false,
|
|
405
|
+
jobsPresent: true,
|
|
406
|
+
jobs: [{ ciphertext: '~022054964136512093518', title: 'A', type: 1, amount: { amount: 50 }, attrs: [], client: {} }],
|
|
407
|
+
});
|
|
408
|
+
await cmd().func(page, { tab: 'most-recent', limit: 5 });
|
|
409
|
+
expect(page.goto).toHaveBeenCalledWith('https://www.upwork.com/nx/find-work/most-recent');
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
it('throws AuthRequiredError when redirected to login', async () => {
|
|
413
|
+
const page = createPageMock({ ready: false, onLogin: true, challenge: false, jobs: [] });
|
|
414
|
+
await expect(cmd().func(page, { tab: 'best-matches' })).rejects.toBeInstanceOf(AuthRequiredError);
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
it('throws EmptyResultError for an empty feed without sentinel rows', async () => {
|
|
418
|
+
const page = createPageMock({ ready: true, onLogin: false, challenge: false, jobsPresent: true, jobs: [] });
|
|
419
|
+
await expect(cmd().func(page, { tab: 'best-matches' })).rejects.toBeInstanceOf(EmptyResultError);
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
it('unwraps Browser Bridge envelopes and rejects malformed feed jobs state', async () => {
|
|
423
|
+
const rows = await cmd().func(createPageMock({
|
|
424
|
+
session: 'site:upwork',
|
|
425
|
+
data: {
|
|
426
|
+
ready: true,
|
|
427
|
+
onLogin: false,
|
|
428
|
+
challenge: false,
|
|
429
|
+
jobsPresent: true,
|
|
430
|
+
jobs: [{ ciphertext: '~022054964136512093518', title: 'A', type: 2, attrs: [], client: {} }],
|
|
431
|
+
},
|
|
432
|
+
}), { tab: 'best-matches' });
|
|
433
|
+
expect(rows[0].id).toBe('~022054964136512093518');
|
|
434
|
+
|
|
435
|
+
await expect(cmd().func(createPageMock({ ready: true, onLogin: false, challenge: false, jobsPresent: true, jobs: null }), { tab: 'best-matches' }))
|
|
436
|
+
.rejects.toBeInstanceOf(CommandExecutionError);
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
it('fails closed when any feed result lacks a round-trippable job id', async () => {
|
|
440
|
+
const page = createPageMock({
|
|
441
|
+
ready: true,
|
|
442
|
+
onLogin: false,
|
|
443
|
+
challenge: false,
|
|
444
|
+
jobsPresent: true,
|
|
445
|
+
jobs: [{ ciphertext: '~022054964136512093518', title: 'A' }, { ciphertext: '', title: 'B' }],
|
|
446
|
+
});
|
|
447
|
+
await expect(cmd().func(page, { tab: 'best-matches' })).rejects.toBeInstanceOf(CommandExecutionError);
|
|
448
|
+
});
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
describe('upwork detail — func behavior', () => {
|
|
452
|
+
const cmd = () => getRegistry().get('upwork/detail');
|
|
453
|
+
|
|
454
|
+
it('returns one row from a populated jobDetails store', async () => {
|
|
455
|
+
const page = createPageMock({
|
|
456
|
+
ready: true, onLogin: false, challenge: false,
|
|
457
|
+
job: {
|
|
458
|
+
uid: '2054964136512093518',
|
|
459
|
+
ciphertext: '~022054964136512093518',
|
|
460
|
+
title: 'Software Developer',
|
|
461
|
+
type: 2,
|
|
462
|
+
extendedBudgetInfo: { hourlyBudgetMin: 40, hourlyBudgetMax: 70 },
|
|
463
|
+
contractorTier: 2,
|
|
464
|
+
workload: 'More than 30 hrs/week',
|
|
465
|
+
category: { name: 'Web Development', urlSlug: 'web-development' },
|
|
466
|
+
attrs: [{ prettyName: 'Python' }],
|
|
467
|
+
description: 'We are looking for...',
|
|
468
|
+
publishTime: '2026-05-14T16:37:43.507Z',
|
|
469
|
+
clientActivity: { totalApplicants: 50, totalHired: 0 },
|
|
470
|
+
},
|
|
471
|
+
buyer: {
|
|
472
|
+
stats: { score: 4.8, totalJobsWithHires: 5, totalCharges: { amount: 188.28 } },
|
|
473
|
+
location: { country: 'United States' },
|
|
474
|
+
},
|
|
475
|
+
});
|
|
476
|
+
const rows = await cmd().func(page, { id: '~022054964136512093518' });
|
|
477
|
+
expect(rows).toHaveLength(1);
|
|
478
|
+
const row = rows[0];
|
|
479
|
+
expect(Object.keys(row)).toEqual(DETAIL_COLUMNS);
|
|
480
|
+
expect(row.id).toBe('~022054964136512093518');
|
|
481
|
+
expect(row.type).toBe('hourly');
|
|
482
|
+
expect(row.budget).toBe('$40-$70/hr');
|
|
483
|
+
expect(row.experienceLevel).toBe('intermediate');
|
|
484
|
+
expect(row.workload).toBe('More than 30 hrs/week');
|
|
485
|
+
expect(row.category).toBe('Web Development');
|
|
486
|
+
expect(row.skills).toBe('Python');
|
|
487
|
+
expect(row.clientCountry).toBe('United States');
|
|
488
|
+
expect(row.clientSpent).toBe(188.28);
|
|
489
|
+
expect(row.clientHires).toBe(5);
|
|
490
|
+
expect(row.clientRating).toBe(4.8);
|
|
491
|
+
expect(row.proposalsCount).toBe(50);
|
|
492
|
+
expect(row.url).toBe('https://www.upwork.com/jobs/~022054964136512093518');
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
it('accepts a full /jobs/ URL as the positional id', async () => {
|
|
496
|
+
const page = createPageMock({
|
|
497
|
+
ready: true, onLogin: false, challenge: false,
|
|
498
|
+
job: { ciphertext: '~022054964136512093518', title: 'X', type: 1, budget: { amount: 100 } },
|
|
499
|
+
buyer: {},
|
|
500
|
+
});
|
|
501
|
+
const rows = await cmd().func(page, { id: 'https://www.upwork.com/jobs/~022054964136512093518' });
|
|
502
|
+
expect(rows[0].id).toBe('~022054964136512093518');
|
|
503
|
+
expect(rows[0].budget).toBe('$100');
|
|
504
|
+
});
|
|
505
|
+
|
|
506
|
+
it('drops zero client score to null', async () => {
|
|
507
|
+
const page = createPageMock({
|
|
508
|
+
ready: true, onLogin: false, challenge: false,
|
|
509
|
+
job: { ciphertext: '~022054964136512093518', title: 'X', type: 2 },
|
|
510
|
+
buyer: { stats: { score: 0, totalJobsWithHires: 0 } },
|
|
511
|
+
});
|
|
512
|
+
const rows = await cmd().func(page, { id: '~022054964136512093518' });
|
|
513
|
+
expect(rows[0].clientRating).toBeNull();
|
|
514
|
+
expect(rows[0].clientHires).toBe(0);
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
it('throws AuthRequiredError when redirected to login', async () => {
|
|
518
|
+
const page = createPageMock({ ready: false, onLogin: true, challenge: false, job: null });
|
|
519
|
+
await expect(cmd().func(page, { id: '~022054964136512093518' })).rejects.toBeInstanceOf(AuthRequiredError);
|
|
520
|
+
});
|
|
521
|
+
|
|
522
|
+
it('throws CommandExecutionError on Cloudflare challenge', async () => {
|
|
523
|
+
const page = createPageMock({ ready: false, onLogin: false, challenge: true, job: null });
|
|
524
|
+
await expect(cmd().func(page, { id: '~022054964136512093518' })).rejects.toBeInstanceOf(CommandExecutionError);
|
|
525
|
+
});
|
|
526
|
+
|
|
527
|
+
it('throws EmptyResultError when the store has no job', async () => {
|
|
528
|
+
const page = createPageMock({ ready: false, onLogin: false, challenge: false, job: null });
|
|
529
|
+
await expect(cmd().func(page, { id: '~022054964136512093518' })).rejects.toBeInstanceOf(EmptyResultError);
|
|
530
|
+
});
|
|
531
|
+
|
|
532
|
+
it('unwraps Browser Bridge envelopes and treats wrong-shape job as parser drift', async () => {
|
|
533
|
+
const rows = await cmd().func(createPageMock({
|
|
534
|
+
session: 'site:upwork',
|
|
535
|
+
data: {
|
|
536
|
+
ready: true,
|
|
537
|
+
onLogin: false,
|
|
538
|
+
challenge: false,
|
|
539
|
+
job: { ciphertext: '~022054964136512093518', title: 'X', type: 1, budget: { amount: 100 } },
|
|
540
|
+
buyer: {},
|
|
541
|
+
},
|
|
542
|
+
}), { id: '~022054964136512093518' });
|
|
543
|
+
expect(rows[0].id).toBe('~022054964136512093518');
|
|
544
|
+
|
|
545
|
+
await expect(cmd().func(createPageMock({ ready: true, onLogin: false, challenge: false, job: [] }), { id: '~022054964136512093518' }))
|
|
546
|
+
.rejects.toBeInstanceOf(CommandExecutionError);
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
it('fails closed when the detail store belongs to a different ciphertext', async () => {
|
|
550
|
+
const page = createPageMock({
|
|
551
|
+
ready: true,
|
|
552
|
+
onLogin: false,
|
|
553
|
+
challenge: false,
|
|
554
|
+
job: { ciphertext: '~022055605504980235850', title: 'Wrong job' },
|
|
555
|
+
buyer: {},
|
|
556
|
+
});
|
|
557
|
+
await expect(cmd().func(page, { id: '~022054964136512093518' }))
|
|
558
|
+
.rejects.toBeInstanceOf(CommandExecutionError);
|
|
559
|
+
});
|
|
560
|
+
|
|
561
|
+
it('rejects malformed ciphertext before opening the page', async () => {
|
|
562
|
+
const page = createPageMock({ ready: true, job: null });
|
|
563
|
+
await expect(cmd().func(page, { id: 'not-an-id' })).rejects.toBeInstanceOf(ArgumentError);
|
|
564
|
+
expect(page.goto).not.toHaveBeenCalled();
|
|
565
|
+
});
|
|
566
|
+
});
|