feat(donehub): add user self endpoint handling and balance calculation logic

This commit is contained in:
cita
2026-03-05 12:23:45 +08:00
parent 24769706e1
commit 11fc61f4fa
4 changed files with 136 additions and 9 deletions
@@ -36,6 +36,18 @@ describe('DoneHubAdapter', () => {
return;
}
if (req.url === '/api/user/self') {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
success: true,
data: {
quota: 20_000_000,
used_quota: 30_000_000,
},
}));
return;
}
res.writeHead(404, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ error: 'not found' }));
});
@@ -73,4 +85,12 @@ describe('DoneHubAdapter', () => {
{ key: 'donehub-token-key', name: 'sys_playground', enabled: true },
]);
});
it('treats quota as remaining balance and sums used quota for total', async () => {
const adapter = new DoneHubAdapter();
const balance = await adapter.getBalance(baseUrl, 'token');
expect(balance.balance).toBe(40);
expect(balance.used).toBe(60);
expect(balance.quota).toBe(100);
});
});