feat(settings): set the Google Maps key through PLACES_API_KEY

The server already put PLACES_API_KEY ahead of the key saved in the admin
panel, but nothing said so: the variable was in no template and the admin
field kept showing a stored value that no search used.

GET /me/settings now answers env_keys, the variable behind each key the
environment sets (Google, Unsplash, Amap), and null for that key's value.
The admin field turns read-only and names the variable, Test still probes
the key a search resolves to, and a save leaves those names out so the
stored fallback survives. The variable is documented in .env.example,
docker-compose.yml, the Helm chart (as a secret) and the wiki.

Addresses discussion #1881.
This commit is contained in:
Maurice
2026-09-24 16:17:54 +02:00
parent 79cd3095e0
commit 8906b66bc8
45 changed files with 308 additions and 36 deletions
+6 -1
View File
@@ -150,6 +150,8 @@ export function buildAdminHook(overrides: Record<string, unknown> = {}): AdminHo
setAmapKey: vi.fn(),
hasMapsKey: false,
hasAmapKey: false,
// No key set by the environment unless a test says so (#1881).
keyInputProps: () => ({ disabled: false, placeholder: 'Enter key...' }),
placesProvider: 'auto',
savingPlacesProvider: false,
showKeys: {},
@@ -188,5 +190,8 @@ export function buildAdminHook(overrides: Record<string, unknown> = {}): AdminHo
handleDeleteUser: vi.fn(),
};
return { ...base, ...overrides } as unknown as AdminHook;
// Derived like the hook does, so a test that only sets mapsKey keeps its Test button.
const merged = { ...base, ...overrides };
if (!('mapsKeyTestable' in overrides)) merged.mapsKeyTestable = !!merged.mapsKey;
return merged as unknown as AdminHook;
}
@@ -1,4 +1,4 @@
// FE-MOB-ASET-001 to FE-MOB-ASET-023
// FE-MOB-ASET-001 to FE-MOB-ASET-024
import React from 'react';
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
import userEvent from '@testing-library/user-event';
@@ -234,6 +234,21 @@ describe('MAdminSettingsSection', () => {
expect(admin.handleValidateKey).toHaveBeenCalledWith('maps');
});
it('FE-MOB-ASET-024: a key the environment sets is read-only and names its variable (#1881)', async () => {
const user = userEvent.setup();
const admin = renderSettings({
keyInputProps: (field: string) =>
field === 'maps' ? { disabled: true, placeholder: 'Set via PLACES_API_KEY' } : { disabled: false, placeholder: 'Enter key...' },
mapsKeyTestable: true,
});
expect(screen.getByLabelText('Google Maps API Key')).toBeDisabled();
expect(screen.getByLabelText('Google Maps API Key')).toHaveAttribute('placeholder', 'Set via PLACES_API_KEY');
expect(screen.getByLabelText('Unsplash API Key')).toBeEnabled();
await user.click(screen.getByRole('button', { name: 'Test' }));
expect(admin.handleValidateKey).toHaveBeenCalledWith('maps');
});
it('FE-MOB-ASET-015: the validation result renders as a valid or invalid line', () => {
const { unmount } = render(
<Harness admin={buildAdminHook({ mapsKey: 'k', validation: { maps: true } })} />,