feat(donehub): add user self endpoint handling and balance calculation logic
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user