Skip to content

Commit

Permalink
fix: ensure numeric values for extra metadata_cache_timeout payloads
Browse files Browse the repository at this point in the history
  • Loading branch information
kidusmakonnen committed May 28, 2024
1 parent 9ac0cf7 commit 0de095e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1739,48 +1739,48 @@ describe('dbReducer', () => {
test('it will set state to payload from extra input change when schema_cache_timeout', () => {
const action: DBReducerActionType = {
type: ActionType.ExtraInputChange,
payload: { name: 'schema_cache_timeout', value: 'bar' },
payload: { name: 'schema_cache_timeout', value: '10' },
};
const currentState = dbReducer(databaseFixture, action);

// extra should be serialized
expect(currentState).toEqual({
...databaseFixture,
extra: '{"metadata_cache_timeout":{"schema_cache_timeout":"bar"}}',
extra: '{"metadata_cache_timeout":{"schema_cache_timeout":10}}',
});
});

test('it will set state to payload from extra input change when table_cache_timeout', () => {
const action: DBReducerActionType = {
type: ActionType.ExtraInputChange,
payload: { name: 'table_cache_timeout', value: 'bar' },
payload: { name: 'table_cache_timeout', value: '10' },
};
const currentState = dbReducer(databaseFixture, action);

// extra should be serialized
expect(currentState).toEqual({
...databaseFixture,
extra: '{"metadata_cache_timeout":{"table_cache_timeout":"bar"}}',
extra: '{"metadata_cache_timeout":{"table_cache_timeout":10}}',
});
});

test('it will overwrite state to payload from extra input change when table_cache_timeout', () => {
const action: DBReducerActionType = {
type: ActionType.ExtraInputChange,
payload: { name: 'table_cache_timeout', value: 'bar' },
payload: { name: 'table_cache_timeout', value: '10' },
};
const currentState = dbReducer(
{
...databaseFixture,
extra: '{"metadata_cache_timeout":{"table_cache_timeout":"foo"}}',
extra: '{"metadata_cache_timeout":{"table_cache_timeout":5}}',
},
action,
);

// extra should be serialized
expect(currentState).toEqual({
...databaseFixture,
extra: '{"metadata_cache_timeout":{"table_cache_timeout":"bar"}}',
extra: '{"metadata_cache_timeout":{"table_cache_timeout":10}}',
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ export function dbReducer(
}),
};
case ActionType.ExtraInputChange:
// "extra" payload in state is a string
if (
action.payload.name === 'schema_cache_timeout' ||
action.payload.name === 'table_cache_timeout'
Expand All @@ -278,7 +277,7 @@ export function dbReducer(
...extraJson,
metadata_cache_timeout: {
...extraJson?.metadata_cache_timeout,
[action.payload.name]: action.payload.value,
[action.payload.name]: Number(action.payload.value),
},
}),
};
Expand Down

0 comments on commit 0de095e

Please sign in to comment.