245 lines
6.5 KiB
JavaScript
245 lines
6.5 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,
|
|
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: "汤文远",
|
|
appUserId: "",
|
|
bindingMode: "NONE",
|
|
personNo: "",
|
|
aliasName: "",
|
|
generation: 12,
|
|
generationName: "文",
|
|
avatarOssId: "",
|
|
relation: "家谱成员",
|
|
branch: "文字辈",
|
|
sex: "MALE",
|
|
birthDate: "1900-01-02",
|
|
birthLunar: "",
|
|
deathDate: "",
|
|
deathLunar: "",
|
|
years: "1900-01-02—",
|
|
birthplace: "祖居地",
|
|
deathPlace: "",
|
|
burialPlace: "",
|
|
spouseNames: "",
|
|
personStatus: "ALIVE",
|
|
biography: "生平资料",
|
|
remark: "",
|
|
relationName: "",
|
|
sortOrder: null,
|
|
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.data.data.birthDate = "1900-01-02 00:00:00";
|
|
const spaceDatePerson = await appApi.getPerson("900001001", "1001");
|
|
assert.strictEqual(spaceDatePerson.birthDate, "1900-01-02");
|
|
|
|
nextResponse = {
|
|
statusCode: 200,
|
|
data: { code: 200, data: null },
|
|
};
|
|
await appApi.createPerson("900001001", {
|
|
bindingMode: "SPECIFIED",
|
|
appUserId: "3001",
|
|
personNo: "P-001",
|
|
name: "OSS头像成员",
|
|
aliasName: "阿汤",
|
|
sex: "0",
|
|
generation: 1,
|
|
generationName: "文",
|
|
fatherId: "3002",
|
|
motherId: "3003",
|
|
avatarOssId: "9007199254740993",
|
|
birthDate: "1900-01-02",
|
|
birthLunar: "0",
|
|
birthPlace: "祖居地",
|
|
deathDate: "2000-01-02",
|
|
deathLunar: "1",
|
|
deathPlace: "故乡",
|
|
burialPlace: "祖茔",
|
|
personStatus: "0",
|
|
biography: "成员简介",
|
|
remark: "测试备注",
|
|
sortOrder: "2",
|
|
relationName: "配偶",
|
|
});
|
|
assert.deepStrictEqual(requests.at(-1).data, {
|
|
bindingMode: "SPECIFIED",
|
|
appUserId: "3001",
|
|
personNo: "P-001",
|
|
name: "OSS头像成员",
|
|
aliasName: "阿汤",
|
|
sex: "0",
|
|
generation: 1,
|
|
generationName: "文",
|
|
fatherId: "3002",
|
|
motherId: "3003",
|
|
avatarOssId: "9007199254740993",
|
|
birthDate: "1900-01-02",
|
|
birthLunar: "0",
|
|
birthPlace: "祖居地",
|
|
deathDate: "2000-01-02",
|
|
deathLunar: "1",
|
|
deathPlace: "故乡",
|
|
burialPlace: "祖茔",
|
|
personStatus: "0",
|
|
biography: "成员简介",
|
|
remark: "测试备注",
|
|
sortOrder: 2,
|
|
relationName: "配偶",
|
|
});
|
|
await assert.rejects(
|
|
appApi.createPerson("900001001", {
|
|
bindingMode: "NONE",
|
|
name: "错误头像成员",
|
|
generation: 1,
|
|
avatarOssId: 9007199254740992,
|
|
}),
|
|
/OSS ID 字符串/,
|
|
);
|
|
await assert.rejects(
|
|
appApi.createPerson("900001001", {
|
|
bindingMode: "SELF",
|
|
appUserId: "3001",
|
|
name: "错误绑定成员",
|
|
}),
|
|
/SELF 身份认领不能提供业务用户标识/,
|
|
);
|
|
await assert.rejects(
|
|
appApi.createPerson("900001001", {
|
|
bindingMode: "SPECIFIED",
|
|
name: "缺少指定用户成员",
|
|
}),
|
|
/指定业务用户绑定必须提供业务用户标识/,
|
|
);
|
|
|
|
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);
|
|
});
|