test-user-consumption.js 871 B

12345678910111213141516171819202122232425262728293031323334
  1. // 测试 user-consumption 路由
  2. import { testClient } from 'hono/testing';
  3. import dataOverviewRoutes from './packages/data-overview-module-mt/src/routes/index.js';
  4. async function testRoute() {
  5. const client = testClient(dataOverviewRoutes);
  6. // 尝试调用 userConsumption 端点
  7. try {
  8. const response = await client.userConsumption.$get({
  9. query: {
  10. page: '1',
  11. limit: '10',
  12. timeRange: 'last30days'
  13. }
  14. }, {
  15. headers: {
  16. 'Authorization': 'Bearer test-token'
  17. }
  18. });
  19. console.log('Response status:', response.status);
  20. if (response.status === 401) {
  21. console.log('认证失败(预期中)');
  22. } else {
  23. const text = await response.text();
  24. console.log('Response body:', text.substring(0, 200));
  25. }
  26. } catch (error) {
  27. console.error('Error:', error);
  28. }
  29. }
  30. testRoute();