Checkout‑Registrierung validiert jetzt die E‑Mail‑Länge, und die Checkout‑Flows sind Paddle‑only: Stripe‑Endpoints/
Services/Helpers sind entfernt, API/Frontend angepasst, Tests auf Paddle umgestellt. Außerdem wurde die CSP gestrafft und Stripe‑Texte in den Abandoned‑Checkout‑Mails ersetzt.
This commit is contained in:
20
resources/js/admin/lib/__tests__/apiError.test.ts
Normal file
20
resources/js/admin/lib/__tests__/apiError.test.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { getApiValidationMessage, ApiError } from '../apiError';
|
||||
|
||||
describe('getApiValidationMessage', () => {
|
||||
it('prefers validation errors when present', () => {
|
||||
const error = new ApiError('Fallback', 422, undefined, {
|
||||
errors: {
|
||||
event_date: ['Das Event-Datum darf nicht in der Vergangenheit liegen.'],
|
||||
},
|
||||
});
|
||||
|
||||
expect(getApiValidationMessage(error, 'Fallback')).toBe('Das Event-Datum darf nicht in der Vergangenheit liegen.');
|
||||
});
|
||||
|
||||
it('falls back to the error message when no validation errors exist', () => {
|
||||
const error = new ApiError('Server error');
|
||||
|
||||
expect(getApiValidationMessage(error, 'Fallback')).toBe('Server error');
|
||||
});
|
||||
});
|
||||
@@ -34,6 +34,17 @@ export function getApiErrorMessage(error: unknown, fallback: string): string {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
export function getApiValidationMessage(error: unknown, fallback: string): string {
|
||||
if (isApiError(error)) {
|
||||
const errors = normalizeValidationErrors(error.meta);
|
||||
if (errors.length) {
|
||||
return errors.join('\n');
|
||||
}
|
||||
}
|
||||
|
||||
return getApiErrorMessage(error, fallback);
|
||||
}
|
||||
|
||||
export type ApiErrorEventDetail = {
|
||||
message: string;
|
||||
status?: number;
|
||||
@@ -64,3 +75,18 @@ export function registerApiErrorListener(handler: (detail: ApiErrorEventDetail)
|
||||
window.addEventListener(API_ERROR_EVENT, listener as EventListener);
|
||||
return () => window.removeEventListener(API_ERROR_EVENT, listener as EventListener);
|
||||
}
|
||||
|
||||
function normalizeValidationErrors(meta?: Record<string, unknown>): string[] {
|
||||
if (!meta || typeof meta !== 'object') {
|
||||
return [];
|
||||
}
|
||||
|
||||
const errors = meta.errors;
|
||||
if (!errors || typeof errors !== 'object') {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Object.values(errors as Record<string, unknown>)
|
||||
.flatMap((value) => (Array.isArray(value) ? value : [value]))
|
||||
.filter((value): value is string => typeof value === 'string' && value.trim() !== '');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user