Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): leave an emptied pool size out of the infra save
Yudhi Armyndharis91802e2b1445
diff --git a/dashboard/src/hooks/useInfraConfigForm.test.ts b/dashboard/src/hooks/useInfraConfigForm.test.tsindex cdbb40612..c16c1d7b7 100644--- a/dashboard/src/hooks/useInfraConfigForm.test.ts+++ b/dashboard/src/hooks/useInfraConfigForm.test.ts@@ -220,3 +220,22 @@ test('a refetch after the form is seeded does not overwrite an edit in progress'assert.equal(result.current.buildSavePayload().database?.host, 'edited-host');});++// parseInt('') is NaN, which JSON writes as null, and the gateway refuses a null pool size.+test('an emptied pool size is left out of the save instead of going out as null', () => {+ const { result } = renderForm({ status: RUNNING, saved: SAVED });+ rtl.act(() => result.current.updateDbConfig('poolSize', NaN));++ const sent = JSON.parse(JSON.stringify(result.current.buildSavePayload())) as { database: Record<string, unknown> };++ assert.ok(!('poolSize' in sent.database), `poolSize went out as ${JSON.stringify(sent.database.poolSize)}`);+});++// The gateway stores any non-negative integer, so a value outside the field's 1 to 50 hint is what was saved+// and goes back unchanged on a save of something else.+test('a stored pool size outside the field range is saved as stored', () => {+ const stored: SavedConfig = { ...SAVED, database: { ...SAVED.database, poolSize: 100 } };+ const { result } = renderForm({ status: RUNNING, saved: stored });++ assert.equal(result.current.buildSavePayload().database?.poolSize, 100);+});diff --git a/dashboard/src/hooks/useInfraConfigForm.ts b/dashboard/src/hooks/useInfraConfigForm.tsindex 544226160..b6bd01539 100644--- a/dashboard/src/hooks/useInfraConfigForm.ts+++ b/dashboard/src/hooks/useInfraConfigForm.ts@@ -240,9 +240,13 @@ export function useInfraConfigForm(const buildSavePayload = (): SaveConfigPayload => ({// A bundled container never receives a typed password (the field is hidden once built-in is on,// but a value typed before the toggle survives in state). '' means "unchanged" on the backend.- database: builtInToSave('database', dbConfig.builtIn)- ? { ...dbConfig, builtIn: true, password: '' }- : { ...dbConfig, builtIn: false },+ // An emptied pool size is NaN, which JSON writes as null and the backend refuses: leave it out.+ database: {+ ...dbConfig,+ builtIn: builtInToSave('database', dbConfig.builtIn),+ password: builtInToSave('database', dbConfig.builtIn) ? '' : dbConfig.password,+ poolSize: Number.isInteger(dbConfig.poolSize) ? dbConfig.poolSize : undefined,+ },// `connected` is runtime-only status, not persisted configuration. Keep it out of the// whitelisted backend DTO so a valid dashboard save cannot be rejected as an unknown field.redis: {diff --git a/dashboard/src/pages/Infrastructure.test.ts b/dashboard/src/pages/Infrastructure.test.tsindex 308b3cbf2..c70d75708 100644--- a/dashboard/src/pages/Infrastructure.test.ts+++ b/dashboard/src/pages/Infrastructure.test.ts@@ -392,6 +392,45 @@ test('editing a database field and saving PUTs the edited value in the request b});});+// Clearing the number input to type a new size leaves NaN, which JSON writes as null, and the gateway+// refuses the whole save for it.+test('a save with the pool size cleared leaves the size out instead of sending null', async () => {+ const { screen, waitFor, fireEvent } = rtl;+ resetFetchCalls();+ const { container } = renderInfrastructure();++ await screen.findByText('Database Configuration');+ await awaitConfigHydrated(container);+ const poolSize = fieldInput(container, 'Pool Size');+ fireEvent.change(poolSize, { target: { value: '' } });+ assert.equal(poolSize.value, '');+ fireEvent.click(screen.getByRole('button', { name: 'Save Configuration' }));++ await waitFor(() => {+ const call = findFetchCall('PUT', '/api/infra/config');+ assert.ok(call, 'expected a PUT to /infra/config');+ const database = (call!.body as { database: Record<string, unknown> }).database;+ assert.ok(!('poolSize' in database), `poolSize went out as ${JSON.stringify(database.poolSize)}`);+ });+});++test('a pool size typed outside the 1 to 50 the field offers is kept inside it', async () => {+ const { screen, fireEvent } = rtl;+ resetFetchCalls();+ const { container } = renderInfrastructure();++ await screen.findByText('Database Configuration');+ await awaitConfigHydrated(container);+ const poolSize = fieldInput(container, 'Pool Size');++ fireEvent.change(poolSize, { target: { value: '100' } });+ assert.equal(poolSize.value, '50');+ fireEvent.change(poolSize, { target: { value: '0' } });+ assert.equal(poolSize.value, '1');+ fireEvent.change(poolSize, { target: { value: '25' } });+ assert.equal(poolSize.value, '25');+});+test('a password typed before switching to a built-in container is not saved', async () => {const { screen, waitFor, fireEvent } = rtl;resetFetchCalls();diff --git a/dashboard/src/pages/Infrastructure.tsx b/dashboard/src/pages/Infrastructure.tsxindex 4a2a8c290..5bdc28bf5 100644--- a/dashboard/src/pages/Infrastructure.tsx+++ b/dashboard/src/pages/Infrastructure.tsx@@ -343,8 +343,16 @@ export function Infrastructure() {type="number"min="1"max="50"- value={configForm.dbConfig.poolSize}- onChange={e => configForm.updateDbConfig('poolSize', parseInt(e.target.value))}+ value={Number.isNaN(configForm.dbConfig.poolSize) ? '' : configForm.dbConfig.poolSize}+ onChange={e => {+ // An emptied field stays NaN and is left out of the save; a typed size is kept+ // inside the range the field offers.+ const size = parseInt(e.target.value);+ configForm.updateDbConfig(+ 'poolSize',+ Number.isNaN(size) ? size : Math.min(50, Math.max(1, size)),+ );+ }}/></div></div>