Skip to content

Commit 7a88617

Browse files
fix(frontend): use grpc base path
1 parent 6ee88a1 commit 7a88617

2 files changed

Lines changed: 138 additions & 1 deletion

File tree

frontend/src/app.test.tsx

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
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 () => {
96+
const { getGrpcBasePath } = await import('./config');
97+
98+
await import('./app');
99+
100+
const { createConnectTransport } = await import('@connectrpc/connect-web');
101+
102+
return { createConnectTransport, getGrpcBasePath };
103+
};
104+
105+
describe('App dataplane transport', () => {
106+
beforeEach(() => {
107+
vi.resetModules();
108+
vi.clearAllMocks();
109+
});
110+
111+
test('uses the configured gRPC base path for Connect Query requests', async () => {
112+
const { createConnectTransport, getGrpcBasePath } = await importAppWithMocks();
113+
114+
expect(getGrpcBasePath).toHaveBeenCalledWith();
115+
expect(createConnectTransport).toHaveBeenCalledWith(
116+
expect.objectContaining({
117+
baseUrl: '/redpanda-console',
118+
})
119+
);
120+
});
121+
122+
test('keeps origin-root behavior for root-mounted deployments', async () => {
123+
const { getGrpcBasePath } = await import('./config');
124+
vi.mocked(getGrpcBasePath).mockReturnValue('');
125+
126+
await import('./app');
127+
128+
const { createConnectTransport } = await import('@connectrpc/connect-web');
129+
130+
expect(getGrpcBasePath).toHaveBeenCalledWith();
131+
expect(createConnectTransport).toHaveBeenCalledWith(
132+
expect.objectContaining({
133+
baseUrl: '',
134+
})
135+
);
136+
});
137+
});

frontend/src/app.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ import { installUISettingsSideEffects } from './state/ui';
5555

5656
// Create transport before router so loaders can use it
5757
const dataplaneTransport = createConnectTransport({
58-
baseUrl: getGrpcBasePath(''), // Embedded mode handles the path separately.
58+
baseUrl: getGrpcBasePath(),
5959
interceptors: [addBearerTokenInterceptor, checkExpiredLicenseInterceptor],
6060
jsonOptions: {
6161
registry: protobufRegistry,

0 commit comments

Comments
 (0)