完成40%
This commit is contained in:
@@ -0,0 +1,206 @@
|
||||
"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() {},
|
||||
};
|
||||
`;
|
||||
|
||||
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,
|
||||
msg: "操作成功",
|
||||
data: [
|
||||
{
|
||||
genealogyId: 900001001,
|
||||
genealogyName: "汤氏家谱",
|
||||
surname: "汤",
|
||||
ancestralHall: "敦睦堂",
|
||||
regionFullName: "河南省洛阳市",
|
||||
memberCount: 158,
|
||||
roleType: "OWNER",
|
||||
canManage: true,
|
||||
canEditContent: true,
|
||||
},
|
||||
{
|
||||
genealogyId: 900001002,
|
||||
genealogyName: "汤氏宗谱",
|
||||
regionName: "山东省济宁市",
|
||||
memberCount: 286,
|
||||
roleType: "MEMBER",
|
||||
canManage: false,
|
||||
canEditContent: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
const result = await appApi.getMyGenealogies();
|
||||
assert.deepStrictEqual(result, [
|
||||
{
|
||||
id: "900001001",
|
||||
name: "汤氏家谱",
|
||||
surname: "汤",
|
||||
hall: "敦睦堂",
|
||||
location: "河南省洛阳市",
|
||||
memberCount: 158,
|
||||
accessRole: "owner",
|
||||
canManage: true,
|
||||
canEditContent: true,
|
||||
},
|
||||
{
|
||||
id: "900001002",
|
||||
name: "汤氏宗谱",
|
||||
surname: "",
|
||||
hall: "",
|
||||
location: "山东省济宁市",
|
||||
memberCount: 286,
|
||||
accessRole: "member",
|
||||
canManage: false,
|
||||
canEditContent: false,
|
||||
},
|
||||
]);
|
||||
assert.strictEqual(requests.length, 1);
|
||||
assert.strictEqual(requests[0].url, "https://backend-api.ddxcjp.cn/genealogy/app/genealogies/mine");
|
||||
assert.strictEqual(requests[0].method, "GET");
|
||||
assert.strictEqual(requests[0].header.clientid, "client-1");
|
||||
assert.strictEqual(requests[0].header.Authorization, "Bearer session-1");
|
||||
assert.strictEqual(requests[0].timeout, 15000);
|
||||
|
||||
nextResponse = {
|
||||
statusCode: 200,
|
||||
data: {
|
||||
code: 200,
|
||||
data: [{
|
||||
genealogyId: 900001003,
|
||||
genealogyName: "只读家谱",
|
||||
memberCount: 1,
|
||||
roleType: "OWNER",
|
||||
canManage: false,
|
||||
canEditContent: false,
|
||||
}],
|
||||
},
|
||||
};
|
||||
const explicitCapabilities = await appApi.getMyGenealogies();
|
||||
assert.strictEqual(explicitCapabilities[0].accessRole, "member");
|
||||
assert.strictEqual(explicitCapabilities[0].canEditContent, false);
|
||||
|
||||
for (const invalidItem of [
|
||||
{
|
||||
genealogyId: 900001004,
|
||||
genealogyName: "缺少权限",
|
||||
memberCount: 1,
|
||||
canEditContent: false,
|
||||
},
|
||||
{
|
||||
genealogyId: 900001005,
|
||||
genealogyName: "错用人物数",
|
||||
personCount: 9,
|
||||
canManage: false,
|
||||
canEditContent: false,
|
||||
},
|
||||
]) {
|
||||
nextResponse = {
|
||||
statusCode: 200,
|
||||
data: { code: 200, data: [invalidItem] },
|
||||
};
|
||||
await assert.rejects(
|
||||
appApi.getMyGenealogies(),
|
||||
(error) => error?.code === "GENEALOGY_RESPONSE_INVALID",
|
||||
);
|
||||
}
|
||||
|
||||
nextResponse = {
|
||||
statusCode: 200,
|
||||
data: {
|
||||
code: 200,
|
||||
data: [
|
||||
{
|
||||
genealogyId: 900001006,
|
||||
genealogyName: "重复一",
|
||||
memberCount: 1,
|
||||
canManage: false,
|
||||
canEditContent: false,
|
||||
},
|
||||
{
|
||||
genealogyId: 900001006,
|
||||
genealogyName: "重复二",
|
||||
memberCount: 2,
|
||||
canManage: false,
|
||||
canEditContent: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
await assert.rejects(
|
||||
appApi.getMyGenealogies(),
|
||||
(error) => error?.code === "GENEALOGY_RESPONSE_INVALID",
|
||||
);
|
||||
|
||||
nextResponse = {
|
||||
statusCode: 200,
|
||||
data: {
|
||||
code: 200,
|
||||
data: [{ genealogyId: 9007199254740992, genealogyName: "失真家谱" }],
|
||||
},
|
||||
};
|
||||
await assert.rejects(
|
||||
appApi.getMyGenealogies(),
|
||||
(error) => error?.code === "GENEALOGY_RESPONSE_INVALID",
|
||||
);
|
||||
|
||||
process.stdout.write("G01-MY-GENEALOGIES-RUNTIME-SMOKE PASS\n");
|
||||
};
|
||||
|
||||
run().catch((error) => {
|
||||
process.stderr.write(`${error.stack || error.message}\n`);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user