journalRecord.api-smoke.js 2.01 KB
/**
 * dailyReport 接口冒烟测试
 * 用法: npm run api:smoke:journal
 */
const { createLoggedInClient } = require("../src/libs/rop/ropClient");

async function main() {
	const client = await createLoggedInClient();
	console.log("axios.baseURL:", client.config.baseURL);
	console.log("axios.appkey:", client.config.appkey);
	console.log("env:", client.config.env);

	const merchantData = await client.callSmartcarlife("dailyReport.merchant.list", {
		currentPage: 1,
		pageSize: 10,
	});
	console.log("  merchant.list total:", merchantData?.total, "listLen:", merchantData?.list?.length);

	const reportDate = new Date().toISOString().slice(0, 10);
	const tabs = [
		["staffDaily", 1],
		["storeDaily", 2],
		["negotiation", 3],
	];

	let fallbackMerchantId = merchantData?.list?.[0]?.merchantId;

	for (const [tabKey, templateType] of tabs) {
		const overviewData = await client.callSmartcarlife("dailyReport.overview.page", {
			currentPage: 1,
			pageSize: 10,
			templateType,
			reportDate,
		});
		console.log(`[OK] dailyReport.overview.page (${tabKey}) total:`, overviewData?.total);
		if (!fallbackMerchantId && overviewData?.list?.[0]?.merchantId) {
			fallbackMerchantId = overviewData.list[0].merchantId;
		}
		const firstId = overviewData?.list?.[0]?.id;
		if (firstId) {
			const detailData = await client.callSmartcarlife("dailyReport.detail.select", { id: firstId });
			console.log(`  detail ${tabKey} id=${firstId} jsonContent=`, !!detailData?.jsonContent);
		}
	}

	if (fallbackMerchantId) {
		const staffData = await client.callSmartcarlife("merchant.staff.list", {
			merchantId: fallbackMerchantId,
		});
		const staffLen = Array.isArray(staffData) ? staffData.length : staffData?.list?.length;
		console.log(`[OK] merchant.staff.list merchantId=${fallbackMerchantId} len=`, staffLen);
	} else {
		console.log("[SKIP] merchant.staff.list: 无可用 merchantId");
	}

	console.log("\nAll dailyReport smoke tests passed.");
}

main().catch((error) => {
	console.error("\nSmoke test failed:", error.message);
	process.exit(1);
});