first commit
This commit is contained in:
27
async-agent-lab/fixture/order-service/test/order-dto.test.js
Normal file
27
async-agent-lab/fixture/order-service/test/order-dto.test.js
Normal file
@@ -0,0 +1,27 @@
|
||||
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 { createStore } from '../src/order-store.js';
|
||||
import { createOrderApi } from '../src/order-api.js';
|
||||
|
||||
test('返回体带订单状态', () => {
|
||||
const order = transition(createOrder({ amount: 12900 }), OrderState.PAID);
|
||||
const dto = toOrderDTO(order);
|
||||
assert.equal(dto.status, 'PAID');
|
||||
assert.equal(dto.amount, 12900);
|
||||
});
|
||||
|
||||
test('GET /orders/:id 返回订单', () => {
|
||||
const store = createStore();
|
||||
const order = store.save(createOrder({ amount: 500 }));
|
||||
const api = createOrderApi(store);
|
||||
const res = api.getOrder(order.id);
|
||||
assert.equal(res.code, 200);
|
||||
assert.equal(res.data.status, 'CREATED');
|
||||
});
|
||||
|
||||
test('订单不存在返回 404', () => {
|
||||
const api = createOrderApi(createStore());
|
||||
assert.equal(api.getOrder('o_missing').code, 404);
|
||||
});
|
||||
Reference in New Issue
Block a user