153 lines
5.0 KiB
JavaScript
153 lines
5.0 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 = { 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 = [];
|
|
const feedResponse = {
|
|
feedId: "9001",
|
|
genealogyId: "1001",
|
|
publisherNickName: "家谱用户",
|
|
feedType: "photo",
|
|
feedContent: "family memory",
|
|
mediaOssIds: "2060000000000000001,2060000000000000002",
|
|
likedByMe: false,
|
|
likeCount: 0,
|
|
commentCount: 0,
|
|
pinned: "0",
|
|
createTime: "2026-07-27T10:00:00+08:00",
|
|
};
|
|
let response = { statusCode: 200, data: { code: 200, data: feedResponse } };
|
|
globalThis.uni = {
|
|
request(options) {
|
|
requests.push(options);
|
|
queueMicrotask(() => options.success(response));
|
|
return { abort() {} };
|
|
},
|
|
};
|
|
const { appApi } = await import(toDataModuleUrl(`${prelude}\n${moduleBody}`));
|
|
|
|
const createdFeed = await appApi.createFeed("1001", {
|
|
feedType: " photo ",
|
|
feedContent: " family memory ",
|
|
mediaOssIds: "2060000000000000001,2060000000000000002",
|
|
sortOrder: "0",
|
|
status: " 0 ",
|
|
});
|
|
assert.deepStrictEqual(createdFeed, {
|
|
id: "9001",
|
|
genealogyId: "1001",
|
|
content: "family memory",
|
|
publisher: "家谱用户",
|
|
type: "photo",
|
|
time: "2026-07-27T10:00:00+08:00",
|
|
mediaOssIds: "2060000000000000001,2060000000000000002",
|
|
likeCount: 0,
|
|
commentCount: 0,
|
|
likedByMe: false,
|
|
pinned: "0",
|
|
});
|
|
assert.deepStrictEqual(requests.at(-1).data, {
|
|
feedType: "photo",
|
|
feedContent: "family memory",
|
|
mediaOssIds: "2060000000000000001,2060000000000000002",
|
|
sortOrder: 0,
|
|
status: "0",
|
|
});
|
|
assert.strictEqual(requests.at(-1).url, "https://backend-api.ddxcjp.cn/genealogy/app/genealogies/1001/feeds");
|
|
|
|
response = { statusCode: 200, data: { code: 200, data: { ...feedResponse, feedContent: "only required" } } };
|
|
await appApi.createFeed("1001", { feedContent: "only required" });
|
|
assert.deepStrictEqual(requests.at(-1).data, { feedContent: "only required" });
|
|
await assert.rejects(
|
|
appApi.createFeed("1001", { feedContent: "bad media", mediaOssIds: "1, 2" }),
|
|
/mediaOssIds/,
|
|
);
|
|
|
|
const updatedFeed = await appApi.updateFeed("1001", "9001", { feedContent: "family memory" });
|
|
assert.strictEqual(updatedFeed.id, "9001");
|
|
assert.strictEqual(requests.at(-1).method, "PUT");
|
|
|
|
response = { statusCode: 200, data: { code: 200, data: {} } };
|
|
|
|
await appApi.createArticle("1001", {
|
|
categoryId: "900040001",
|
|
articleTitle: " title ",
|
|
articleSummary: " summary ",
|
|
coverOssId: "9007199254740993",
|
|
articleContent: " body ",
|
|
authorName: " author ",
|
|
sortOrder: "1",
|
|
status: " 0 ",
|
|
});
|
|
assert.deepStrictEqual(requests.at(-1).data, {
|
|
categoryId: 900040001,
|
|
articleTitle: "title",
|
|
articleSummary: "summary",
|
|
coverOssId: "9007199254740993",
|
|
articleContent: "body",
|
|
authorName: "author",
|
|
sortOrder: 1,
|
|
status: "0",
|
|
});
|
|
assert.strictEqual(requests.at(-1).url, "https://backend-api.ddxcjp.cn/genealogy/app/genealogies/1001/articles");
|
|
|
|
await appApi.createAlbum("1001", {
|
|
albumName: " old photos ",
|
|
albumDesc: " family album ",
|
|
coverOssId: "9007199254740993",
|
|
sortOrder: "1",
|
|
status: " 0 ",
|
|
});
|
|
assert.deepStrictEqual(requests.at(-1).data, {
|
|
albumName: "old photos",
|
|
albumDesc: "family album",
|
|
coverOssId: "9007199254740993",
|
|
sortOrder: 1,
|
|
status: "0",
|
|
});
|
|
assert.strictEqual(requests.at(-1).url, "https://backend-api.ddxcjp.cn/genealogy/app/genealogies/1001/albums");
|
|
await assert.rejects(
|
|
appApi.createAlbum("1001", { albumName: "bad id", coverOssId: 900001 }),
|
|
/OSS ID 字符串/,
|
|
);
|
|
|
|
delete globalThis.uni;
|
|
process.stdout.write("FAMILY-CREATE-API-RUNTIME-SMOKE PASS\n");
|
|
};
|
|
|
|
run().catch((error) => {
|
|
process.stderr.write(`${error.stack || error.message}\n`);
|
|
process.exit(1);
|
|
});
|