sadpandajoe commented on code in PR #36771:
URL: https://github.com/apache/superset/pull/36771#discussion_r2662938873
##########
superset-frontend/src/utils/export.test.ts:
##########
@@ -396,3 +397,53 @@ test('handles export with empty IDs array', async () => {
}),
);
});
+
+const { ensureAppRoot } = jest.requireMock('./pathUtils');
+
+const doublePrefixTestCases = [
+ {
+ name: 'subdirectory prefix',
+ appRoot: '/superset',
+ resource: 'dashboard',
+ ids: [1],
+ },
+ {
+ name: 'subdirectory prefix (dataset)',
+ appRoot: '/superset',
+ resource: 'dataset',
+ ids: [1],
+ },
+ {
+ name: 'nested prefix',
+ appRoot: '/my-app/superset',
+ resource: 'dataset',
+ ids: [1, 2],
+ },
+];
+
+test.each(doublePrefixTestCases)(
+ 'handleResourceExport endpoint should not include app prefix: $name',
+ async ({ appRoot, resource, ids }) => {
+ // Simulate real ensureAppRoot behavior: prepend the appRoot
+ (ensureAppRoot as jest.Mock).mockImplementation(
+ (path: string) => `${appRoot}${path}`,
+ );
+
+ const doneMock = jest.fn();
+ await handleResourceExport(resource, ids, doneMock);
+
+ // The endpoint passed to SupersetClient.get should NOT have the appRoot
prefix
+ // because SupersetClient.getUrl() adds it when building the full URL.
+ const expectedEndpoint =
`/api/v1/${resource}/export/?q=!(${ids.join(',')})`;
+
+ // Explicitly verify no prefix in endpoint - this will fail if
ensureAppRoot is used
+ const callArgs = (SupersetClient.get as jest.Mock).mock.calls.slice(
+ -1,
+ )[0][0];
+ expect(callArgs.endpoint).not.toContain(appRoot);
Review Comment:
The redundancy is intentional - line 443 is a "guard assertion" providing
better failure diagnostics and documentation. Line 444 is a "correctness
assertion". Both serve different purposes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]