83 lines
3.7 KiB
JavaScript
83 lines
3.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 = { mode: "remote", 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 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, data: [{ invitationId: "9001", inviteStatus: "PENDING" }] } };
|
|
assert.deepStrictEqual(await appApi.getCeremonyInvitations("1001", "2001"), [{ invitationId: "9001", inviteStatus: "PENDING" }]);
|
|
assert.strictEqual(requests.at(-1).url, "https://backend-api.ddxcjp.cn/genealogy/app/genealogies/1001/ceremonies/2001/invitations");
|
|
assert.strictEqual(requests.at(-1).method, "GET");
|
|
|
|
nextResponse = { statusCode: 200, data: { code: 200, data: { invitationId: "9001", inviteStatus: "ACCEPTED" } } };
|
|
await appApi.respondToCeremonyInvitation("1001", "2001", { inviteStatus: "ACCEPTED" });
|
|
assert.strictEqual(requests.at(-1).url, "https://backend-api.ddxcjp.cn/genealogy/app/genealogies/1001/ceremonies/2001/invitations/me");
|
|
assert.strictEqual(requests.at(-1).method, "PUT");
|
|
assert.deepStrictEqual(requests.at(-1).data, { inviteStatus: "ACCEPTED" });
|
|
|
|
nextResponse = { statusCode: 200, data: { code: 200, data: [] } };
|
|
await appApi.replaceCeremonyInvitees("1001", "2001", { inviteeUserIds: [] });
|
|
assert.strictEqual(requests.at(-1).url, "https://backend-api.ddxcjp.cn/genealogy/app/genealogies/1001/ceremonies/2001/invitees");
|
|
assert.deepStrictEqual(requests.at(-1).data, { inviteeUserIds: [] });
|
|
|
|
await assert.rejects(
|
|
appApi.replaceCeremonyInvitees("1001", "2001", { inviteeUserIds: [7, 7] }),
|
|
/重复标识/,
|
|
);
|
|
await assert.rejects(
|
|
appApi.replaceCeremonyInvitees("1001", "2001", { inviteeUserIds: ["2081232520259612673"] }),
|
|
(error) => error?.code === "CEREMONY_INVITEE_ID_UNSAFE",
|
|
);
|
|
|
|
nextResponse = { statusCode: 200, data: { code: 200, data: [] } };
|
|
await appApi.getMyCeremonyInvitations();
|
|
assert.strictEqual(requests.at(-1).url, "https://backend-api.ddxcjp.cn/genealogy/app/genealogies/ceremony-invitations/mine");
|
|
assert.strictEqual(requests.at(-1).method, "GET");
|
|
delete globalThis.uni;
|
|
process.stdout.write("CEREMONY-INVITATIONS-API-RUNTIME-SMOKE PASS\n");
|
|
};
|
|
|
|
run().catch((error) => {
|
|
process.stderr.write(`${error.stack || error.message}\n`);
|
|
process.exit(1);
|
|
});
|