multi-platform-concurrent.integration.test.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * Integration test for multi-platform concurrent requests
  3. *
  4. * This test validates concurrent request handling across multiple platforms
  5. * Tests MUST FAIL until implementation is complete.
  6. */
  7. import { describe, test, expect, beforeEach, jest } from '@jest/globals'
  8. // Import types that will be implemented
  9. import type { IUniversalHttpClient, HttpClientRequest, BatchResult } from '@/types/httpClientCore'
  10. describe('Multi-Platform Concurrent Requests Integration', () => {
  11. let httpClient: IUniversalHttpClient
  12. beforeEach(async () => {
  13. // This will fail until IUniversalHttpClient is implemented
  14. // eslint-disable-next-line @typescript-eslint/no-require-imports
  15. const { HttpClientCore } = require('@/core/http-client/HttpClientCore')
  16. httpClient = new HttpClientCore()
  17. // Register all platform adapters
  18. const platforms = ['pacifica', 'binance', 'aster']
  19. for (const platform of platforms) {
  20. // eslint-disable-next-line @typescript-eslint/no-require-imports
  21. const AdapterClass = require(`@/adapters/${platform}/${platform.charAt(0).toUpperCase() + platform.slice(1)}HttpAdapter`)
  22. const adapter = new AdapterClass[`${platform.charAt(0).toUpperCase() + platform.slice(1)}HttpAdapter`]({
  23. platform,
  24. baseUrl: `https://api.${platform}.com`
  25. })
  26. httpClient.registerPlatform(platform, adapter)
  27. }
  28. })
  29. test('should handle concurrent requests across multiple platforms', async () => {
  30. const requests: HttpClientRequest[] = [
  31. {
  32. platform: 'pacifica',
  33. accountId: 'pacifica-account',
  34. method: 'GET',
  35. url: '/api/v1/account/info'
  36. },
  37. {
  38. platform: 'binance',
  39. accountId: 'binance-account',
  40. method: 'GET',
  41. url: '/api/v3/account'
  42. },
  43. {
  44. platform: 'aster',
  45. accountId: 'aster-account',
  46. method: 'GET',
  47. url: '/api/balances'
  48. }
  49. ]
  50. const startTime = Date.now()
  51. const batchResult: BatchResult = await httpClient.batchRequest(requests)
  52. const duration = Date.now() - startTime
  53. expect(batchResult).toBeDefined()
  54. expect(batchResult.results).toHaveLength(3)
  55. expect(batchResult.summary.successful).toBe(3)
  56. expect(duration).toBeLessThan(500) // Should be much faster than sequential
  57. })
  58. })