|
| 1 | +/** |
| 2 | + * Copyright 2022 Redpanda Data, Inc. |
| 3 | + * |
| 4 | + * Use of this software is governed by the Business Source License |
| 5 | + * included in the file https://github.com/redpanda-data/redpanda/blob/dev/licenses/bsl.md |
| 6 | + * |
| 7 | + * As of the Change Date specified in that file, in accordance with |
| 8 | + * the Business Source License, use of this software will be governed |
| 9 | + * by the Apache License, Version 2.0 |
| 10 | + */ |
| 11 | + |
| 12 | +// This test imports app.tsx to assert its module-level transport wiring, so the |
| 13 | +// app's heavy runtime dependencies are mocked below. |
| 14 | +vi.mock('@connectrpc/connect-web', () => ({ |
| 15 | + createConnectTransport: vi.fn(() => ({ kind: 'transport' })), |
| 16 | +})); |
| 17 | + |
| 18 | +vi.mock('./config', () => ({ |
| 19 | + setup: vi.fn(() => vi.fn()), |
| 20 | + getGrpcBasePath: vi.fn(() => '/redpanda-console'), |
| 21 | + addBearerTokenInterceptor: vi.fn((next) => async (request: unknown) => await next(request)), |
| 22 | + checkExpiredLicenseInterceptor: vi.fn((next) => async (request: unknown) => await next(request)), |
| 23 | +})); |
| 24 | + |
| 25 | +vi.mock('@builder.io/sdk-react', () => ({ |
| 26 | + Content: () => null, |
| 27 | +})); |
| 28 | + |
| 29 | +vi.mock('@connectrpc/connect-query', () => ({ |
| 30 | + TransportProvider: ({ children }: { children: React.ReactNode }) => children, |
| 31 | +})); |
| 32 | + |
| 33 | +vi.mock('@redpanda-data/ui', () => ({ |
| 34 | + ChakraProvider: ({ children }: { children: React.ReactNode }) => children, |
| 35 | + redpandaToastOptions: {}, |
| 36 | +})); |
| 37 | + |
| 38 | +vi.mock('@tanstack/react-query', () => ({ |
| 39 | + QueryClientProvider: ({ children }: { children: React.ReactNode }) => children, |
| 40 | +})); |
| 41 | + |
| 42 | +vi.mock('@tanstack/react-query-devtools', () => ({ |
| 43 | + ReactQueryDevtools: () => null, |
| 44 | +})); |
| 45 | + |
| 46 | +vi.mock('@tanstack/react-router', () => ({ |
| 47 | + createRouter: vi.fn(() => ({})), |
| 48 | + RouterProvider: () => null, |
| 49 | +})); |
| 50 | + |
| 51 | +vi.mock('components/builder-io/builder-custom-components', () => ({ |
| 52 | + builderCustomComponents: [], |
| 53 | +})); |
| 54 | + |
| 55 | +vi.mock('components/constants', () => ({ |
| 56 | + BUILDER_API_KEY: 'test-key', |
| 57 | +})); |
| 58 | + |
| 59 | +vi.mock('custom-feature-flag-provider', () => ({ |
| 60 | + CustomFeatureFlagProvider: ({ children }: { children: React.ReactNode }) => children, |
| 61 | +})); |
| 62 | + |
| 63 | +vi.mock('hooks/use-developer-view', () => ({ |
| 64 | + default: () => false, |
| 65 | +})); |
| 66 | + |
| 67 | +vi.mock('protobuf-registry', () => ({ |
| 68 | + protobufRegistry: {}, |
| 69 | +})); |
| 70 | + |
| 71 | +vi.mock('query-client', () => ({ |
| 72 | + default: {}, |
| 73 | +})); |
| 74 | + |
| 75 | +vi.mock('utils/env', () => ({ |
| 76 | + getBasePath: () => '/redpanda-console', |
| 77 | +})); |
| 78 | + |
| 79 | +vi.mock('utils/redpanda-theme', () => ({ |
| 80 | + patchedRedpandaTheme: {}, |
| 81 | +})); |
| 82 | + |
| 83 | +vi.mock('./components/misc/not-found-page', () => ({ |
| 84 | + NotFoundPage: () => null, |
| 85 | +})); |
| 86 | + |
| 87 | +vi.mock('./routeTree.gen', () => ({ |
| 88 | + routeTree: {}, |
| 89 | +})); |
| 90 | + |
| 91 | +vi.mock('./state/ui', () => ({ |
| 92 | + installUISettingsSideEffects: vi.fn(() => vi.fn()), |
| 93 | +})); |
| 94 | + |
| 95 | +const importAppWithMocks = async ({ grpcBasePath = '/redpanda-console' }: { grpcBasePath?: string } = {}) => { |
| 96 | + const { getGrpcBasePath } = await import('./config'); |
| 97 | + vi.mocked(getGrpcBasePath).mockReturnValue(grpcBasePath); |
| 98 | + |
| 99 | + await import('./app'); |
| 100 | + |
| 101 | + const { createConnectTransport } = await import('@connectrpc/connect-web'); |
| 102 | + |
| 103 | + return { createConnectTransport, getGrpcBasePath }; |
| 104 | +}; |
| 105 | + |
| 106 | +describe('App dataplane transport', () => { |
| 107 | + beforeEach(() => { |
| 108 | + vi.resetModules(); |
| 109 | + vi.resetAllMocks(); |
| 110 | + }); |
| 111 | + |
| 112 | + test('uses the configured gRPC base path for Connect Query requests', async () => { |
| 113 | + const { createConnectTransport, getGrpcBasePath } = await importAppWithMocks(); |
| 114 | + |
| 115 | + expect(getGrpcBasePath).toHaveBeenCalledWith(); |
| 116 | + expect(createConnectTransport).toHaveBeenCalledWith( |
| 117 | + expect.objectContaining({ |
| 118 | + baseUrl: '/redpanda-console', |
| 119 | + }) |
| 120 | + ); |
| 121 | + }); |
| 122 | + |
| 123 | + test('keeps origin-root behavior for root-mounted deployments', async () => { |
| 124 | + const { createConnectTransport, getGrpcBasePath } = await importAppWithMocks({ grpcBasePath: '' }); |
| 125 | + |
| 126 | + expect(getGrpcBasePath).toHaveBeenCalledWith(); |
| 127 | + expect(createConnectTransport).toHaveBeenCalledWith( |
| 128 | + expect.objectContaining({ |
| 129 | + baseUrl: '', |
| 130 | + }) |
| 131 | + ); |
| 132 | + }); |
| 133 | +}); |
0 commit comments