admin/components/events/create/cloneFromEvent.test.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

108 lines
3.0 KiB
TypeScript

import { describe, expect, it, vi } from 'vitest'
import type { CreatedEvent } from '@/services/events'
import type { EventFaq, EventMedia } from '@/services/eventDetail'
import { mapEventToWizardCloneData } from '@/components/events/create/cloneFromEvent'
vi.stubGlobal('crypto', {
randomUUID: () => 'test-uuid',
})
const baseEvent = {
id: 'evt-1',
organizerId: 'user-1',
categoryId: 3,
clonedFromEventId: null,
title: 'دورهمی هفتگی',
slug: 'weekly-meetup',
shortDescription: 'خلاصه',
description: '<p>توضیح</p>',
startsAt: '2030-06-01T10:00:00.000Z',
endsAt: '2030-06-01T12:30:00.000Z',
provinceId: 8,
cityId: 301,
address: 'تهران',
lat: 35.7,
lng: 51.4,
isFree: false,
price: 150000,
capacity: 40,
reservedCapacity: 3,
bookedCount: 5,
cancellationFeePercent: 10,
commissionPercent: null,
effectiveCommissionPercent: 7,
status: 'published',
isFeatured: false,
settings: {
isDiscoverable: true,
autoCreateGroup: true,
addressVisibility: 'public',
generalArea: null,
waitlistAutoOffer: true,
sendReviewRequestSms: false,
},
discoveryPlacements: [],
adminApprovedAt: null,
rejectionReason: null,
avgRating: null,
reviewsCount: 0,
publishedAt: '2030-01-01T00:00:00.000Z',
createdAt: '2030-01-01T00:00:00.000Z',
updatedAt: '2030-01-01T00:00:00.000Z',
posterUrl: null,
} as unknown as CreatedEvent
describe('mapEventToWizardCloneData', () => {
it('prefills wizard fields from the source event', () => {
const media: EventMedia[] = [
{
id: 'm1',
eventId: 'evt-1',
mediaType: 'image',
url: 'https://cdn.example/poster.jpg',
thumbnailUrl: null,
sortOrder: 0,
isPoster: true,
isSquarePoster: false,
createdAt: '2030-01-01T00:00:00.000Z',
},
{
id: 'm2',
eventId: 'evt-1',
mediaType: 'image',
url: 'https://cdn.example/square.jpg',
thumbnailUrl: null,
sortOrder: 1,
isPoster: false,
isSquarePoster: true,
createdAt: '2030-01-01T00:00:00.000Z',
},
]
const faqs: EventFaq[] = [
{
id: 'f1',
eventId: 'evt-1',
question: 'چه زمانی؟',
answer: 'شنبه',
sortOrder: 0,
createdAt: '2030-01-01T00:00:00.000Z',
updatedAt: '2030-01-01T00:00:00.000Z',
},
]
const result = mapEventToWizardCloneData(baseEvent, media, faqs)
expect(result.title).toBe('دورهمی هفتگی (کپی)')
expect(result.slug).toBe('weekly-meetup')
expect(result.categoryId).toBe('3')
expect(result.cityId).toBe('301')
expect(result.capacity).toBe(40)
expect(result.reservedCapacity).toBe(3)
expect(result.media).toHaveLength(2)
expect(result.media[0]?.url).toBe('https://cdn.example/poster.jpg')
expect(result.media[1]?.url).toBe('https://cdn.example/square.jpg')
expect(result.faqs).toEqual([{ id: 'test-uuid', question: 'چه زمانی؟', answer: 'شنبه' }])
})
})