feat: localize license states and restore revoked licenses
Co-Authored-By: Craft Agent <agents-noreply@craft.do>
This commit is contained in:
@@ -27,6 +27,7 @@ export async function setInstanceFrozen(instanceID:string,frozen:boolean,key:str
|
||||
export async function listLicenseInstances(id:number) { return api.get<{data:LicenseInstance[]}>(`/licenses/${id}/instances`) }
|
||||
export async function getLicense(id:number) { return api.get<{data:License}>(`/licenses/${id}`) }
|
||||
export async function deleteLicense(id:number) { return api.delete(`/licenses/${id}`) }
|
||||
export async function restoreLicense(id:number,idempotencyKey:string) { return api.post(`/licenses/${id}/restore`,{}, {headers:{'Idempotency-Key':idempotencyKey}}) }
|
||||
export async function revokeLicense(id:number,idempotencyKey:string) { return api.post(`/licenses/${id}/revoke`,{}, {headers:{'Idempotency-Key':idempotencyKey}}) }
|
||||
export async function renewLicense(id:number,expires_at:string,idempotencyKey:string) { return api.post(`/licenses/${id}/renew`,{expires_at},{headers:{'Idempotency-Key':idempotencyKey}}) }
|
||||
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { flushPromises, mount } from '@vue/test-utils'
|
||||
import { defineComponent } from 'vue'
|
||||
const confirmation = vi.hoisted(() => vi.fn())
|
||||
vi.mock('element-plus', () => ({ ElMessage: { success:vi.fn(), error:vi.fn() }, ElMessageBox: { confirm:confirmation } }))
|
||||
|
||||
const routeState = vi.hoisted(() => ({meta:{view:'licenses'},query:{}}))
|
||||
const routerMock = vi.hoisted(() => ({push:vi.fn(),replace:vi.fn()}))
|
||||
vi.mock('vue-router', () => ({useRoute:()=>routeState,useRouter:()=>routerMock}))
|
||||
const health = vi.hoisted(() => ({ checkApiHealth: vi.fn() }))
|
||||
vi.mock('../api-health', () => health)
|
||||
const business = vi.hoisted(() => ({ me: vi.fn(), listCustomers: vi.fn(), listProducts: vi.fn(), listLicenses: vi.fn(), issueLicense: vi.fn(), renewLicense: vi.fn(), listLicenseInstances: vi.fn() }))
|
||||
const business = vi.hoisted(() => ({ me: vi.fn(), listCustomers: vi.fn(), listProducts: vi.fn(), listLicenses: vi.fn(), issueLicense: vi.fn(), renewLicense: vi.fn(), restoreLicense:vi.fn(), listLicenseInstances: vi.fn() }))
|
||||
vi.mock('../api', () => business)
|
||||
const settingsApi = vi.hoisted(() => ({ getSettings: vi.fn() }))
|
||||
vi.mock('../admin-api', () => settingsApi)
|
||||
@@ -25,6 +27,28 @@ const ButtonStub = defineComponent({
|
||||
})
|
||||
|
||||
describe('Overview API status', () => {
|
||||
it('shows Chinese revoked status and restores with the same key on retry', async () => {
|
||||
routeState.meta.view = 'licenses'
|
||||
health.checkApiHealth.mockResolvedValue('online')
|
||||
business.me.mockResolvedValue({data:{data:{username:'admin'}}})
|
||||
business.listCustomers.mockResolvedValue({data:{data:[],meta:{total:0}}})
|
||||
business.listProducts.mockResolvedValue({data:{data:[]}})
|
||||
const row = {id:7,status:'revoked',expires_at:'2027-01-01T00:00:00Z'}
|
||||
business.listLicenses.mockResolvedValue({data:{data:[row],meta:{total:1}}})
|
||||
confirmation.mockResolvedValue(true)
|
||||
business.restoreLicense.mockRejectedValueOnce(new Error('网络错误')).mockResolvedValueOnce({})
|
||||
const Column = defineComponent({props:['label'],setup:()=>({row}),template:'<div v-if="label===\'状态\'||label===\'操作\'"><slot :row="row" /></div>'})
|
||||
const wrapper = mount(Overview,{global:{stubs:{'router-link':true,'el-button':ButtonStub,'el-table':TableStub,'el-table-column':Column,'el-dialog':true,'el-drawer':true,'el-input':true,'el-form':true,'el-select':true,'el-option':true,'el-date-picker':true,'el-pagination':true},directives:{loading:()=>{}}}})
|
||||
await flushPromises()
|
||||
expect(wrapper.text()).toContain('已撤销')
|
||||
const restore = wrapper.findAll('button').find(b=>b.text()==='恢复授权')!
|
||||
await restore.trigger('click'); await flushPromises()
|
||||
const key=business.restoreLicense.mock.calls[0][1]
|
||||
await restore.trigger('click'); await flushPromises()
|
||||
expect(business.restoreLicense).toHaveBeenLastCalledWith(7,key)
|
||||
expect(confirmation.mock.calls[0][0]).toContain('原有效期')
|
||||
wrapper.unmount()
|
||||
})
|
||||
it('renews using a date picker, validates dates and reuses the key on retry', async () => {
|
||||
routeState.meta.view = 'licenses'
|
||||
health.checkApiHealth.mockResolvedValue('online')
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user