191 lines
4.8 KiB
JavaScript
191 lines
4.8 KiB
JavaScript
"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,
|
|
name: "汤文远",
|
|
generation: 12,
|
|
generationName: "文",
|
|
birthDate: "1900-01-01T16:00:00.000Z",
|
|
relationName: "始祖",
|
|
spouses: [{
|
|
personId: 1002,
|
|
name: "李氏",
|
|
generation: 12,
|
|
generationName: "文",
|
|
birthDate: "1905-03-03T16:00:00.000Z",
|
|
}],
|
|
children: [{
|
|
personId: 1011,
|
|
name: "汤正明",
|
|
generation: 13,
|
|
generationName: "正",
|
|
fatherId: 1001,
|
|
children: [{
|
|
personId: 1021,
|
|
name: "汤志成",
|
|
generation: 14,
|
|
generationName: "志",
|
|
fatherId: 1011,
|
|
deathDate: "2020-05-06T00:00:00+08:00",
|
|
}],
|
|
}, {
|
|
personId: 1031,
|
|
name: "周明轩",
|
|
generation: 13,
|
|
generationName: "正",
|
|
spouses: [{
|
|
personId: 1011,
|
|
name: "汤正明",
|
|
generation: 13,
|
|
generationName: "正",
|
|
}],
|
|
}],
|
|
}],
|
|
},
|
|
};
|
|
|
|
const tree = await appApi.getTree("900001001");
|
|
assert.deepStrictEqual(tree, [
|
|
{
|
|
id: "1001",
|
|
parentId: null,
|
|
name: "汤文远",
|
|
relation: "始祖",
|
|
generation: 12,
|
|
branch: "文字辈",
|
|
years: "1900-01-02—",
|
|
sex: "",
|
|
personStatus: "",
|
|
},
|
|
{
|
|
id: "1002",
|
|
parentId: null,
|
|
spouseOf: "1001",
|
|
name: "李氏",
|
|
relation: "配偶",
|
|
generation: 12,
|
|
branch: "文字辈",
|
|
years: "1905-03-04—",
|
|
sex: "",
|
|
personStatus: "",
|
|
},
|
|
{
|
|
id: "1011",
|
|
parentId: "1001",
|
|
name: "汤正明",
|
|
relation: "后代",
|
|
generation: 13,
|
|
branch: "正字辈",
|
|
years: "生卒待补",
|
|
sex: "",
|
|
personStatus: "",
|
|
},
|
|
{
|
|
id: "1021",
|
|
parentId: "1011",
|
|
name: "汤志成",
|
|
relation: "后代",
|
|
generation: 14,
|
|
branch: "志字辈",
|
|
years: "—2020-05-06",
|
|
sex: "",
|
|
personStatus: "",
|
|
},
|
|
{
|
|
id: "1031",
|
|
parentId: "1001",
|
|
spouseOf: "1011",
|
|
name: "周明轩",
|
|
relation: "配偶",
|
|
generation: 13,
|
|
branch: "正字辈",
|
|
years: "生卒待补",
|
|
sex: "",
|
|
personStatus: "",
|
|
},
|
|
]);
|
|
assert.strictEqual(
|
|
requests[0].url,
|
|
"https://backend-api.ddxcjp.cn/genealogy/app/genealogies/900001001/lineage/tree",
|
|
);
|
|
assert.strictEqual(requests[0].header.Authorization, "Bearer session-1");
|
|
assert.strictEqual(requests[0].timeout, 15000);
|
|
|
|
nextResponse = {
|
|
statusCode: 200,
|
|
data: {
|
|
code: 200,
|
|
data: [{
|
|
personId: 1001,
|
|
name: "重复根",
|
|
generation: 1,
|
|
children: [{ personId: 1001, name: "重复子", generation: 2 }],
|
|
}],
|
|
},
|
|
};
|
|
await assert.rejects(
|
|
appApi.getTree("900001001"),
|
|
(error) => error?.code === "LINEAGE_TREE_RESPONSE_INVALID",
|
|
);
|
|
|
|
process.stdout.write("T01-TREE-API-RUNTIME-SMOKE PASS\n");
|
|
};
|
|
|
|
run().catch((error) => {
|
|
process.stderr.write(`${error.stack || error.message}\n`);
|
|
process.exit(1);
|
|
});
|