| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- import test from 'node:test';
- import assert from 'node:assert/strict';
- import {
- assertAllowedMiaoguoPrice,
- buildWechatProductId,
- isMiaoguoTestUser,
- resolveConfiguredProduct
- } from '../src/api/virtualPay/virtualPayProduct.js';
- test('按内部产品编号和实际金额生成微信道具 ID', () => {
- assert.equal(buildWechatProductId(166, 100), '166_1');
- assert.equal(buildWechatProductId(166, 19900), '166_199');
- assert.equal(buildWechatProductId(166, 25800), '166_258');
- assert.equal(buildWechatProductId(205, 19900), '205_199');
- });
- test('秒过只接受已发布的三个业务价位', () => {
- assert.doesNotThrow(() => assertAllowedMiaoguoPrice(9, 100));
- assert.doesNotThrow(() => assertAllowedMiaoguoPrice(7, 19900));
- assert.doesNotThrow(() => assertAllowedMiaoguoPrice(7, 25800));
- assert.throws(() => assertAllowedMiaoguoPrice(7, 100, 8), /暂不支持/);
- assert.throws(() => assertAllowedMiaoguoPrice(9, 19900), /暂不支持/);
- });
- test('仅服务端确认的测试用户可用 1 元测试购买', () => {
- assert.equal(isMiaoguoTestUser(1), true);
- assert.equal(isMiaoguoTestUser(7), true);
- assert.equal(isMiaoguoTestUser(8), false);
- assert.equal(isMiaoguoTestUser(3089), true);
- assert.doesNotThrow(() => assertAllowedMiaoguoPrice(7, 100, 1));
- assert.doesNotThrow(() => assertAllowedMiaoguoPrice(7, 100, 3089));
- });
- test('没有显式配置时使用道具命名约定', () => {
- const product = resolveConfiguredProduct({
- products: [],
- payType: 7,
- price: 19900,
- env: 0,
- internalProductId: 166
- });
- assert.equal(product.productId, '166_199');
- assert.equal(product.resolvedGoodsPrice, 19900);
- });
- test('显式商品配置仍可覆盖默认命名规则', () => {
- const product = resolveConfiguredProduct({
- products: [{ productId: 'special_offer', payType: 7, price: 19900, goodsPrice: 25800, env: 0 }],
- payType: 7,
- price: 19900,
- env: 0,
- internalProductId: 166
- });
- assert.equal(product.productId, 'special_offer');
- assert.equal(product.resolvedGoodsPrice, 25800);
- });
- test('默认道具命名拒绝非整数元金额', () => {
- assert.throws(() => buildWechatProductId(166, 19950), /整数元/);
- });
|