@chainlesschain/personal-data-hub 0.4.29 → 0.4.31
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/lib/forensics/qq-nt-collect.js +190 -0
- package/lib/prompt-builder.js +15 -1
- package/package.json +8 -3
- package/__tests__/adapter-guide.test.js +0 -47
- package/__tests__/adapter-spec.test.js +0 -78
- package/__tests__/adapters/ai-chat-cookie-capture-spec.test.js +0 -211
- package/__tests__/adapters/ai-chat-health-checker.test.js +0 -262
- package/__tests__/adapters/ai-chat-history.test.js +0 -396
- package/__tests__/adapters/ai-chat-http-client.test.js +0 -242
- package/__tests__/adapters/ai-chat-vendors.test.js +0 -874
- package/__tests__/adapters/alipay-bill-adapter.test.js +0 -538
- package/__tests__/adapters/apple-health.test.js +0 -95
- package/__tests__/adapters/bank-family.test.js +0 -125
- package/__tests__/adapters/biz-tianyancha.test.js +0 -159
- package/__tests__/adapters/browser-history-chrome.test.js +0 -377
- package/__tests__/adapters/browser-history-edge.test.js +0 -159
- package/__tests__/adapters/car-mercedesme.test.js +0 -74
- package/__tests__/adapters/doc-baidu-netdisk.test.js +0 -102
- package/__tests__/adapters/doc-camscanner.test.js +0 -147
- package/__tests__/adapters/doc-platforms.test.js +0 -177
- package/__tests__/adapters/edu-huawei-learning-live.test.js +0 -198
- package/__tests__/adapters/edu-zuoyebang-live.test.js +0 -226
- package/__tests__/adapters/email-adapter-snapshot.test.js +0 -237
- package/__tests__/adapters/email-adapter.test.js +0 -742
- package/__tests__/adapters/email-classifier.test.js +0 -347
- package/__tests__/adapters/email-imap-session.test.js +0 -334
- package/__tests__/adapters/email-parser.test.js +0 -244
- package/__tests__/adapters/email-pdf-extractor.test.js +0 -529
- package/__tests__/adapters/email-providers.test.js +0 -84
- package/__tests__/adapters/email-retry-progress.test.js +0 -294
- package/__tests__/adapters/email-templates.test.js +0 -822
- package/__tests__/adapters/family-23-collectors-scaffold.test.js +0 -182
- package/__tests__/adapters/finance-alipay-live.test.js +0 -258
- package/__tests__/adapters/finance-dcep.test.js +0 -74
- package/__tests__/adapters/fitness-joyrun.test.js +0 -82
- package/__tests__/adapters/game-genshin-live.test.js +0 -238
- package/__tests__/adapters/game-genshin-scaffold.test.js +0 -108
- package/__tests__/adapters/game-honor-of-kings-live.test.js +0 -230
- package/__tests__/adapters/git-activity.test.js +0 -222
- package/__tests__/adapters/gov-12123.test.js +0 -103
- package/__tests__/adapters/gov-ixiamen.test.js +0 -150
- package/__tests__/adapters/gov-tax.test.js +0 -135
- package/__tests__/adapters/health-meiyou.test.js +0 -125
- package/__tests__/adapters/local-files.test.js +0 -264
- package/__tests__/adapters/local-im-pc.test.js +0 -154
- package/__tests__/adapters/messaging-whatsapp.test.js +0 -289
- package/__tests__/adapters/music-kugou.test.js +0 -187
- package/__tests__/adapters/music-qq.test.js +0 -112
- package/__tests__/adapters/netease-music-live.test.js +0 -244
- package/__tests__/adapters/netease-music.test.js +0 -74
- package/__tests__/adapters/pc-local-discovery.test.js +0 -141
- package/__tests__/adapters/qq-pc-direct-read.test.js +0 -227
- package/__tests__/adapters/reading-family.test.js +0 -108
- package/__tests__/adapters/recruit-boss.test.js +0 -180
- package/__tests__/adapters/shell-history.test.js +0 -180
- package/__tests__/adapters/shopping-base.test.js +0 -179
- package/__tests__/adapters/shopping-dianping.test.js +0 -239
- package/__tests__/adapters/social-bilibili-adb-api-client.test.js +0 -721
- package/__tests__/adapters/social-bilibili-adb-chromium-cookies-reader.test.js +0 -346
- package/__tests__/adapters/social-bilibili-adb-collector.test.js +0 -284
- package/__tests__/adapters/social-bilibili-adb-cookies-extension.test.js +0 -343
- package/__tests__/adapters/social-bilibili-adb-snapshot-builder.test.js +0 -296
- package/__tests__/adapters/social-csdn.test.js +0 -175
- package/__tests__/adapters/social-dongchedi.test.js +0 -165
- package/__tests__/adapters/social-douyin-adb-aweme-detail.test.js +0 -165
- package/__tests__/adapters/social-douyin-adb-collector.test.js +0 -254
- package/__tests__/adapters/social-douyin-adb-db-extension.test.js +0 -114
- package/__tests__/adapters/social-douyin-adb-im-db-parser.test.js +0 -304
- package/__tests__/adapters/social-douyin-adb-snapshot-builder.test.js +0 -216
- package/__tests__/adapters/social-douyin-adb-usage-profile.test.js +0 -229
- package/__tests__/adapters/social-douyin-adb-watch-history.test.js +0 -269
- package/__tests__/adapters/social-kuaishou-adb-api-client.test.js +0 -496
- package/__tests__/adapters/social-kuaishou-adb-collector.test.js +0 -276
- package/__tests__/adapters/social-kuaishou-adb-cookies-extension.test.js +0 -152
- package/__tests__/adapters/social-kuaishou-adb-snapshot-builder.test.js +0 -178
- package/__tests__/adapters/social-toutiao-adb-account-reader.test.js +0 -135
- package/__tests__/adapters/social-toutiao-adb-api-client.test.js +0 -626
- package/__tests__/adapters/social-toutiao-adb-article.test.js +0 -155
- package/__tests__/adapters/social-toutiao-adb-collector.test.js +0 -378
- package/__tests__/adapters/social-toutiao-adb-cookies-extension.test.js +0 -193
- package/__tests__/adapters/social-toutiao-adb-snapshot-builder.test.js +0 -196
- package/__tests__/adapters/social-toutiao-kuaishou-scaffold.test.js +0 -311
- package/__tests__/adapters/social-weibo-adb-api-client.test.js +0 -362
- package/__tests__/adapters/social-weibo-adb-collector.test.js +0 -201
- package/__tests__/adapters/social-weibo-adb-cookies-extension.test.js +0 -167
- package/__tests__/adapters/social-weibo-adb-snapshot-builder.test.js +0 -189
- package/__tests__/adapters/social-xiaohongshu-adb-api-client.test.js +0 -431
- package/__tests__/adapters/social-xiaohongshu-adb-collector.test.js +0 -207
- package/__tests__/adapters/social-xiaohongshu-adb-cookies-extension.test.js +0 -0
- package/__tests__/adapters/social-xiaohongshu-adb-sign-provider-injection.test.js +0 -351
- package/__tests__/adapters/social-xiaohongshu-adb-sign.test.js +0 -130
- package/__tests__/adapters/social-xiaohongshu-adb-snapshot-builder.test.js +0 -200
- package/__tests__/adapters/social-zhihu.test.js +0 -246
- package/__tests__/adapters/system-data-adapter.test.js +0 -443
- package/__tests__/adapters/system-data-android-ingest.test.js +0 -144
- package/__tests__/adapters/system-data-android.test.js +0 -519
- package/__tests__/adapters/system-data-disclosure.test.js +0 -153
- package/__tests__/adapters/travel-12306.test.js +0 -512
- package/__tests__/adapters/travel-amap.test.js +0 -219
- package/__tests__/adapters/travel-baidu-map.test.js +0 -305
- package/__tests__/adapters/travel-base.test.js +0 -205
- package/__tests__/adapters/travel-ctrip.test.js +0 -377
- package/__tests__/adapters/travel-didi-consumer.test.js +0 -66
- package/__tests__/adapters/travel-didi.test.js +0 -204
- package/__tests__/adapters/travel-tencent-map.test.js +0 -207
- package/__tests__/adapters/travel-tongcheng.test.js +0 -289
- package/__tests__/adapters/video-platforms.test.js +0 -152
- package/__tests__/adapters/video-xigua.test.js +0 -106
- package/__tests__/adapters/vscode.test.js +0 -299
- package/__tests__/adapters/wechat-bootstrap.test.js +0 -240
- package/__tests__/adapters/wechat-env-probe.test.js +0 -162
- package/__tests__/adapters/wechat-frida-agent.test.js +0 -322
- package/__tests__/adapters/wechat-frida-integration.test.js +0 -149
- package/__tests__/adapters/wechat-frida-key-provider.test.js +0 -188
- package/__tests__/adapters/wechat-md5-key-provider.test.js +0 -101
- package/__tests__/adapters/wechat-pc-direct-read.test.js +0 -365
- package/__tests__/adapters/wechat-pc-group-topic.test.js +0 -63
- package/__tests__/adapters/wechat-pc-v4-sidecar.test.js +0 -72
- package/__tests__/adapters/weread.test.js +0 -123
- package/__tests__/adapters/wework-pc.test.js +0 -124
- package/__tests__/adapters/win-recent.test.js +0 -192
- package/__tests__/analysis-skills.test.js +0 -754
- package/__tests__/analysis.test.js +0 -1845
- package/__tests__/audio-ximalaya-snapshot.test.js +0 -279
- package/__tests__/batch.test.js +0 -133
- package/__tests__/bridges-cc-kg.test.js +0 -231
- package/__tests__/bridges-cc-llm.test.js +0 -191
- package/__tests__/bridges-cc-rag.test.js +0 -162
- package/__tests__/categories.test.js +0 -92
- package/__tests__/e2e/ai-chat-cross-source-journey.test.js +0 -213
- package/__tests__/e2e/full-user-journey.test.js +0 -188
- package/__tests__/e2e/local-data-adapters-cli.e2e.test.js +0 -146
- package/__tests__/entity-resolver-ingest-hook.test.js +0 -177
- package/__tests__/entity-resolver-stages.test.js +0 -411
- package/__tests__/entity-resolver-vault.test.js +0 -249
- package/__tests__/entity-resolver.test.js +0 -526
- package/__tests__/fitness-keep-snapshot.test.js +0 -224
- package/__tests__/fixtures/entity-resolver-200-mock.json +0 -96
- package/__tests__/ids.test.js +0 -45
- package/__tests__/integration/ai-chat-history-registry.test.js +0 -228
- package/__tests__/integration/aichat-wizard-end-to-end.test.js +0 -282
- package/__tests__/integration/cross-adapter-pipelines.test.js +0 -396
- package/__tests__/integration/local-data-adapters-pipeline.test.js +0 -373
- package/__tests__/integration/social-bilibili-pipeline.test.js +0 -261
- package/__tests__/integration/wechat-bootstrap-end-to-end.test.js +0 -390
- package/__tests__/key-providers.test.js +0 -126
- package/__tests__/kg-derive.test.js +0 -219
- package/__tests__/llm-client.test.js +0 -122
- package/__tests__/longtail-adapters.test.js +0 -281
- package/__tests__/messaging-qq-snapshot.test.js +0 -294
- package/__tests__/mobile-extractor-encrypted.test.js +0 -460
- package/__tests__/mobile-extractor.test.js +0 -288
- package/__tests__/mock-adapter.test.js +0 -93
- package/__tests__/prompt-builder.test.js +0 -249
- package/__tests__/query-parser.test.js +0 -365
- package/__tests__/rag-derive.test.js +0 -169
- package/__tests__/registry-readiness.test.js +0 -292
- package/__tests__/registry.test.js +0 -420
- package/__tests__/salvage-ingest.test.js +0 -97
- package/__tests__/schemas.test.js +0 -331
- package/__tests__/shopping-adapters.test.js +0 -392
- package/__tests__/shopping-eleme-snapshot.test.js +0 -454
- package/__tests__/shopping-pinduoduo-snapshot.test.js +0 -484
- package/__tests__/shopping-snapshot.test.js +0 -438
- package/__tests__/shopping-vipshop-snapshot.test.js +0 -425
- package/__tests__/shopping-xianyu-snapshot.test.js +0 -451
- package/__tests__/sidecar-contacts-cross-validate.test.js +0 -186
- package/__tests__/sidecar-supervisor.test.js +0 -128
- package/__tests__/sign-providers.test.js +0 -62
- package/__tests__/social-adapters.test.js +0 -280
- package/__tests__/social-bilibili-snapshot.test.js +0 -278
- package/__tests__/social-douban-snapshot.test.js +0 -351
- package/__tests__/social-douyin-im-direct-read.test.js +0 -377
- package/__tests__/social-douyin-salvage-collector.test.js +0 -98
- package/__tests__/social-douyin-salvage-mapper.test.js +0 -90
- package/__tests__/social-douyin-snapshot.test.js +0 -256
- package/__tests__/social-kuaishou-snapshot.test.js +0 -362
- package/__tests__/social-toutiao-snapshot.test.js +0 -366
- package/__tests__/social-weibo-snapshot.test.js +0 -234
- package/__tests__/social-weibo-sqlite-device.test.js +0 -174
- package/__tests__/social-xiaohongshu-snapshot.test.js +0 -232
- package/__tests__/sqlite-leaf-salvage.test.js +0 -97
- package/__tests__/travel-adapters.test.js +0 -483
- package/__tests__/travel-maps-snapshot.test.js +0 -426
- package/__tests__/vault-driver-error.test.js +0 -74
- package/__tests__/vault-search-helpers.test.js +0 -104
- package/__tests__/vault-search.test.js +0 -423
- package/__tests__/vault.test.js +0 -767
- package/__tests__/wechat-adapter.test.js +0 -594
- package/__tests__/whatsapp-adapter.test.js +0 -138
- package/scripts/_make-fixture-all.js +0 -126
- package/scripts/_make-fixture-contacts.js +0 -84
- package/scripts/evaluate-entity-resolver.js +0 -213
- package/scripts/run-native-tests-sandbox.sh +0 -55
- package/scripts/smoke-phase-5-5.js +0 -196
- package/scripts/smoke-phase-5-7.js +0 -181
- package/scripts/smoke-system-data-contacts.js +0 -309
- package/scripts/smoke-system-data.js +0 -312
- package/vitest.config.js +0 -88
|
@@ -1,278 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { describe, it, expect, beforeEach } from "vitest";
|
|
4
|
-
|
|
5
|
-
const fs = require("node:fs");
|
|
6
|
-
const path = require("node:path");
|
|
7
|
-
const os = require("node:os");
|
|
8
|
-
|
|
9
|
-
const {
|
|
10
|
-
BilibiliAdapter,
|
|
11
|
-
SNAPSHOT_SCHEMA_VERSION,
|
|
12
|
-
VALID_KINDS,
|
|
13
|
-
} = require("../lib/adapters/social-bilibili");
|
|
14
|
-
const { validateBatch } = require("../lib/batch");
|
|
15
|
-
|
|
16
|
-
// A8 v0.1 (2026-05-22) — snapshot-mode tests, mirroring system-data-android.
|
|
17
|
-
//
|
|
18
|
-
// Why a separate file? `social-adapters.test.js` covers the legacy sqlite
|
|
19
|
-
// path (Phase 7.5 device-pull). Snapshot mode is a brand-new ingestion path
|
|
20
|
-
// driven by in-APK Android cc reading JSON from the phone's own WebView+OkHttp
|
|
21
|
-
// pipeline. Keeping tests separated makes it obvious which mode a regression
|
|
22
|
-
// belongs to.
|
|
23
|
-
|
|
24
|
-
function writeSnapshot(dir, snapshot) {
|
|
25
|
-
const p = path.join(dir, "social-bilibili.json");
|
|
26
|
-
fs.writeFileSync(p, JSON.stringify(snapshot), "utf-8");
|
|
27
|
-
return p;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
describe("BilibiliAdapter snapshot mode", () => {
|
|
31
|
-
let tmpDir;
|
|
32
|
-
beforeEach(() => {
|
|
33
|
-
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "bili-snap-"));
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it("exports SNAPSHOT_SCHEMA_VERSION = 1 + 4 VALID_KINDS", () => {
|
|
37
|
-
expect(SNAPSHOT_SCHEMA_VERSION).toBe(1);
|
|
38
|
-
expect(VALID_KINDS).toEqual(["history", "favourite", "dynamic", "follow"]);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it("authenticate(inputPath) ok when readable", async () => {
|
|
42
|
-
const p = writeSnapshot(tmpDir, {
|
|
43
|
-
schemaVersion: 1,
|
|
44
|
-
snapshottedAt: Date.now(),
|
|
45
|
-
events: [],
|
|
46
|
-
});
|
|
47
|
-
const a = new BilibiliAdapter();
|
|
48
|
-
const res = await a.authenticate({ inputPath: p });
|
|
49
|
-
expect(res.ok).toBe(true);
|
|
50
|
-
expect(res.mode).toBe("snapshot-file");
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it("authenticate(inputPath) fails when path unreadable", async () => {
|
|
54
|
-
const a = new BilibiliAdapter();
|
|
55
|
-
const res = await a.authenticate({ inputPath: path.join(tmpDir, "missing.json") });
|
|
56
|
-
expect(res.ok).toBe(false);
|
|
57
|
-
expect(res.reason).toBe("INPUT_PATH_UNREADABLE");
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("authenticate() with neither inputPath nor dbPath returns NO_INPUT", async () => {
|
|
61
|
-
const a = new BilibiliAdapter();
|
|
62
|
-
const res = await a.authenticate({});
|
|
63
|
-
expect(res.ok).toBe(false);
|
|
64
|
-
expect(res.reason).toBe("NO_INPUT");
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it("rejects schemaVersion mismatch", async () => {
|
|
68
|
-
const p = writeSnapshot(tmpDir, {
|
|
69
|
-
schemaVersion: 99,
|
|
70
|
-
snapshottedAt: Date.now(),
|
|
71
|
-
events: [],
|
|
72
|
-
});
|
|
73
|
-
const a = new BilibiliAdapter();
|
|
74
|
-
let threw = null;
|
|
75
|
-
try {
|
|
76
|
-
for await (const _r of a.sync({ inputPath: p })) { /* drain */ }
|
|
77
|
-
} catch (err) {
|
|
78
|
-
threw = err;
|
|
79
|
-
}
|
|
80
|
-
expect(threw).toBeTruthy();
|
|
81
|
-
expect(String(threw.message)).toMatch(/schemaVersion mismatch/);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it("empty events array yields nothing (no crash)", async () => {
|
|
85
|
-
const p = writeSnapshot(tmpDir, {
|
|
86
|
-
schemaVersion: 1,
|
|
87
|
-
snapshottedAt: Date.now(),
|
|
88
|
-
events: [],
|
|
89
|
-
});
|
|
90
|
-
const a = new BilibiliAdapter();
|
|
91
|
-
const raws = [];
|
|
92
|
-
for await (const r of a.sync({ inputPath: p })) raws.push(r);
|
|
93
|
-
expect(raws).toHaveLength(0);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it("yields all 4 kinds + normalize produces valid batches", async () => {
|
|
97
|
-
const p = writeSnapshot(tmpDir, {
|
|
98
|
-
schemaVersion: 1,
|
|
99
|
-
snapshottedAt: 1716000000000,
|
|
100
|
-
account: { uid: "12345", displayName: "alice" },
|
|
101
|
-
events: [
|
|
102
|
-
{
|
|
103
|
-
kind: "history",
|
|
104
|
-
id: "BV1abc",
|
|
105
|
-
capturedAt: 1715000000000,
|
|
106
|
-
title: "Rust 异步学习",
|
|
107
|
-
bvid: "BV1abc",
|
|
108
|
-
avid: 42,
|
|
109
|
-
duration: 600,
|
|
110
|
-
uploader: "技术UP主",
|
|
111
|
-
uploaderMid: 100,
|
|
112
|
-
part: "01 介绍",
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
kind: "favourite",
|
|
116
|
-
id: "fav-BV2def",
|
|
117
|
-
capturedAt: 1714000000000,
|
|
118
|
-
title: "前端架构",
|
|
119
|
-
bvid: "BV2def",
|
|
120
|
-
folderName: "学习",
|
|
121
|
-
uploader: "码农UP",
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
kind: "dynamic",
|
|
125
|
-
id: "dyn-99",
|
|
126
|
-
capturedAt: 1713000000000,
|
|
127
|
-
summary: "今天发了一个新视频",
|
|
128
|
-
dynamicType: "video",
|
|
129
|
-
rid: 99,
|
|
130
|
-
authorMid: 200,
|
|
131
|
-
authorName: "我关注的UP",
|
|
132
|
-
},
|
|
133
|
-
{
|
|
134
|
-
kind: "follow",
|
|
135
|
-
id: "follow-300",
|
|
136
|
-
capturedAt: 1712000000000,
|
|
137
|
-
mid: 300,
|
|
138
|
-
uname: "美食UP",
|
|
139
|
-
face: "https://i0.hdslb.com/...",
|
|
140
|
-
sign: "好吃的视频",
|
|
141
|
-
},
|
|
142
|
-
],
|
|
143
|
-
});
|
|
144
|
-
const a = new BilibiliAdapter();
|
|
145
|
-
const raws = [];
|
|
146
|
-
for await (const r of a.sync({ inputPath: p })) raws.push(r);
|
|
147
|
-
|
|
148
|
-
expect(raws).toHaveLength(4);
|
|
149
|
-
expect(raws.map((r) => r.kind).sort()).toEqual([
|
|
150
|
-
"dynamic",
|
|
151
|
-
"favourite",
|
|
152
|
-
"follow",
|
|
153
|
-
"history",
|
|
154
|
-
]);
|
|
155
|
-
// Stable originalId format
|
|
156
|
-
expect(raws.find((r) => r.kind === "history").originalId).toBe("bilibili:history:BV1abc");
|
|
157
|
-
expect(raws.find((r) => r.kind === "favourite").originalId).toBe("bilibili:favourite:fav-BV2def");
|
|
158
|
-
expect(raws.find((r) => r.kind === "dynamic").originalId).toBe("bilibili:dynamic:dyn-99");
|
|
159
|
-
expect(raws.find((r) => r.kind === "follow").originalId).toBe("bilibili:follow:follow-300");
|
|
160
|
-
|
|
161
|
-
// Normalize each + validate
|
|
162
|
-
for (const raw of raws) {
|
|
163
|
-
const batch = a.normalize(raw);
|
|
164
|
-
const v = validateBatch(batch);
|
|
165
|
-
expect(v.valid).toBe(true);
|
|
166
|
-
|
|
167
|
-
if (raw.kind === "history") {
|
|
168
|
-
expect(batch.events[0].subtype).toBe("browse");
|
|
169
|
-
expect(batch.events[0].extra.bvid).toBe("BV1abc");
|
|
170
|
-
expect(batch.events[0].extra.duration).toBe(600);
|
|
171
|
-
expect(batch.items).toHaveLength(1);
|
|
172
|
-
expect(batch.items[0].name).toBe("Rust 异步学习");
|
|
173
|
-
} else if (raw.kind === "favourite") {
|
|
174
|
-
expect(batch.events[0].subtype).toBe("like");
|
|
175
|
-
expect(batch.events[0].extra.folderName).toBe("学习");
|
|
176
|
-
expect(batch.items).toHaveLength(1);
|
|
177
|
-
} else if (raw.kind === "dynamic") {
|
|
178
|
-
expect(batch.events[0].subtype).toBe("browse");
|
|
179
|
-
expect(batch.events[0].extra.dynamicType).toBe("video");
|
|
180
|
-
expect(batch.events[0].extra.authorName).toBe("我关注的UP");
|
|
181
|
-
} else if (raw.kind === "follow") {
|
|
182
|
-
// Follow yields a person, not an event
|
|
183
|
-
expect(batch.events).toHaveLength(0);
|
|
184
|
-
expect(batch.persons).toHaveLength(1);
|
|
185
|
-
expect(batch.persons[0].names[0]).toBe("美食UP");
|
|
186
|
-
expect(batch.persons[0].identifiers["bilibili-mid"]).toEqual(["300"]);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
it("per-kind include filter (e.g. include.follow=false drops follows)", async () => {
|
|
192
|
-
const p = writeSnapshot(tmpDir, {
|
|
193
|
-
schemaVersion: 1,
|
|
194
|
-
snapshottedAt: Date.now(),
|
|
195
|
-
events: [
|
|
196
|
-
{ kind: "history", id: "h1", title: "x" },
|
|
197
|
-
{ kind: "follow", id: "f1", mid: 1, uname: "u" },
|
|
198
|
-
],
|
|
199
|
-
});
|
|
200
|
-
const a = new BilibiliAdapter();
|
|
201
|
-
const raws = [];
|
|
202
|
-
for await (const r of a.sync({ inputPath: p, include: { follow: false } })) {
|
|
203
|
-
raws.push(r);
|
|
204
|
-
}
|
|
205
|
-
expect(raws).toHaveLength(1);
|
|
206
|
-
expect(raws[0].kind).toBe("history");
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
it("limit caps emission", async () => {
|
|
210
|
-
const p = writeSnapshot(tmpDir, {
|
|
211
|
-
schemaVersion: 1,
|
|
212
|
-
snapshottedAt: Date.now(),
|
|
213
|
-
events: [
|
|
214
|
-
{ kind: "history", id: "1", title: "a" },
|
|
215
|
-
{ kind: "history", id: "2", title: "b" },
|
|
216
|
-
{ kind: "history", id: "3", title: "c" },
|
|
217
|
-
],
|
|
218
|
-
});
|
|
219
|
-
const a = new BilibiliAdapter();
|
|
220
|
-
const raws = [];
|
|
221
|
-
for await (const r of a.sync({ inputPath: p, limit: 2 })) raws.push(r);
|
|
222
|
-
expect(raws).toHaveLength(2);
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
it("skips unknown kinds (forward-compat with future event types)", async () => {
|
|
226
|
-
const p = writeSnapshot(tmpDir, {
|
|
227
|
-
schemaVersion: 1,
|
|
228
|
-
snapshottedAt: Date.now(),
|
|
229
|
-
events: [
|
|
230
|
-
{ kind: "history", id: "1", title: "ok" },
|
|
231
|
-
{ kind: "fancy-new-kind-from-future", id: "x", data: "?" },
|
|
232
|
-
{ kind: "favourite", id: "f", title: "also ok" },
|
|
233
|
-
],
|
|
234
|
-
});
|
|
235
|
-
const a = new BilibiliAdapter();
|
|
236
|
-
const raws = [];
|
|
237
|
-
for await (const r of a.sync({ inputPath: p })) raws.push(r);
|
|
238
|
-
expect(raws).toHaveLength(2);
|
|
239
|
-
expect(raws.map((r) => r.kind).sort()).toEqual(["favourite", "history"]);
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
it("uses fallback originalId when event.id absent (no crash, still ingestable)", async () => {
|
|
243
|
-
const p = writeSnapshot(tmpDir, {
|
|
244
|
-
schemaVersion: 1,
|
|
245
|
-
snapshottedAt: Date.now(),
|
|
246
|
-
events: [
|
|
247
|
-
// Missing id — adapter should derive from bvid/mid/rid or generate fallback
|
|
248
|
-
{ kind: "history", bvid: "BV1xyz", title: "no-id" },
|
|
249
|
-
{ kind: "follow", mid: 999, uname: "with-mid-no-id" },
|
|
250
|
-
{ kind: "dynamic", summary: "no id no rid" },
|
|
251
|
-
],
|
|
252
|
-
});
|
|
253
|
-
const a = new BilibiliAdapter();
|
|
254
|
-
const raws = [];
|
|
255
|
-
for await (const r of a.sync({ inputPath: p })) raws.push(r);
|
|
256
|
-
expect(raws).toHaveLength(3);
|
|
257
|
-
// history derives from bvid
|
|
258
|
-
expect(raws[0].originalId).toBe("bilibili:history:BV1xyz");
|
|
259
|
-
// follow derives from mid
|
|
260
|
-
expect(raws[1].originalId).toBe("bilibili:follow:999");
|
|
261
|
-
// dynamic with no id/bvid/mid/rid → fallback unknown- prefix
|
|
262
|
-
expect(raws[2].originalId).toMatch(/^bilibili:dynamic:unknown-/);
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
it("snapshot account propagates to payload (Path Y can re-attribute later)", async () => {
|
|
266
|
-
const p = writeSnapshot(tmpDir, {
|
|
267
|
-
schemaVersion: 1,
|
|
268
|
-
snapshottedAt: Date.now(),
|
|
269
|
-
account: { uid: "55555", displayName: "tester" },
|
|
270
|
-
events: [{ kind: "history", id: "1", title: "x" }],
|
|
271
|
-
});
|
|
272
|
-
const a = new BilibiliAdapter();
|
|
273
|
-
const raws = [];
|
|
274
|
-
for await (const r of a.sync({ inputPath: p })) raws.push(r);
|
|
275
|
-
expect(raws).toHaveLength(1);
|
|
276
|
-
expect(raws[0].payload.account.uid).toBe("55555");
|
|
277
|
-
});
|
|
278
|
-
});
|
|
@@ -1,351 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { describe, it, expect, beforeEach } from "vitest";
|
|
4
|
-
|
|
5
|
-
const fs = require("node:fs");
|
|
6
|
-
const path = require("node:path");
|
|
7
|
-
const os = require("node:os");
|
|
8
|
-
|
|
9
|
-
const {
|
|
10
|
-
DoubanAdapter,
|
|
11
|
-
SNAPSHOT_SCHEMA_VERSION,
|
|
12
|
-
VALID_SNAPSHOT_KINDS,
|
|
13
|
-
extractData,
|
|
14
|
-
} = require("../lib/adapters/social-douban");
|
|
15
|
-
const { assertAdapter } = require("../lib/adapter-spec");
|
|
16
|
-
const { validateBatch } = require("../lib/batch");
|
|
17
|
-
|
|
18
|
-
// 豆瓣 (Douban / Frodo) — 书影音 interest graph. Mirrors social-zhihu's two-mode
|
|
19
|
-
// custom-normalize shape + video-base MEDIA event+item for marks. Frodo signing
|
|
20
|
-
// is injected (signProvider) so the adapter stays pure-Node.
|
|
21
|
-
|
|
22
|
-
function writeSnapshot(dir, snapshot) {
|
|
23
|
-
const p = path.join(dir, "social-douban.json");
|
|
24
|
-
fs.writeFileSync(p, JSON.stringify(snapshot), "utf-8");
|
|
25
|
-
return p;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
describe("DoubanAdapter snapshot mode", () => {
|
|
29
|
-
let tmpDir;
|
|
30
|
-
beforeEach(() => {
|
|
31
|
-
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "douban-snap-"));
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it("exports schema constants", () => {
|
|
35
|
-
expect(SNAPSHOT_SCHEMA_VERSION).toBe(1);
|
|
36
|
-
expect(VALID_SNAPSHOT_KINDS).toEqual(["interest", "review", "follow"]);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it("authenticate(inputPath) ok when readable", async () => {
|
|
40
|
-
const p = writeSnapshot(tmpDir, { schemaVersion: 1, snapshottedAt: Date.now(), events: [] });
|
|
41
|
-
const a = new DoubanAdapter();
|
|
42
|
-
const res = await a.authenticate({ inputPath: p });
|
|
43
|
-
expect(res.ok).toBe(true);
|
|
44
|
-
expect(res.mode).toBe("snapshot-file");
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it("authenticate() no input → NO_INPUT", async () => {
|
|
48
|
-
const a = new DoubanAdapter();
|
|
49
|
-
const res = await a.authenticate({});
|
|
50
|
-
expect(res.ok).toBe(false);
|
|
51
|
-
expect(res.reason).toBe("NO_INPUT");
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("sync() without input throws with signProvider hint", async () => {
|
|
55
|
-
const a = new DoubanAdapter();
|
|
56
|
-
let threw = null;
|
|
57
|
-
try {
|
|
58
|
-
for await (const _r of a.sync({})) { /* drain */ }
|
|
59
|
-
} catch (err) {
|
|
60
|
-
threw = err;
|
|
61
|
-
}
|
|
62
|
-
expect(threw).toBeTruthy();
|
|
63
|
-
expect(String(threw.message)).toMatch(/signProvider/);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it("rejects schemaVersion mismatch", async () => {
|
|
67
|
-
const p = writeSnapshot(tmpDir, { schemaVersion: 99, snapshottedAt: Date.now(), events: [] });
|
|
68
|
-
const a = new DoubanAdapter();
|
|
69
|
-
let threw = null;
|
|
70
|
-
try {
|
|
71
|
-
for await (const _r of a.sync({ inputPath: p })) { /* drain */ }
|
|
72
|
-
} catch (err) {
|
|
73
|
-
threw = err;
|
|
74
|
-
}
|
|
75
|
-
expect(String(threw.message)).toMatch(/schemaVersion mismatch/);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it("interest (看过电影) → MEDIA event + MEDIA item, normalizes cleanly", async () => {
|
|
79
|
-
const now = Date.now();
|
|
80
|
-
const p = writeSnapshot(tmpDir, {
|
|
81
|
-
schemaVersion: 1,
|
|
82
|
-
snapshottedAt: now,
|
|
83
|
-
account: { userId: "12345", name: "alice" },
|
|
84
|
-
events: [
|
|
85
|
-
{
|
|
86
|
-
kind: "interest", id: "interest-m1", subjectId: "26266893",
|
|
87
|
-
subjectType: "movie", title: "瞬息全宇宙", status: "done",
|
|
88
|
-
myRating: 5, comment: "好看", createdTime: 1700000000, url: "https://movie.douban.com/subject/26266893/",
|
|
89
|
-
},
|
|
90
|
-
],
|
|
91
|
-
});
|
|
92
|
-
const a = new DoubanAdapter();
|
|
93
|
-
const raws = [];
|
|
94
|
-
for await (const r of a.sync({ inputPath: p })) raws.push(r);
|
|
95
|
-
expect(raws.length).toBe(1);
|
|
96
|
-
expect(raws[0].kind).toBe("interest");
|
|
97
|
-
expect(raws[0].originalId).toBe("douban:interest:interest-m1");
|
|
98
|
-
|
|
99
|
-
const batch = a.normalize(raws[0]);
|
|
100
|
-
expect(validateBatch(batch).valid).toBe(true);
|
|
101
|
-
expect(batch.events.length).toBe(1);
|
|
102
|
-
expect(batch.items.length).toBe(1);
|
|
103
|
-
expect(batch.events[0].subtype).toBe("media");
|
|
104
|
-
expect(batch.events[0].content.title).toContain("看过电影: 瞬息全宇宙");
|
|
105
|
-
expect(batch.events[0].extra.myRating).toBe(5);
|
|
106
|
-
expect(batch.items[0].name).toBe("瞬息全宇宙");
|
|
107
|
-
expect(JSON.stringify(batch)).toContain("好看");
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it("interest status maps to verb (mark=想看, doing=在看, done=看过)", async () => {
|
|
111
|
-
const now = Date.now();
|
|
112
|
-
const cases = [
|
|
113
|
-
{ status: "mark", verb: "想看" },
|
|
114
|
-
{ status: "doing", verb: "在看" },
|
|
115
|
-
{ status: "done", verb: "看过" },
|
|
116
|
-
];
|
|
117
|
-
for (const c of cases) {
|
|
118
|
-
const p = writeSnapshot(tmpDir, {
|
|
119
|
-
schemaVersion: 1, snapshottedAt: now,
|
|
120
|
-
events: [
|
|
121
|
-
{ kind: "interest", id: `i-${c.status}`, subjectId: "1", subjectType: "book",
|
|
122
|
-
title: "三体", status: c.status, createdTime: now },
|
|
123
|
-
],
|
|
124
|
-
});
|
|
125
|
-
const a = new DoubanAdapter();
|
|
126
|
-
const raws = [];
|
|
127
|
-
for await (const r of a.sync({ inputPath: p })) raws.push(r);
|
|
128
|
-
const batch = a.normalize(raws[0]);
|
|
129
|
-
expect(batch.events[0].content.title).toContain(`${c.verb}图书: 三体`);
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it("review → POST event", async () => {
|
|
134
|
-
const now = Date.now();
|
|
135
|
-
const p = writeSnapshot(tmpDir, {
|
|
136
|
-
schemaVersion: 1, snapshottedAt: now,
|
|
137
|
-
events: [
|
|
138
|
-
{ kind: "review", id: "review-1", reviewId: "9001", title: "一篇影评",
|
|
139
|
-
abstract: "<p>写得不错</p>", subjectTitle: "瞬息全宇宙", rating: 4, createdTime: now },
|
|
140
|
-
],
|
|
141
|
-
});
|
|
142
|
-
const a = new DoubanAdapter();
|
|
143
|
-
const raws = [];
|
|
144
|
-
for await (const r of a.sync({ inputPath: p })) raws.push(r);
|
|
145
|
-
const batch = a.normalize(raws[0]);
|
|
146
|
-
expect(validateBatch(batch).valid).toBe(true);
|
|
147
|
-
expect(batch.events[0].subtype).toBe("post");
|
|
148
|
-
expect(batch.events[0].content.title).toBe("一篇影评");
|
|
149
|
-
expect(batch.events[0].content.text).toBe("写得不错"); // html stripped
|
|
150
|
-
expect(batch.events[0].extra.rating).toBe(4);
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it("follow → CONTACT person with douban-id identifier", async () => {
|
|
154
|
-
const now = Date.now();
|
|
155
|
-
const p = writeSnapshot(tmpDir, {
|
|
156
|
-
schemaVersion: 1, snapshottedAt: now,
|
|
157
|
-
events: [
|
|
158
|
-
{ kind: "follow", id: "follow-u1", memberId: "67890", name: "豆友小张",
|
|
159
|
-
url: "https://www.douban.com/people/67890/", capturedAt: now },
|
|
160
|
-
],
|
|
161
|
-
});
|
|
162
|
-
const a = new DoubanAdapter();
|
|
163
|
-
const raws = [];
|
|
164
|
-
for await (const r of a.sync({ inputPath: p })) raws.push(r);
|
|
165
|
-
const batch = a.normalize(raws[0]);
|
|
166
|
-
expect(validateBatch(batch).valid).toBe(true);
|
|
167
|
-
expect(batch.persons.length).toBe(1);
|
|
168
|
-
expect(batch.persons[0].id).toBe("person-douban-67890");
|
|
169
|
-
expect(batch.persons[0].names).toEqual(["豆友小张"]);
|
|
170
|
-
expect(batch.persons[0].identifiers["douban-id"]).toEqual(["67890"]);
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it("respects per-kind include opt-out + limit", async () => {
|
|
174
|
-
const now = Date.now();
|
|
175
|
-
const events = [
|
|
176
|
-
{ kind: "interest", id: "i1", subjectId: "1", subjectType: "movie", title: "a", status: "done", createdTime: now },
|
|
177
|
-
{ kind: "review", id: "r1", reviewId: "2", title: "b", createdTime: now },
|
|
178
|
-
{ kind: "follow", id: "f1", memberId: "3", name: "c", capturedAt: now },
|
|
179
|
-
];
|
|
180
|
-
const p = writeSnapshot(tmpDir, { schemaVersion: 1, snapshottedAt: now, events });
|
|
181
|
-
const a = new DoubanAdapter();
|
|
182
|
-
const raws = [];
|
|
183
|
-
for await (const r of a.sync({ inputPath: p, include: { review: false, follow: false } })) raws.push(r);
|
|
184
|
-
expect(raws.length).toBe(1);
|
|
185
|
-
expect(raws[0].kind).toBe("interest");
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
it("filters unknown kinds (forward compat)", async () => {
|
|
189
|
-
const now = Date.now();
|
|
190
|
-
const p = writeSnapshot(tmpDir, {
|
|
191
|
-
schemaVersion: 1, snapshottedAt: now,
|
|
192
|
-
events: [
|
|
193
|
-
{ kind: "interest", id: "i1", subjectId: "1", subjectType: "movie", title: "a", status: "done", createdTime: now },
|
|
194
|
-
{ kind: "status", id: "s1" },
|
|
195
|
-
],
|
|
196
|
-
});
|
|
197
|
-
const a = new DoubanAdapter();
|
|
198
|
-
const raws = [];
|
|
199
|
-
for await (const r of a.sync({ inputPath: p })) raws.push(r);
|
|
200
|
-
expect(raws.length).toBe(1);
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
it("advertises snapshot + cookie-api capabilities; passes assertAdapter", () => {
|
|
204
|
-
const a = new DoubanAdapter();
|
|
205
|
-
expect(a.capabilities).toContain("sync:snapshot");
|
|
206
|
-
expect(a.capabilities).toContain("sync:cookie-api");
|
|
207
|
-
expect(assertAdapter(a).ok).toBe(true);
|
|
208
|
-
});
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
describe("DoubanAdapter cookie-api mode", () => {
|
|
212
|
-
it("authenticate(cookie) requires account.userId", async () => {
|
|
213
|
-
const a = new DoubanAdapter({ account: { cookies: "bid=ok" } });
|
|
214
|
-
const res = await a.authenticate();
|
|
215
|
-
expect(res.ok).toBe(false);
|
|
216
|
-
expect(res.reason).toBe("NO_ACCOUNT_USER_ID");
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
it("authenticate(cookie) ok when userId + cookies present", async () => {
|
|
220
|
-
const a = new DoubanAdapter({ account: { userId: "12345", cookies: "bid=ok" } });
|
|
221
|
-
const res = await a.authenticate();
|
|
222
|
-
expect(res.ok).toBe(true);
|
|
223
|
-
expect(res.mode).toBe("cookie");
|
|
224
|
-
expect(res.account).toBe("12345");
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
it("fetches interests/reviews/following across the plan and normalizes", async () => {
|
|
228
|
-
const byUrl = (url) => {
|
|
229
|
-
if (url.includes("/interests")) {
|
|
230
|
-
return {
|
|
231
|
-
interests: [
|
|
232
|
-
{ id: "int1", status: "done", create_time: "2024-01-02 10:00:00",
|
|
233
|
-
rating: { value: 4 }, comment: "不错",
|
|
234
|
-
subject: { id: "26266893", type: "movie", title: "瞬息全宇宙", url: "u" } },
|
|
235
|
-
],
|
|
236
|
-
total: 1,
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
if (url.includes("/reviews")) {
|
|
240
|
-
return { reviews: [{ id: "rev1", title: "影评", abstract: "好", create_time: "2024-01-03 10:00:00", subject: { title: "瞬息全宇宙" } }], total: 1 };
|
|
241
|
-
}
|
|
242
|
-
if (url.includes("/following")) {
|
|
243
|
-
return { users: [{ id: "u9", name: "豆友" }], total: 1 };
|
|
244
|
-
}
|
|
245
|
-
return { total: 0 };
|
|
246
|
-
};
|
|
247
|
-
const fetchFn = async (opts) => byUrl(opts.url);
|
|
248
|
-
const a = new DoubanAdapter({ account: { userId: "12345", cookies: "bid=ok" }, fetchFn });
|
|
249
|
-
const raws = [];
|
|
250
|
-
for await (const r of a.sync({})) raws.push(r);
|
|
251
|
-
expect(raws.map((r) => r.kind).sort()).toEqual(["follow", "interest", "review"]);
|
|
252
|
-
|
|
253
|
-
const interest = raws.find((r) => r.kind === "interest");
|
|
254
|
-
const ib = a.normalize(interest);
|
|
255
|
-
expect(validateBatch(ib).valid).toBe(true);
|
|
256
|
-
expect(ib.events[0].subtype).toBe("media");
|
|
257
|
-
expect(ib.events[0].content.title).toContain("看过电影: 瞬息全宇宙");
|
|
258
|
-
expect(ib.events[0].extra.myRating).toBe(4);
|
|
259
|
-
expect(ib.items[0].name).toBe("瞬息全宇宙");
|
|
260
|
-
|
|
261
|
-
const follow = raws.find((r) => r.kind === "follow");
|
|
262
|
-
const fb = a.normalize(follow);
|
|
263
|
-
expect(fb.persons[0].identifiers["douban-id"]).toEqual(["u9"]);
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
it("invokes signProvider and passes sign to fetchFn", async () => {
|
|
267
|
-
let seenSign = null;
|
|
268
|
-
const signProvider = async () => "SIG-1";
|
|
269
|
-
const fetchFn = async (opts) => {
|
|
270
|
-
seenSign = opts.sign;
|
|
271
|
-
return { total: 0 };
|
|
272
|
-
};
|
|
273
|
-
const a = new DoubanAdapter({
|
|
274
|
-
account: { userId: "12345", cookies: "bid=ok" },
|
|
275
|
-
fetchFn,
|
|
276
|
-
signProvider,
|
|
277
|
-
});
|
|
278
|
-
for await (const _r of a.sync({ include: { review: false, follow: false } })) { /* drain */ }
|
|
279
|
-
expect(seenSign).toBe("SIG-1");
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
it("passes sign: null when no signProvider", async () => {
|
|
283
|
-
let seen = "unset";
|
|
284
|
-
const fetchFn = async (opts) => {
|
|
285
|
-
seen = opts.sign;
|
|
286
|
-
return { total: 0 };
|
|
287
|
-
};
|
|
288
|
-
const a = new DoubanAdapter({ account: { userId: "12345", cookies: "bid=ok" }, fetchFn });
|
|
289
|
-
for await (const _r of a.sync({ include: { review: false, follow: false } })) { /* drain */ }
|
|
290
|
-
expect(seen).toBe(null);
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
it("paginates interests with start cursor until total reached", async () => {
|
|
294
|
-
const seenStarts = [];
|
|
295
|
-
const all = Array.from({ length: 25 }, (_, i) => ({
|
|
296
|
-
id: `int${i}`, status: "done", create_time: "2024-01-01 00:00:00",
|
|
297
|
-
subject: { id: String(i), type: "book", title: `书${i}` },
|
|
298
|
-
}));
|
|
299
|
-
const fetchFn = async (opts) => {
|
|
300
|
-
if (!opts.url.includes("/interests")) return { total: 0 };
|
|
301
|
-
const start = opts.query.start;
|
|
302
|
-
seenStarts.push(start);
|
|
303
|
-
return { interests: all.slice(start, start + 20), total: all.length };
|
|
304
|
-
};
|
|
305
|
-
const a = new DoubanAdapter({ account: { userId: "12345", cookies: "bid=ok" }, fetchFn });
|
|
306
|
-
const raws = [];
|
|
307
|
-
for await (const r of a.sync({ include: { review: false, follow: false } })) raws.push(r);
|
|
308
|
-
expect(raws.length).toBe(25);
|
|
309
|
-
expect(seenStarts).toEqual([0, 20]);
|
|
310
|
-
});
|
|
311
|
-
|
|
312
|
-
it("extractData tolerates Frodo response shapes", () => {
|
|
313
|
-
expect(extractData({ interests: [1] }, "interest")).toEqual([1]);
|
|
314
|
-
expect(extractData({ reviews: [2] }, "review")).toEqual([2]);
|
|
315
|
-
expect(extractData({ users: [3] }, "follow")).toEqual([3]);
|
|
316
|
-
expect(extractData({ items: [4] })).toEqual([4]);
|
|
317
|
-
expect(extractData([5])).toEqual([5]);
|
|
318
|
-
expect(extractData({})).toEqual([]);
|
|
319
|
-
expect(extractData(null)).toEqual([]);
|
|
320
|
-
});
|
|
321
|
-
|
|
322
|
-
it("uses opts.*Url overrides", async () => {
|
|
323
|
-
const seen = [];
|
|
324
|
-
const fetchFn = async (opts) => {
|
|
325
|
-
seen.push(opts.url);
|
|
326
|
-
return { total: 0 };
|
|
327
|
-
};
|
|
328
|
-
const a = new DoubanAdapter({
|
|
329
|
-
account: { userId: "12345", cookies: "bid=ok" },
|
|
330
|
-
fetchFn,
|
|
331
|
-
interestsUrl: "https://x/i/{id}",
|
|
332
|
-
reviewsUrl: "https://x/r/{id}",
|
|
333
|
-
followingUrl: "https://x/f/{id}",
|
|
334
|
-
});
|
|
335
|
-
for await (const _r of a.sync({})) { /* drain */ }
|
|
336
|
-
expect(seen).toContain("https://x/i/12345");
|
|
337
|
-
expect(seen).toContain("https://x/r/12345");
|
|
338
|
-
expect(seen).toContain("https://x/f/12345");
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
it("default fetchFn throws legible error in cookie mode without injection", async () => {
|
|
342
|
-
const a = new DoubanAdapter({ account: { userId: "12345", cookies: "bid=ok" } });
|
|
343
|
-
let threw = null;
|
|
344
|
-
try {
|
|
345
|
-
for await (const _r of a.sync({})) { /* drain */ }
|
|
346
|
-
} catch (err) {
|
|
347
|
-
threw = err;
|
|
348
|
-
}
|
|
349
|
-
expect(String(threw.message)).toMatch(/no fetchFn configured/);
|
|
350
|
-
});
|
|
351
|
-
});
|