"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" }); const fromApiGenealogyAccess = () => null; const session = { getToken: () => "session-1", saveToken() {} }; `; let nextResponse; const requests = []; 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: { personId: 1001, genealogyId: 900001001, genealogyName: "联调测试家谱", name: "汤文远", generation: 12, generationName: "文", sex: "MALE", fatherId: 900, fatherName: "汤世德", motherId: 901, motherName: "周氏", birthDate: "1900-01-02T00:00:00+08:00", birthPlace: "祖居地", personStatus: "ALIVE", biography: "生平资料", }, }, }; const person = await appApi.getPerson("900001001", "1001"); assert.deepStrictEqual(person, { id: "1001", genealogyId: "900001001", genealogyName: "联调测试家谱", name: "汤文远", generation: 12, generationName: "文", relation: "家谱成员", branch: "文字辈", sex: "MALE", birthDate: "1900-01-02", deathDate: "", years: "1900-01-02—", birthplace: "祖居地", biography: "生平资料", status: "normal", relatives: [ { id: "900", name: "汤世德", relation: "父亲" }, { id: "901", name: "周氏", relation: "母亲" }, ], }); assert.strictEqual( requests[0].url, "https://backend-api.ddxcjp.cn/genealogy/app/genealogies/900001001/lineage/persons/1001", ); assert.strictEqual(requests[0].method, "GET"); assert.strictEqual(requests[0].header.Authorization, "Bearer session-1"); assert.strictEqual(requests[0].timeout, 15000); nextResponse = { statusCode: 200, data: { code: 200, data: { personId: 1002, genealogyId: 900001001, name: "wrong identity", generation: 12, }, }, }; await assert.rejects( appApi.getPerson("900001001", "1001"), (error) => error?.code === "LINEAGE_PERSON_RESPONSE_INVALID", ); nextResponse = { statusCode: 200, data: { code: 200, data: { personId: 1001, genealogyId: 900001001, name: "invalid date", generation: 12, birthDate: "not-a-date", }, }, }; await assert.rejects( appApi.getPerson("900001001", "1001"), (error) => error?.code === "LINEAGE_PERSON_RESPONSE_INVALID", ); process.stdout.write("T03-MEMBER-API-RUNTIME-SMOKE PASS\n"); }; run().catch((error) => { process.stderr.write(`${error.stack || error.message}\n`); process.exit(1); });