stockManage.spec.js 1.98 KB
import mockRequest from "./request";
import {
	exportStockMoveTemplate,
	getStockMoveLogPage,
	importStockMove,
	listUpgradeGoodsSimple,
	moveMerchantGoodsStock,
} from "./stockManage";

jest.mock("./request", () => jest.fn(data => Promise.resolve(data)));

describe("stock move api", () => {
	beforeEach(() => {
		mockRequest.mockClear();
	});

	it("queries light-modification products for the target UID selector", async () => {
		await listUpgradeGoodsSimple({
			currentPage: 1,
			pageSize: 20,
			commodityCode: "UID",
			productType: 1,
		});
		expect(mockRequest).toHaveBeenCalledWith({
			currentPage: 1,
			pageSize: 20,
			commodityCode: "UID",
			productType: 1,
			method: "dj.api.smartcarlife.productManager.listUpgradeGoodsSimple",
		}, "post");
	});

	it("submits all identifiers required by a single stock move", async () => {
		await moveMerchantGoodsStock({
			upgradeGoodsId: 1,
			yqMerchantId: 2,
			targetUpgradeGoodsId: 3,
		});
		expect(mockRequest).toHaveBeenCalledWith({
			upgradeGoodsId: 1,
			yqMerchantId: 2,
			targetUpgradeGoodsId: 3,
			method: "dj.api.smartcarlife.MerchantGoodsStockMonthReport.stockMove",
		}, "post", [], { useResponseMessage: true });
	});

	it("uploads the batch file without including it in the signature", async () => {
		const file = { name: "stock.xlsx" };
		await importStockMove({ file });
		expect(mockRequest).toHaveBeenCalledWith({
			file,
			method: "dj.api.smartcarlife.MerchantGoodsStockMonthReport.stockMove.import",
		}, "post", ["file"]);
	});

	it("exposes template and log endpoints", async () => {
		await exportStockMoveTemplate();
		expect(mockRequest).toHaveBeenLastCalledWith({
			method: "dj.api.smartcarlife.MerchantGoodsStockMonthReport.stockMove.template.export",
		}, "post");

		await getStockMoveLogPage({ upgradeGoodsId: 1, yqMerchantId: 2 });
		expect(mockRequest).toHaveBeenLastCalledWith({
			upgradeGoodsId: 1,
			yqMerchantId: 2,
			method: "dj.api.smartcarlife.MerchantGoodsStockMonthReport.stockMove.log.page",
		}, "post");
	});
});