111 lines
4.9 KiB
JavaScript
111 lines
4.9 KiB
JavaScript
import assert from "node:assert/strict";
|
||
import { access, readFile } from "node:fs/promises";
|
||
import test from "node:test";
|
||
import {
|
||
formatShanghaiDate,
|
||
parseStoredDate,
|
||
} from "../app/date-utils.ts";
|
||
|
||
test("builds the branded external task shell", async () => {
|
||
const [page, layout] = await Promise.all([
|
||
readFile(new URL("../app/page.tsx", import.meta.url), "utf8"),
|
||
readFile(new URL("../app/layout.tsx", import.meta.url), "utf8"),
|
||
]);
|
||
assert.match(layout, /KOC LOOP|外部任务领取/);
|
||
assert.match(layout, /og\.png/);
|
||
assert.match(page, /正在打开任务/);
|
||
await access(new URL("../dist/server/index.js", import.meta.url));
|
||
});
|
||
|
||
test("keeps claiming minimal and backfill one-to-one", async () => {
|
||
const [page, layout, packageJson, hosting] =
|
||
await Promise.all([
|
||
readFile(new URL("../app/page.tsx", import.meta.url), "utf8"),
|
||
readFile(new URL("../app/layout.tsx", import.meta.url), "utf8"),
|
||
readFile(new URL("../package.json", import.meta.url), "utf8"),
|
||
readFile(new URL("../.openai/hosting.json", import.meta.url), "utf8"),
|
||
]);
|
||
|
||
assert.match(page, /微信号\s*\/\s*手机号/);
|
||
assert.doesNotMatch(page, /企微昵称\s*\/\s*联系人/);
|
||
assert.match(page, /claimantIdentifier:\s*claimantName/);
|
||
assert.match(page, /const \[quantity, setQuantity\] = useState\(1\)/);
|
||
assert.match(page, /distributionId:\s*selected\.id/);
|
||
assert.doesNotMatch(page, /发布账号昵称/);
|
||
assert.doesNotMatch(page, /accountNickname/);
|
||
assert.match(page, /发布链接/);
|
||
assert.match(page, /识别发布账号/);
|
||
assert.match(page, /inputMode="url"/);
|
||
assert.match(page, /长链、短链或整段分享文案/);
|
||
assert.doesNotMatch(page, /type="url"/);
|
||
assert.match(page, /发布截图/);
|
||
assert.match(page, /发布配图/);
|
||
assert.match(page, /复制标题/);
|
||
assert.match(page, /复制文案/);
|
||
assert.match(page, /下载原图/);
|
||
assert.match(page, /批量保存图片/);
|
||
assert.match(page, /navigator\.share/);
|
||
assert.match(page, /zipSync/);
|
||
assert.match(page, /navigator\.clipboard\.writeText/);
|
||
assert.match(page, /URL\.createObjectURL/);
|
||
assert.match(page, /\/api\/partner-image/);
|
||
assert.match(page, /找回领取记录/);
|
||
assert.match(page, /action:\s*"recover"/);
|
||
assert.match(page, /同一任务多次领取会分批展示/);
|
||
assert.match(page, /这篇笔记已回填,不会与其他笔记错配/);
|
||
assert.doesNotMatch(page, /批量回填/);
|
||
assert.doesNotMatch(page, /复制标题和正文/);
|
||
assert.match(page, /PRODUCTION_ADMIN_ORIGIN/);
|
||
assert.match(page, /\/api\/partner-upload/);
|
||
assert.match(page, /"X-KOC-Distribution":\s*selectedItem\.id/);
|
||
assert.match(page, /"X-KOC-Upload-Kind":\s*kind/);
|
||
assert.match(page, /上传截图并填写数据/);
|
||
assert.match(page, /提交创作者数据/);
|
||
assert.match(page, /submit_creator_metrics/);
|
||
assert.match(page, /creatorExposure/);
|
||
assert.match(page, /creatorViews/);
|
||
assert.match(page, /截图仅用于运营核对,不再自动OCR/);
|
||
assert.match(page, /曝光量/);
|
||
assert.match(page, /阅读量/);
|
||
assert.doesNotMatch(page, /recognizeCreatorMetrics/);
|
||
assert.match(page, /note-index \$\{item\.publish_url \? "done" : ""\}/);
|
||
assert.match(packageJson, /"fflate":\s*"0\.7\.4"/);
|
||
assert.doesNotMatch(packageJson, /tesseract\.js/);
|
||
assert.match(layout, /逐篇查看笔记详情并一一回填/);
|
||
assert.doesNotMatch(packageJson, /react-loading-skeleton/);
|
||
const hostingConfig = JSON.parse(hosting);
|
||
assert.equal(hostingConfig.d1, null);
|
||
assert.equal(hostingConfig.r2, null);
|
||
|
||
await access(new URL("../public/og.png", import.meta.url));
|
||
await access(new URL("../public/favicon.svg", import.meta.url));
|
||
});
|
||
|
||
test("shows D1 timestamps in Beijing time", () => {
|
||
const stored = "2026-07-29 05:36:00";
|
||
assert.equal(parseStoredDate(stored).toISOString(), "2026-07-29T05:36:00.000Z");
|
||
assert.match(formatShanghaiDate(stored, true), /07\/29.*13:36/);
|
||
});
|
||
|
||
test("creates anonymous delegation bundles and reuses one-to-one backfill", async () => {
|
||
const [page, layout, styles] = await Promise.all([
|
||
readFile(new URL("../app/page.tsx", import.meta.url), "utf8"),
|
||
readFile(new URL("../app/layout.tsx", import.meta.url), "utf8"),
|
||
readFile(new URL("../app/globals.css", import.meta.url), "utf8"),
|
||
]);
|
||
|
||
assert.match(page, /选择笔记并分享/);
|
||
assert.match(page, /生成并复制分享链接/);
|
||
assert.match(page, /action:\s*"create_delegation"/);
|
||
assert.match(page, /action:\s*"revoke_delegation"/);
|
||
assert.match(page, /合作社转派 · 无需登录/);
|
||
assert.match(page, /"X-KOC-Delegation"/);
|
||
assert.match(page, /url\.searchParams\.set\("share", shareToken\)/);
|
||
assert.match(page, /请保存当前分享链接/);
|
||
assert.doesNotMatch(page, /底层KOC手机号|底层KOC企微|底层KOC微信/);
|
||
assert.match(layout, /index:\s*false/);
|
||
assert.match(layout, /referrer:\s*"no-referrer"/);
|
||
assert.match(styles, /\.share-checkbox/);
|
||
assert.match(styles, /\.delegation-history/);
|
||
});
|