完成40%

This commit is contained in:
rain
2026-07-23 17:21:27 +08:00
parent f1edc6b533
commit bb6431b319
114 changed files with 10931 additions and 877 deletions
+120
View File
@@ -0,0 +1,120 @@
"use strict";
const assert = require("assert");
const fs = require("fs");
const path = require("path");
const toDataModuleUrl = (source) =>
`data:text/javascript;base64,${Buffer.from(source).toString("base64")}`;
const run = async () => {
const rawSource = fs.readFileSync(path.join(__dirname, "../utils/api.js"), "utf8");
const moduleBody = rawSource.slice(rawSource.indexOf("const successCodes"));
const prelude = `
const currentUser = {};
const genealogies = [];
const publicGenealogies = [];
const treeMembers = [];
const notifications = [];
const joinApplications = [];
const listFamilyFeedFixtures = () => [];
const listFamilyArticleFixtures = () => [];
const listFamilyAlbumFixtures = () => [];
const listCeremonyFixtures = () => [];
const listGrowthRecordFixtures = () => [];
const listNotificationFixtures = () => [];
const runtimeConfig = {
mode: "remote",
baseUrl: "https://backend-api.ddxcjp.cn",
clientId: "client-1",
tenantId: "000000",
};
const hasRemoteConfig = () => true;
const resolveRuntimeMode = () => "remote";
const AUTH_TAC_SCENE = Object.freeze({});
const assertSmsCode = (value) => value;
const GENEALOGY_ACCESS_PRESET = Object.freeze({
MEMBER_ONLY: "MEMBER_ONLY",
PUBLIC_APPLY: "PUBLIC_APPLY",
});
const fromApiGenealogyAccess = ({ visibility, joinMode } = {}) =>
visibility === "1" && joinMode === "1"
? "PUBLIC_APPLY"
: visibility === "2" && joinMode === "0"
? "MEMBER_ONLY"
: null;
const session = {
getToken: () => "session-1",
saveToken() {},
};
`;
const requests = [];
let nextResponse;
globalThis.uni = {
request(options) {
requests.push(options);
queueMicrotask(() => options.success(nextResponse));
return { abort() {} };
},
};
const { appApi } = await import(toDataModuleUrl(`${prelude}\n${moduleBody}`));
nextResponse = {
statusCode: 200,
data: {
code: 200,
data: {
genealogyId: 900001001,
genealogyName: "汤氏家谱",
surname: "汤",
ancestralHall: "敦睦堂",
regionFullName: "河南省洛阳市",
intro: "敦亲睦族,敬祖传家。",
visibility: "1",
joinMode: "1",
memberCount: 158,
personCount: 146,
roleType: "OWNER",
canManage: true,
canEditContent: true,
joinTime: "2026-07-23T08:00:00+08:00",
},
},
};
const result = await appApi.getOverview("900001001");
assert.deepStrictEqual(result, {
id: "900001001",
name: "汤氏家谱",
surname: "汤",
hall: "敦睦堂",
location: "河南省洛阳市",
memberCount: 158,
personCount: 146,
accessPreset: "PUBLIC_APPLY",
accessRole: "owner",
canManage: true,
canEditContent: true,
intro: "敦亲睦族,敬祖传家。",
joinTime: "2026-07-23T08:00:00+08:00",
});
assert.strictEqual(
requests[0].url,
"https://backend-api.ddxcjp.cn/genealogy/app/genealogies/900001001/overview",
);
assert.strictEqual(requests[0].header.Authorization, "Bearer session-1");
assert.strictEqual(requests[0].timeout, 15000);
await assert.rejects(
appApi.getOverview("../other"),
(error) => error?.code === "GENEALOGY_ID_INVALID",
);
process.stdout.write("G05-OVERVIEW-API-RUNTIME-SMOKE PASS\n");
};
run().catch((error) => {
process.stderr.write(`${error.stack || error.message}\n`);
process.exit(1);
});