Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion superset-frontend/src/SqlLab/reducers/sqlLab.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,53 @@ import sqlLabReducer from 'src/SqlLab/reducers/sqlLab';
import * as actions from 'src/SqlLab/actions/sqlLab';
import type { SqlLabAction } from 'src/SqlLab/actions/sqlLab';
import type { SqlLabRootState } from 'src/SqlLab/types';
import { table, initialState as mockState } from '../fixtures';
import {
table,
databases,
initialState as mockState,
} from '../fixtures';

type SqlLabState = SqlLabRootState['sqlLab'];
const initialState = mockState.sqlLab as unknown as SqlLabState;

// eslint-disable-next-line no-restricted-globals -- TODO: Migrate from describe blocks
describe('sqlLabReducer', () => {
describe('Database actions', () => {
test('should merge databases instead of replacing existing database state', () => {
const existingDb = databases.result[0];
const incomingDb = databases.result[1];

const state = {
...initialState,
databases: {
[existingDb.id]: {
...existingDb,
extra_json: {},
},
},
};

const action = actions.setDatabases([
{
...incomingDb,
extra: '{}',
},
] as any);
Comment on lines +50 to +55

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Remove the any cast on the setDatabases payload and type it using the action creator's expected argument type (or a specific database DTO type) so the test validates real compile-time contracts. [custom_rule]

Severity Level: Minor ⚠️

Why it matters? 🤔

This is TypeScript code in a modified test file, and it uses as any on the setDatabases payload. The custom rule explicitly forbids new or modified TypeScript/TSX code from using any, so this is a real violation.

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** superset-frontend/src/SqlLab/reducers/sqlLab.test.ts
**Line:** 50:55
**Comment:**
	*Custom Rule: Remove the `any` cast on the `setDatabases` payload and type it using the action creator's expected argument type (or a specific database DTO type) so the test validates real compile-time contracts.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎


const newState = sqlLabReducer(state as any, action);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Avoid casting state to any; declare state with the proper reducer state type so the reducer call remains fully type-checked. [custom_rule]

Severity Level: Minor ⚠️

Why it matters? 🤔

This modified TypeScript test line casts state to any, which directly violates the rule against using any in new or changed TS/TSX code. The suggestion is therefore valid.

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** superset-frontend/src/SqlLab/reducers/sqlLab.test.ts
**Line:** 57:57
**Comment:**
	*Custom Rule: Avoid casting `state` to `any`; declare `state` with the proper reducer state type so the reducer call remains fully type-checked.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎


expect(newState.databases[existingDb.id]).toBeDefined();
expect(newState.databases[incomingDb.id]).toBeDefined();

expect(
newState.databases[existingDb.id].database_name,
).toBe(existingDb.database_name);

expect(
newState.databases[incomingDb.id].database_name,
).toBe(incomingDb.database_name);
});
});
// eslint-disable-next-line no-restricted-globals -- TODO: Migrate from describe blocks
describe('Query editors actions', () => {
let newState: SqlLabState;
Expand Down
8 changes: 7 additions & 1 deletion superset-frontend/src/SqlLab/reducers/sqlLab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,13 @@ export default function sqlLabReducer(
extra_json: JSON.parse(db.extra || ''),
};
});
return { ...state, databases };
return {
...state,
databases: {
...state.databases,
...databases,
},
};
},
[actions.REFRESH_QUERIES]() {
let newQueries = { ...state.queries };
Expand Down