feat: implement license platform business flows and delivery tooling
Some checks failed
Check / delivery-static (push) Has been cancelled
Check / api (push) Has been cancelled
Check / web (push) Has been cancelled

Add admin and customer interfaces, orders, signed activation and leases, protected package delivery, keyring verification, migrations, security controls, tests and deployment documentation.

Co-Authored-By: Craft Agent <agents-noreply@craft.do>
This commit is contained in:
2026-10-09 15:33:22 +08:00
parent 3ab651d3a8
commit 54c318c615
142 changed files with 11105 additions and 178 deletions

View File

@@ -0,0 +1,39 @@
import { describe, expect, it, vi, beforeEach } from 'vitest'
import { flushPromises, mount } from '@vue/test-utils'
import type { Customer, Product } from '../api'
import ElementPlus from 'element-plus'
import { defineComponent } from 'vue'
const SelectStub = defineComponent({ name:'ElSelect', props:['modelValue'], emits:['update:modelValue'], template:'<select :value="modelValue" @change="$emit(\'update:modelValue\', Number($event.target.value))"><option value="1">客户</option><option value="2">产品</option></select>' })
const calls = vi.hoisted(() => ({ listOrders:vi.fn(),getOrder:vi.fn(),createOrder:vi.fn(),confirmPayment:vi.fn(),issueOrder:vi.fn() }))
vi.mock('../orders-api', () => calls)
import OrdersPanel from './OrdersPanel.vue'
const order = {id:42,order_no:'test-order',customer_id:1,customer_name:'测试客户',product_id:2,product_name:'测试产品',amount_cents:100,currency:'CNY',status:'paid',payment_reference:'BANK-001',license_id:null}
const props: {customers: Customer[]; products: Product[]} = {customers:[{id:1,name:'测试客户',contact_email:'a@example.test',status:'active',created_at:'',updated_at:''}],products:[{id:2,code:'test',name:'测试产品',description:'',active:true,created_at:'',updated_at:''}]}
function button(wrapper:ReturnType<typeof mount>,text:string) { return wrapper.findAll('button').find(item=>item.text()===text)! }
beforeEach(()=>{vi.resetAllMocks();calls.listOrders.mockResolvedValue({data:{data:[order],meta:{total:1}}});calls.getOrder.mockResolvedValue({data:{data:order}})})
describe('OrdersPanel',()=>{
it('loads persisted orders and retrieves detail',async()=>{
const wrapper=mount(OrdersPanel,{props,global:{plugins:[ElementPlus]}});await flushPromises()
expect(wrapper.text()).toContain('test-order');expect(calls.listOrders).toHaveBeenCalledWith(1)
await button(wrapper,'详情').trigger('click');await flushPromises();expect(calls.getOrder).toHaveBeenCalledWith(42)
wrapper.unmount()
})
it('retains an unchanged create key after failure',async()=>{
calls.createOrder.mockRejectedValueOnce(new Error('network')).mockResolvedValueOnce({})
const wrapper=mount(OrdersPanel,{props,global:{plugins:[ElementPlus],stubs:{teleport:true,ElSelect:SelectStub}}});await flushPromises()
await button(wrapper,'录入订单').trigger('click');await flushPromises()
const selects=wrapper.findAllComponents({name:'ElSelect'})
selects[0]!.vm.$emit('update:modelValue',1);selects[1]!.vm.$emit('update:modelValue',2);await flushPromises()
await button(wrapper,'创建订单').trigger('click');await flushPromises()
await button(wrapper,'创建订单').trigger('click');await flushPromises()
expect(calls.createOrder).toHaveBeenCalledTimes(2)
expect(calls.createOrder.mock.calls[0]![1]).toBe(calls.createOrder.mock.calls[1]![1])
expect(calls.createOrder.mock.calls[0]![0]).toEqual({customer_id:1,product_id:2,amount_cents:100,currency:'CNY'})
wrapper.unmount()
})
it('displays loading failures',async()=>{
calls.listOrders.mockRejectedValue(new Error('订单接口失败'))
const wrapper=mount(OrdersPanel,{props,global:{plugins:[ElementPlus]}});await flushPromises()
expect(wrapper.get('[role="alert"]').text()).toBe('订单接口失败');wrapper.unmount()
})
})