Fix guest demo UX and enforce guest limits
This commit is contained in:
23
resources/js/guest/services/__tests__/eventApi.test.ts
Normal file
23
resources/js/guest/services/__tests__/eventApi.test.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { fetchEvent, FetchEventError } from '../eventApi';
|
||||
|
||||
describe('fetchEvent', () => {
|
||||
it('maps guest_limit_exceeded error codes', async () => {
|
||||
const originalFetch = global.fetch;
|
||||
global.fetch = vi.fn().mockResolvedValue({
|
||||
ok: false,
|
||||
status: 402,
|
||||
json: async () => ({
|
||||
error: { code: 'guest_limit_exceeded', message: 'Limit reached' },
|
||||
}),
|
||||
} as Response);
|
||||
|
||||
await expect(fetchEvent('token')).rejects.toEqual(
|
||||
expect.objectContaining<Pick<FetchEventError, 'code'>>({
|
||||
code: 'guest_limit_exceeded',
|
||||
})
|
||||
);
|
||||
|
||||
global.fetch = originalFetch;
|
||||
});
|
||||
});
|
||||
@@ -132,6 +132,7 @@ export type FetchEventErrorCode =
|
||||
| 'token_revoked'
|
||||
| 'token_rate_limited'
|
||||
| 'access_rate_limited'
|
||||
| 'guest_limit_exceeded'
|
||||
| 'gallery_expired'
|
||||
| 'event_not_public'
|
||||
| 'network_error'
|
||||
@@ -187,6 +188,7 @@ const API_ERROR_CODES: FetchEventErrorCode[] = [
|
||||
'token_revoked',
|
||||
'token_rate_limited',
|
||||
'access_rate_limited',
|
||||
'guest_limit_exceeded',
|
||||
'gallery_expired',
|
||||
'event_not_public',
|
||||
];
|
||||
@@ -221,6 +223,8 @@ function defaultMessageForCode(code: FetchEventErrorCode): string {
|
||||
return 'Zu viele Versuche in kurzer Zeit. Bitte warte einen Moment und versuche es erneut.';
|
||||
case 'access_rate_limited':
|
||||
return 'Zu viele Aufrufe in kurzer Zeit. Bitte warte einen Moment und versuche es erneut.';
|
||||
case 'guest_limit_exceeded':
|
||||
return 'Dieses Event hat sein Gäste-Limit erreicht. Bitte kontaktiere die Veranstalter:innen.';
|
||||
case 'gallery_expired':
|
||||
return 'Die Galerie ist nicht mehr verfügbar.';
|
||||
case 'event_not_public':
|
||||
@@ -237,7 +241,11 @@ function defaultMessageForCode(code: FetchEventErrorCode): string {
|
||||
|
||||
export async function fetchEvent(eventKey: string): Promise<EventData> {
|
||||
try {
|
||||
const res = await fetch(`/api/v1/events/${encodeURIComponent(eventKey)}`);
|
||||
const res = await fetch(`/api/v1/events/${encodeURIComponent(eventKey)}`, {
|
||||
headers: {
|
||||
'X-Device-Id': getDeviceId(),
|
||||
},
|
||||
});
|
||||
if (!res.ok) {
|
||||
let apiMessage: string | null = null;
|
||||
let rawCode: unknown;
|
||||
|
||||
Reference in New Issue
Block a user