fix(metadata): require Google Books API key (#1795)
Co-authored-by: James Ward <james@notjam.es>
This commit is contained in:
co-authored by
James Ward
parent
29ebdac19e
commit
4df58169b7
+17
-14
@@ -51,11 +51,14 @@
|
|||||||
|
|
||||||
<div class="setting-item">
|
<div class="setting-item">
|
||||||
<div class="setting-header">
|
<div class="setting-header">
|
||||||
<p-toggleswitch [(ngModel)]="googleEnabled"></p-toggleswitch>
|
<p-toggleswitch
|
||||||
|
[(ngModel)]="googleEnabled"
|
||||||
|
[disabled]="!googleApiKeyConfigured">
|
||||||
|
</p-toggleswitch>
|
||||||
<span class="setting-label">Google Books</span>
|
<span class="setting-label">Google Books</span>
|
||||||
</div>
|
</div>
|
||||||
@if (googleEnabled) {
|
<div class="setting-options">
|
||||||
<div class="setting-options">
|
@if (googleEnabled) {
|
||||||
<div class="config-field">
|
<div class="config-field">
|
||||||
<span class="config-label">{{ t('languageRestriction') }}</span>
|
<span class="config-label">{{ t('languageRestriction') }}</span>
|
||||||
<p-select
|
<p-select
|
||||||
@@ -66,18 +69,18 @@
|
|||||||
class="config-select">
|
class="config-select">
|
||||||
</p-select>
|
</p-select>
|
||||||
</div>
|
</div>
|
||||||
<div class="config-field">
|
}
|
||||||
<span class="config-label">{{ t('apiKeyOptional') }}</span>
|
<div class="config-field">
|
||||||
<p class="config-description">{{ t('googleApiDesc') }}</p>
|
<span class="config-label">{{ t('googleApiLabel') }}</span>
|
||||||
<input
|
<p class="config-description">{{ t('googleApiDesc') }}</p>
|
||||||
type="text"
|
<input
|
||||||
pInputText
|
type="text"
|
||||||
[placeholder]="t('googleApiPlaceholder')"
|
pInputText
|
||||||
[(ngModel)]="googleApiKey"
|
[placeholder]="t('googleApiPlaceholder')"
|
||||||
class="config-input"/>
|
[(ngModel)]="googleApiKey"
|
||||||
</div>
|
class="config-input"/>
|
||||||
</div>
|
</div>
|
||||||
}
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="setting-item">
|
<div class="setting-item">
|
||||||
|
|||||||
+102
-7
@@ -1,10 +1,105 @@
|
|||||||
import {describe, it} from 'vitest';
|
import {signal, type WritableSignal} from '@angular/core';
|
||||||
|
import {ComponentFixture, TestBed} from '@angular/core/testing';
|
||||||
|
import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
|
||||||
|
import {of} from 'rxjs';
|
||||||
|
|
||||||
// NOTE(frontend-seam): Real coverage here needs a seam around effect-driven settings hydration and
|
import {MessageService} from 'primeng/api';
|
||||||
// the large provider payload editor so save behavior can be asserted without coupling the spec to a
|
|
||||||
// brittle form snapshot across every provider toggle and token field.
|
import {getTranslocoModule} from '../../../../core/testing/transloco-testing';
|
||||||
describe.skip('MetadataProviderSettingsComponent', () => {
|
import {type AppSettings, AppSettingKey} from '../../../../shared/model/app-settings.model';
|
||||||
it('needs a provider-settings form seam to verify payload assembly and toggle/token interactions deterministically', () => {
|
import {AppSettingsService} from '../../../../shared/service/app-settings.service';
|
||||||
// TODO(seam): Cover applySettings, token gating, and save payload composition once the provider editor state is extracted behind a smaller adapter.
|
import {MetadataProviderSettingsComponent} from './metadata-provider-settings.component';
|
||||||
|
|
||||||
|
describe('MetadataProviderSettingsComponent', () => {
|
||||||
|
let fixture: ComponentFixture<MetadataProviderSettingsComponent>;
|
||||||
|
let component: MetadataProviderSettingsComponent;
|
||||||
|
let appSettingsSignal: WritableSignal<AppSettings | null>;
|
||||||
|
let saveSettings: ReturnType<typeof vi.fn>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
appSettingsSignal = signal<AppSettings | null>(null);
|
||||||
|
saveSettings = vi.fn(() => of(void 0));
|
||||||
|
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
imports: [MetadataProviderSettingsComponent, getTranslocoModule()],
|
||||||
|
providers: [
|
||||||
|
{
|
||||||
|
provide: AppSettingsService,
|
||||||
|
useValue: {
|
||||||
|
appSettings: appSettingsSignal,
|
||||||
|
saveSettings,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{provide: MessageService, useValue: {add: vi.fn()}},
|
||||||
|
],
|
||||||
|
}).compileComponents();
|
||||||
|
|
||||||
|
fixture = TestBed.createComponent(MetadataProviderSettingsComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
TestBed.resetTestingModule();
|
||||||
|
vi.restoreAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not hydrate Google Books as enabled without an API key', () => {
|
||||||
|
appSettingsSignal.set(buildSettings({enabled: true, apiKey: ''}));
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
expect(component.googleEnabled).toBe(false);
|
||||||
|
expect(component.googleApiKeyConfigured).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('hydrates Google Books as enabled with an API key', () => {
|
||||||
|
appSettingsSignal.set(buildSettings({enabled: true, apiKey: 'valid-key'}));
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
expect(component.googleEnabled).toBe(true);
|
||||||
|
expect(component.googleApiKeyConfigured).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('persists Google Books as enabled when an API key is configured', () => {
|
||||||
|
component.googleEnabled = true;
|
||||||
|
component.googleApiKey = ' configured-key ';
|
||||||
|
|
||||||
|
component.saveSettings();
|
||||||
|
|
||||||
|
const providerSettings = getSavedProviderSettings();
|
||||||
|
expect(providerSettings.google).toEqual({
|
||||||
|
enabled: true,
|
||||||
|
language: '',
|
||||||
|
apiKey: 'configured-key',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not persist Google Books as enabled without an API key', () => {
|
||||||
|
component.googleEnabled = true;
|
||||||
|
component.googleApiKey = '';
|
||||||
|
|
||||||
|
component.saveSettings();
|
||||||
|
|
||||||
|
expect(getSavedProviderSettings().google.enabled).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
function getSavedProviderSettings() {
|
||||||
|
const payload = saveSettings.mock.calls[0][0] as {
|
||||||
|
key: string;
|
||||||
|
newValue: {google: {enabled: boolean; language: string; apiKey: string}};
|
||||||
|
}[];
|
||||||
|
|
||||||
|
expect(payload[0].key).toBe(AppSettingKey.METADATA_PROVIDER_SETTINGS);
|
||||||
|
return payload[0].newValue;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function buildSettings(google: {enabled: boolean; apiKey: string}): AppSettings {
|
||||||
|
return {
|
||||||
|
metadataProviderSettings: {
|
||||||
|
google: {
|
||||||
|
...google,
|
||||||
|
language: '',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} as AppSettings;
|
||||||
|
}
|
||||||
|
|||||||
+6
-2
@@ -116,9 +116,9 @@ export class MetadataProviderSettingsComponent {
|
|||||||
this.amazonCookie = metadataProviderSettings?.amazon?.cookie ?? "";
|
this.amazonCookie = metadataProviderSettings?.amazon?.cookie ?? "";
|
||||||
this.selectedAmazonDomain = metadataProviderSettings?.amazon?.domain ?? 'com';
|
this.selectedAmazonDomain = metadataProviderSettings?.amazon?.domain ?? 'com';
|
||||||
this.goodreadsEnabled = metadataProviderSettings?.goodReads?.enabled ?? false;
|
this.goodreadsEnabled = metadataProviderSettings?.goodReads?.enabled ?? false;
|
||||||
this.googleEnabled = metadataProviderSettings?.google?.enabled ?? false;
|
|
||||||
this.selectedGoogleLanguage = metadataProviderSettings?.google?.language ?? '';
|
this.selectedGoogleLanguage = metadataProviderSettings?.google?.language ?? '';
|
||||||
this.googleApiKey = metadataProviderSettings?.google?.apiKey ?? '';
|
this.googleApiKey = metadataProviderSettings?.google?.apiKey ?? '';
|
||||||
|
this.googleEnabled = (metadataProviderSettings?.google?.enabled ?? false) && this.googleApiKeyConfigured;
|
||||||
this.hardcoverToken = metadataProviderSettings?.hardcover?.apiKey ?? '';
|
this.hardcoverToken = metadataProviderSettings?.hardcover?.apiKey ?? '';
|
||||||
this.hardcoverEnabled = metadataProviderSettings?.hardcover?.enabled ?? false;
|
this.hardcoverEnabled = metadataProviderSettings?.hardcover?.enabled ?? false;
|
||||||
this.comicvineEnabled = metadataProviderSettings?.comicvine?.enabled ?? false;
|
this.comicvineEnabled = metadataProviderSettings?.comicvine?.enabled ?? false;
|
||||||
@@ -141,6 +141,10 @@ export class MetadataProviderSettingsComponent {
|
|||||||
this.comicvineToken = newToken;
|
this.comicvineToken = newToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get googleApiKeyConfigured(): boolean {
|
||||||
|
return this.googleApiKey.trim().length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
saveSettings(): void {
|
saveSettings(): void {
|
||||||
const payload = [
|
const payload = [
|
||||||
{
|
{
|
||||||
@@ -157,7 +161,7 @@ export class MetadataProviderSettingsComponent {
|
|||||||
},
|
},
|
||||||
goodReads: {enabled: this.goodreadsEnabled},
|
goodReads: {enabled: this.goodreadsEnabled},
|
||||||
google: {
|
google: {
|
||||||
enabled: this.googleEnabled,
|
enabled: this.googleEnabled && this.googleApiKeyConfigured,
|
||||||
language: this.selectedGoogleLanguage,
|
language: this.selectedGoogleLanguage,
|
||||||
apiKey: this.googleApiKey.trim()
|
apiKey: this.googleApiKey.trim()
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -56,8 +56,8 @@
|
|||||||
"cookiePlaceholder": "Paste your Amazon cookie",
|
"cookiePlaceholder": "Paste your Amazon cookie",
|
||||||
"languageRestriction": "Language Restriction",
|
"languageRestriction": "Language Restriction",
|
||||||
"selectLanguage": "Select Language",
|
"selectLanguage": "Select Language",
|
||||||
"apiKeyOptional": "API Key (Optional)",
|
"googleApiLabel": "Google Books API Key",
|
||||||
"googleApiDesc": "Providing a Google Books API key increases rate limits and improves reliability.",
|
"googleApiDesc": "A Google Books API key is required to enable this provider.",
|
||||||
"googleApiPlaceholder": "Enter Google Books API key",
|
"googleApiPlaceholder": "Enter Google Books API key",
|
||||||
"apiToken": "API Token",
|
"apiToken": "API Token",
|
||||||
"hardcoverPlaceholder": "Enter Hardcover API token",
|
"hardcoverPlaceholder": "Enter Hardcover API token",
|
||||||
|
|||||||
Reference in New Issue
Block a user