first commit
This commit is contained in:
35
async-agent-lab/fixture/order-service/test/consumers.test.js
Normal file
35
async-agent-lab/fixture/order-service/test/consumers.test.js
Normal file
@@ -0,0 +1,35 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createOrder, transition, OrderState } from '../src/order.js';
|
||||
import { toOrderDTO } from '../src/order-dto.js';
|
||||
import { canRefund } from '../src/consumers/refund.js';
|
||||
import { buildNotification } from '../src/consumers/notify.js';
|
||||
import { countByStatus } from '../src/consumers/dashboard.js';
|
||||
|
||||
const dtoIn = (state) => {
|
||||
const order = createOrder({ amount: 100 });
|
||||
if (state === OrderState.SHIPPED) transition(order, OrderState.PAID);
|
||||
if (state !== OrderState.CREATED) transition(order, state);
|
||||
return toOrderDTO(order);
|
||||
};
|
||||
|
||||
test('已支付和已发货的订单可以退款', () => {
|
||||
assert.equal(canRefund(dtoIn(OrderState.PAID)), true);
|
||||
assert.equal(canRefund(dtoIn(OrderState.SHIPPED)), true);
|
||||
assert.equal(canRefund(dtoIn(OrderState.CREATED)), false);
|
||||
assert.equal(canRefund(dtoIn(OrderState.CANCELLED)), false);
|
||||
});
|
||||
|
||||
test('通知文案跟随订单状态', () => {
|
||||
assert.equal(buildNotification(dtoIn(OrderState.PAID)).text, '支付成功,等待发货');
|
||||
assert.equal(buildNotification(dtoIn(OrderState.CANCELLED)).text, '订单已取消');
|
||||
});
|
||||
|
||||
test('看板按状态计数', () => {
|
||||
const counts = countByStatus([
|
||||
dtoIn(OrderState.PAID),
|
||||
dtoIn(OrderState.PAID),
|
||||
dtoIn(OrderState.CREATED),
|
||||
]);
|
||||
assert.deepEqual(counts, { PAID: 2, CREATED: 1 });
|
||||
});
|
||||
Reference in New Issue
Block a user