52 lines
2.7 KiB
JavaScript
52 lines
2.7 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_VERIFICATION_OPERATION = 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 responseData = [];
|
|
globalThis.uni = {
|
|
request(options) {
|
|
requests.push(options);
|
|
queueMicrotask(() => options.success({ statusCode: 200, data: { code: 200, data: responseData } }));
|
|
return { abort() {} };
|
|
},
|
|
};
|
|
const { appApi } = await import(toDataModuleUrl(`${prelude}\n${moduleBody}`));
|
|
|
|
responseData = [{ id: "help-1" }];
|
|
assert.deepStrictEqual(await appApi.getSiteArticles({ articleType: " help ", limit: "5" }), responseData);
|
|
assert.strictEqual(requests.at(-1).url, "https://backend-api.ddxcjp.cn/genealogy/app/site/articles");
|
|
assert.deepStrictEqual(requests.at(-1).data, { articleType: "help", limit: 5 });
|
|
assert.strictEqual(requests.at(-1).header.Authorization, undefined);
|
|
await assert.rejects(appApi.getSiteArticles({ limit: 0 }), /数量上限/);
|
|
|
|
responseData = { pageKey: "about" };
|
|
assert.deepStrictEqual(await appApi.getSitePage("about us"), responseData);
|
|
assert.strictEqual(requests.at(-1).url, "https://backend-api.ddxcjp.cn/genealogy/app/site/pages/about%20us");
|
|
assert.strictEqual(requests.at(-1).header.Authorization, undefined);
|
|
await assert.rejects(appApi.getSitePage(" "), /页面标识/);
|
|
|
|
delete globalThis.uni;
|
|
process.stdout.write("SITE-CONTENT-API-RUNTIME-SMOKE PASS\n");
|
|
};
|
|
|
|
run().catch((error) => {
|
|
process.stderr.write(`${error.stack || error.message}\n`);
|
|
process.exit(1);
|
|
});
|