feat: integrate token point usage v2
Some checks failed
Electron E2E / Electron E2E (macos-latest) (push) Has been cancelled
Electron E2E / Electron E2E (ubuntu-latest) (push) Has been cancelled
Electron E2E / Electron E2E (windows-latest) (push) Has been cancelled

This commit is contained in:
2026-09-06 14:24:50 +08:00
parent 9fed0cc7c4
commit 83ad10d95e
14 changed files with 907 additions and 201 deletions

View File

@@ -7,7 +7,7 @@ import {
fetchMyWorksProjects,
fetchWorksAsset,
fetchWorksAssets,
fetchWorksTokenUsage,
fetchWorksTokenPointBalance,
fetchWorksProjectVersions,
fetchWorksProjects,
publishWorksProjectSource,
@@ -212,22 +212,37 @@ describe('works square client', () => {
);
});
it('loads billing token usage with the current access token', async () => {
const usage = {
five_hour_remaining_percent: 72.5,
weekly_remaining_percent: 48,
plan_code: 'pro',
plan_name: '专业版',
it('loads the V2 token point balance with the current access token', async () => {
const points = {
plan_code: 'mastery',
plan_name: '精通',
cycle_start: '2026-09-01T00:00:00Z',
cycle_end: '2026-09-08T00:00:00Z',
next_refresh_at: '2026-09-08T00:00:00Z',
weekly_allowance: '500.00',
weekly_used: '100.00',
weekly_reserved: '25.00',
weekly_remaining: '375.00',
permanent_total: '50.00',
permanent_used: '0.00',
permanent_reserved: '0.00',
permanent_remaining: '50.00',
total_remaining: '425.00',
entitlement_source: 'self',
family_shared: false,
can_manage_membership: true,
upgrade_action: 'self_service',
shared_available: null,
};
hostApiFetchMock.mockResolvedValueOnce({ success: true, usage });
hostApiFetchMock.mockResolvedValueOnce({ success: true, points });
const result = await fetchWorksTokenUsage('access-token');
const result = await fetchWorksTokenPointBalance('access-token');
expect(result).toEqual(usage);
expect(result.plan_code).toBe('pro');
expect(result.plan_name).toBe('专业版');
expect(result).toEqual(points);
expect(result.plan_code).toBe('mastery');
expect(result.plan_name).toBe('精通');
expect(hostApiFetchMock).toHaveBeenCalledWith(
'/api/works/billing/token-usage',
'/api/works/billing/points',
{
headers: {
'X-NianCode-Access-Token': 'access-token',