admin/e2e/fixtures/consumerEventApi.ts
alisaza e1eaf5eff5 feat: initial ghabilee-admin backoffice app
Extract admin dashboard from ghabilee-frontend2 into a dedicated Next.js
app for backoffice.ghabilee.ir (no SEO indexing / Clarity).
2026-09-05 13:12:59 +03:30

153 lines
4.6 KiB
TypeScript

/**
* Shared event payloads for consumer Playwright e2e.
*
* Next SSR fetches `NEXT_PUBLIC_API_URL` (127.0.0.1:3000 in e2e) — Playwright
* `page.route` cannot intercept that. `global-setup` serves these shapes so
* `/e/:slug` and `/e/:uuid` render instead of 404.
*/
export const E2E_PAYMENT_EVENT_ID = '11111111-1111-4111-8111-111111111111'
export const E2E_PAYMENT_EVENT_SLUG = 'e2e-payment-event'
export const E2E_WAITLIST_EVENT_ID = '22222222-2222-4222-8222-222222222222'
export const E2E_WAITLIST_EVENT_SLUG = 'e2e-full-event'
export const E2E_KEEPALIVE_EVENT_ID = '33333333-3333-4333-8333-333333333333'
export const E2E_KEEPALIVE_EVENT_SLUG = 'demo-event'
const baseEvent = (overrides: Record<string, unknown> = {}) => ({
id: E2E_PAYMENT_EVENT_ID,
organizerId: 'organizer-1',
categoryId: 10,
categoryName: 'ورزشی',
cityName: 'تهران',
title: 'رویداد تست پرداخت',
slug: E2E_PAYMENT_EVENT_SLUG,
shortDescription: 'توضیح کوتاه',
description: 'توضیح کامل',
startsAt: '2030-01-01T10:00:00.000Z',
endsAt: '2030-01-01T12:00:00.000Z',
provinceId: 1,
cityId: 2,
address: 'تهران',
lat: 35.7,
lng: 51.4,
isFree: false,
price: 100_000,
capacity: 20,
bookedCount: 1,
reservedCapacity: 0,
status: 'published',
isFeatured: false,
posterUrl: null,
avgRating: null,
reviewsCount: 0,
genderRestriction: null,
ageRestriction: null,
settings: {
isDiscoverable: true,
addressVisibility: 'public' as const,
generalArea: null,
},
...overrides,
})
export const e2ePaymentEvent = (title = 'رویداد تست پرداخت') => baseEvent({ title })
export const e2eWaitlistEvent = () =>
baseEvent({
id: E2E_WAITLIST_EVENT_ID,
slug: E2E_WAITLIST_EVENT_SLUG,
title: 'رویداد تکمیل ظرفیت',
status: 'full',
capacity: 10,
bookedCount: 10,
settings: {
isDiscoverable: true,
autoCreateGroup: true,
addressVisibility: 'public',
generalArea: null,
waitlistAutoOffer: true,
},
})
export const e2eKeepAliveEvent = () =>
baseEvent({
id: E2E_KEEPALIVE_EVENT_ID,
slug: E2E_KEEPALIVE_EVENT_SLUG,
title: 'ایونت تست keep-alive',
price: 0,
isFree: true,
})
const landingOrganizer = {
id: 'organizer-1',
firstName: 'سارا',
lastName: 'احمدی',
avatarUrl: null,
gender: 'female' as const,
followersCount: 0,
pastEventsCount: 0,
contactLinks: [] as { channel: string; label: string; url: string }[],
}
export const e2eEventLandingBootstrap = (event: ReturnType<typeof baseEvent>) => ({
event,
category: { id: 10, name: 'ورزشی', slug: 'sports' },
city: { id: 2, name: 'تهران' },
media: [],
faqs: [],
organizer: landingOrganizer,
reviews: [],
reviewsTotal: 0,
})
export const e2eDiscoveryCities = [{ id: 1, provinceId: 8, name: 'تهران', slug: 'tehran' }]
export const e2eEmptyHomeFeed = {
popular: [] as unknown[],
categoryPreviews: [] as unknown[],
cityPreviews: [] as unknown[],
}
/** Resolve SSR GETs used by consumer home + event landing during Playwright. */
export function matchConsumerE2eMockGet(pathname: string): { status: number; body: unknown } | null {
if (pathname === '/api/v1/discovery/cities') {
return { status: 200, body: { success: true, data: e2eDiscoveryCities } }
}
if (pathname === '/api/v1/discovery/categories') {
return { status: 200, body: { success: true, data: [] } }
}
if (pathname === '/api/v1/discovery/home-feed') {
return { status: 200, body: { success: true, data: e2eEmptyHomeFeed } }
}
if (pathname === `/api/v1/events/by-slug/${E2E_PAYMENT_EVENT_SLUG}/bootstrap`) {
return { status: 200, body: { success: true, data: e2eEventLandingBootstrap(e2ePaymentEvent()) } }
}
if (pathname === `/api/v1/events/by-slug/${E2E_WAITLIST_EVENT_SLUG}/bootstrap`) {
return { status: 200, body: { success: true, data: e2eEventLandingBootstrap(e2eWaitlistEvent()) } }
}
if (pathname === `/api/v1/events/by-slug/${E2E_KEEPALIVE_EVENT_SLUG}/bootstrap`) {
return { status: 200, body: { success: true, data: e2eEventLandingBootstrap(e2eKeepAliveEvent()) } }
}
if (pathname === `/api/v1/events/${E2E_PAYMENT_EVENT_ID}`) {
return { status: 200, body: { success: true, data: e2ePaymentEvent() } }
}
if (pathname === `/api/v1/events/${E2E_WAITLIST_EVENT_ID}`) {
return { status: 200, body: { success: true, data: e2eWaitlistEvent() } }
}
if (pathname === `/api/v1/events/${E2E_KEEPALIVE_EVENT_ID}`) {
return { status: 200, body: { success: true, data: e2eKeepAliveEvent() } }
}
return null
}