WAPC2FLIVE 创建企微审批 POC 样件
这个提交包含在:
@@ -143,31 +143,47 @@ function fixtureNumber(targetKey, generatedAt) {
|
||||
return `WAPC2F-${targetKey}-${generatedAt.slice(0, 10).replace(/-/g, "")}`;
|
||||
}
|
||||
|
||||
function fixtureControlIds() {
|
||||
return {
|
||||
type: "Text-01",
|
||||
date: "Date-01",
|
||||
reason: "Textarea-01",
|
||||
};
|
||||
}
|
||||
|
||||
function buildTemplateControl(control, id, title, options = {}) {
|
||||
return {
|
||||
property: {
|
||||
control,
|
||||
id,
|
||||
title: localized(title),
|
||||
placeholder: localized(options.placeholder || title),
|
||||
require: options.require ? 1 : 0,
|
||||
un_print: 1,
|
||||
},
|
||||
config: options.config || {},
|
||||
};
|
||||
}
|
||||
|
||||
function dayTimestamp(generatedAt) {
|
||||
const date = new Date(`${generatedAt.slice(0, 10)}T00:00:00.000Z`);
|
||||
return String(Math.floor(date.getTime() / 1000));
|
||||
}
|
||||
|
||||
function buildTemplateFixturePayload(target, generatedAt) {
|
||||
const label = targetLabel(target.key);
|
||||
const number = fixtureNumber(target.key, generatedAt);
|
||||
const controlIds = fixtureControlIds();
|
||||
return {
|
||||
template_names: localized(`OA-POC-${label}-${generatedAt.slice(0, 10)}`),
|
||||
template_name: localized(`OA-POC-${label}-${generatedAt.slice(0, 10)}`),
|
||||
template_content: {
|
||||
controls: [
|
||||
{
|
||||
control: "Text",
|
||||
id: "fixture_type",
|
||||
title: localized("类型"),
|
||||
require: 1,
|
||||
},
|
||||
{
|
||||
control: "Date",
|
||||
id: "fixture_date",
|
||||
title: localized("日期"),
|
||||
require: 1,
|
||||
},
|
||||
{
|
||||
control: "Textarea",
|
||||
id: "fixture_reason",
|
||||
title: localized("说明"),
|
||||
require: 0,
|
||||
},
|
||||
buildTemplateControl("Text", controlIds.type, "类型", { require: true }),
|
||||
buildTemplateControl("Date", controlIds.date, "日期", {
|
||||
require: true,
|
||||
config: { date: { type: "day" } },
|
||||
}),
|
||||
buildTemplateControl("Textarea", controlIds.reason, "说明", { require: false }),
|
||||
],
|
||||
},
|
||||
fixture_marker: {
|
||||
@@ -182,39 +198,38 @@ function buildTemplateFixturePayload(target, generatedAt) {
|
||||
function buildApplyFixturePayload({ target, templateId, applicantUserId, approverUserId, generatedAt }) {
|
||||
const label = targetLabel(target.key);
|
||||
const number = fixtureNumber(target.key, generatedAt);
|
||||
const controlIds = fixtureControlIds();
|
||||
return {
|
||||
creator_userid: applicantUserId,
|
||||
template_id: templateId,
|
||||
use_template_approver: 0,
|
||||
approver: [
|
||||
{
|
||||
attr: 2,
|
||||
attr: 1,
|
||||
userid: [approverUserId],
|
||||
},
|
||||
],
|
||||
notifyer: [
|
||||
{
|
||||
userid: [approverUserId],
|
||||
},
|
||||
approverUserId,
|
||||
],
|
||||
notify_type: 1,
|
||||
apply_data: {
|
||||
contents: [
|
||||
{
|
||||
control: "Text",
|
||||
id: "fixture_type",
|
||||
id: controlIds.type,
|
||||
title: localized("类型"),
|
||||
value: { text: label },
|
||||
},
|
||||
{
|
||||
control: "Date",
|
||||
id: "fixture_date",
|
||||
id: controlIds.date,
|
||||
title: localized("日期"),
|
||||
value: { date: generatedAt.slice(0, 10) },
|
||||
value: { date: { type: "day", s_timestamp: dayTimestamp(generatedAt) } },
|
||||
},
|
||||
{
|
||||
control: "Textarea",
|
||||
id: "fixture_reason",
|
||||
id: controlIds.reason,
|
||||
title: localized("说明"),
|
||||
value: { text: `${number} low-risk dry-run fixture` },
|
||||
},
|
||||
@@ -234,7 +249,7 @@ function summarizeFixturePayload(payload, kind) {
|
||||
: payload?.apply_data?.contents || [];
|
||||
const controlTypes = {};
|
||||
for (const control of controls) {
|
||||
const key = toSafeString(control?.control || "unknown", 80) || "unknown";
|
||||
const key = toSafeString(control?.control || control?.property?.control || "unknown", 80) || "unknown";
|
||||
controlTypes[key] = (controlTypes[key] || 0) + 1;
|
||||
}
|
||||
return {
|
||||
|
||||
@@ -124,6 +124,65 @@ describe("check-wecom-approval-fixtures", () => {
|
||||
expect(report.checks.fixturePayloads).toHaveLength(2);
|
||||
});
|
||||
|
||||
it("builds create_template payload with official template_name and property controls", () => {
|
||||
const payload = buildTemplateFixturePayload(
|
||||
{ key: "leave", label: "请假" },
|
||||
"2026-05-19T10:00:00.000Z",
|
||||
);
|
||||
|
||||
expect(payload.template_names).toBeUndefined();
|
||||
expect(payload.template_name).toEqual([{ text: "OA-POC-请假-2026-05-19", lang: "zh_CN" }]);
|
||||
expect(payload.template_content.controls).toHaveLength(3);
|
||||
expect(payload.template_content.controls[0]).toMatchObject({
|
||||
property: {
|
||||
control: "Text",
|
||||
id: "Text-01",
|
||||
title: [{ text: "类型", lang: "zh_CN" }],
|
||||
placeholder: [{ text: "类型", lang: "zh_CN" }],
|
||||
require: 1,
|
||||
un_print: 1,
|
||||
},
|
||||
config: {},
|
||||
});
|
||||
expect(payload.template_content.controls[1]).toMatchObject({
|
||||
property: {
|
||||
control: "Date",
|
||||
id: "Date-01",
|
||||
},
|
||||
config: {
|
||||
date: {
|
||||
type: "day",
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("builds applyevent payload with template control ids and non-self approver", () => {
|
||||
const payload = buildApplyFixturePayload({
|
||||
target: { key: "leave", label: "请假" },
|
||||
templateId: SENSITIVE_TEMPLATE_ID,
|
||||
applicantUserId: SENSITIVE_APPLICANT_USERID,
|
||||
approverUserId: SENSITIVE_APPROVER_USERID,
|
||||
generatedAt: "2026-05-19T10:00:00.000Z",
|
||||
});
|
||||
|
||||
expect(payload.creator_userid).toBe(SENSITIVE_APPLICANT_USERID);
|
||||
expect(payload.template_id).toBe(SENSITIVE_TEMPLATE_ID);
|
||||
expect(payload.use_template_approver).toBe(0);
|
||||
expect(payload.approver).toEqual([{ attr: 1, userid: [SENSITIVE_APPROVER_USERID] }]);
|
||||
expect(payload.notifyer).toEqual([SENSITIVE_APPROVER_USERID]);
|
||||
expect(payload.apply_data.contents.map((item) => item.id)).toEqual(["Text-01", "Date-01", "Textarea-01"]);
|
||||
expect(payload.apply_data.contents[1]).toMatchObject({
|
||||
control: "Date",
|
||||
value: {
|
||||
date: {
|
||||
type: "day",
|
||||
s_timestamp: "1779148800",
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("does not write in live mode without the explicit env switch", async () => {
|
||||
const createTemplateImpl = vi.fn();
|
||||
const report = await executeApprovalFixtures(baseOptions({
|
||||
|
||||
在新工单中引用
屏蔽一个用户