104 lines
3.8 KiB
JavaScript
104 lines
3.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 = { 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 = [];
|
|
globalThis.uni = {
|
|
request(options) {
|
|
requests.push(options);
|
|
queueMicrotask(() => options.success({ statusCode: 200, data: { code: 200, data: {} } }));
|
|
return { abort() {} };
|
|
},
|
|
};
|
|
const { appApi } = await import(toDataModuleUrl(`${prelude}\n${moduleBody}`));
|
|
const ossId = "9007199254740993";
|
|
|
|
await appApi.updateGenealogy("1001", { coverOssId: ossId });
|
|
assert.strictEqual(requests.at(-1).data.coverOssId, ossId);
|
|
await appApi.createArticle("1001", { articleTitle: "家风", articleContent: "正文", coverOssId: ossId });
|
|
assert.strictEqual(requests.at(-1).data.coverOssId, ossId);
|
|
await appApi.createAlbum("1001", { albumName: "相册", coverOssId: ossId });
|
|
assert.strictEqual(requests.at(-1).data.coverOssId, ossId);
|
|
await appApi.createAlbumPhoto("1001", "2001", { ossId });
|
|
assert.strictEqual(requests.at(-1).data.ossId, ossId);
|
|
await appApi.createVideo("1001", {
|
|
videoTitle: "清明祭祖",
|
|
videoDesc: "家族活动记录",
|
|
videoOssId: ossId,
|
|
});
|
|
assert.deepStrictEqual(requests.at(-1).data, {
|
|
videoTitle: "清明祭祖",
|
|
videoDesc: "家族活动记录",
|
|
videoOssId: ossId,
|
|
});
|
|
await appApi.createCeremony("1001", { ceremonyType: "祭祖", ceremonyTitle: "清明祭祖", coverOssId: ossId });
|
|
assert.strictEqual(requests.at(-1).data.coverOssId, ossId);
|
|
await appApi.createCeremony("1001", {
|
|
ceremonyType: "祭祖",
|
|
ceremonyTitle: "清明祭祖",
|
|
locationAddress: "北京市朝阳区测试路",
|
|
longitude: "116.4074",
|
|
latitude: "39.9042",
|
|
status: "0",
|
|
});
|
|
assert.deepStrictEqual(requests.at(-1).data, {
|
|
ceremonyType: "祭祖",
|
|
ceremonyTitle: "清明祭祖",
|
|
locationAddress: "北京市朝阳区测试路",
|
|
longitude: 116.4074,
|
|
latitude: 39.9042,
|
|
status: "0",
|
|
});
|
|
await assert.rejects(
|
|
appApi.createCeremony("1001", { ceremonyType: "祭祖", ceremonyTitle: "清明祭祖", longitude: 116.4074 }),
|
|
/longitude 和 latitude 必须同时提供/,
|
|
);
|
|
|
|
await assert.rejects(
|
|
appApi.createAlbumPhoto("1001", "2001", { ossId: 900001 }),
|
|
/OSS ID 字符串/,
|
|
);
|
|
await assert.rejects(
|
|
appApi.createVideo("1001", { videoTitle: "测试视频", videoOssId: 900001 }),
|
|
/OSS ID 字符串/,
|
|
);
|
|
|
|
delete globalThis.uni;
|
|
process.stdout.write("OSS-ID-PAYLOAD-API-RUNTIME-SMOKE PASS\n");
|
|
};
|
|
|
|
run().catch((error) => {
|
|
process.stderr.write(`${error.stack || error.message}\n`);
|
|
process.exit(1);
|
|
});
|