2026-03-21 10:12:17 +01:00
|
|
|
import { describe, it, expect, beforeEach, vi } from 'vitest'
|
|
|
|
|
import { initSortable } from '../../assets/modules/sortable.js'
|
|
|
|
|
|
|
|
|
|
function createList(reorderUrl = '/reorder') {
|
|
|
|
|
const list = document.createElement('div')
|
|
|
|
|
list.id = 'categories-list'
|
|
|
|
|
if (reorderUrl) {
|
|
|
|
|
list.dataset.reorderUrl = reorderUrl
|
|
|
|
|
}
|
|
|
|
|
document.body.appendChild(list)
|
|
|
|
|
|
|
|
|
|
return list
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function addItem(list, id) {
|
|
|
|
|
const el = document.createElement('div')
|
|
|
|
|
el.dataset.id = String(id)
|
|
|
|
|
list.appendChild(el)
|
|
|
|
|
|
|
|
|
|
return el
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function createDragEvent(type, overrides = {}) {
|
|
|
|
|
const event = new Event(type, { bubbles: true, cancelable: true })
|
|
|
|
|
event.dataTransfer = { effectAllowed: '' }
|
|
|
|
|
event.preventDefault = vi.fn()
|
|
|
|
|
Object.assign(event, overrides)
|
|
|
|
|
|
|
|
|
|
return event
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
describe('initSortable', () => {
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
document.body.innerHTML = ''
|
|
|
|
|
vi.restoreAllMocks()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('does nothing without categories-list element', () => {
|
|
|
|
|
expect(() => initSortable()).not.toThrow()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('does nothing without reorderUrl', () => {
|
|
|
|
|
const list = document.createElement('div')
|
|
|
|
|
list.id = 'categories-list'
|
|
|
|
|
document.body.appendChild(list)
|
|
|
|
|
expect(() => initSortable()).not.toThrow()
|
|
|
|
|
expect(list.querySelector('[draggable]')).toBeNull()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('sets draggable on all data-id elements', () => {
|
|
|
|
|
const list = createList()
|
|
|
|
|
addItem(list, 1)
|
|
|
|
|
addItem(list, 2)
|
|
|
|
|
|
|
|
|
|
initSortable()
|
|
|
|
|
|
|
|
|
|
list.querySelectorAll('[data-id]').forEach(el => {
|
|
|
|
|
expect(el.getAttribute('draggable')).toBe('true')
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('adds opacity-50 on dragstart', () => {
|
|
|
|
|
const list = createList()
|
|
|
|
|
const item = addItem(list, 1)
|
|
|
|
|
|
|
|
|
|
initSortable()
|
|
|
|
|
|
|
|
|
|
const event = createDragEvent('dragstart')
|
|
|
|
|
item.dispatchEvent(event)
|
|
|
|
|
|
|
|
|
|
expect(item.classList.contains('opacity-50')).toBe(true)
|
|
|
|
|
expect(event.dataTransfer.effectAllowed).toBe('move')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('dragstart does nothing when no data-id parent', () => {
|
|
|
|
|
const list = createList()
|
|
|
|
|
const child = document.createElement('span')
|
|
|
|
|
list.appendChild(child)
|
|
|
|
|
|
|
|
|
|
initSortable()
|
|
|
|
|
|
|
|
|
|
const event = createDragEvent('dragstart')
|
|
|
|
|
child.dispatchEvent(event)
|
|
|
|
|
|
|
|
|
|
expect(child.classList.contains('opacity-50')).toBe(false)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('removes opacity-50 on dragend', () => {
|
|
|
|
|
const list = createList()
|
|
|
|
|
const item = addItem(list, 1)
|
|
|
|
|
|
|
|
|
|
initSortable()
|
|
|
|
|
|
|
|
|
|
const startEvent = createDragEvent('dragstart')
|
|
|
|
|
item.dispatchEvent(startEvent)
|
|
|
|
|
expect(item.classList.contains('opacity-50')).toBe(true)
|
|
|
|
|
|
|
|
|
|
const endEvent = createDragEvent('dragend')
|
|
|
|
|
item.dispatchEvent(endEvent)
|
|
|
|
|
expect(item.classList.contains('opacity-50')).toBe(false)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('dragend does nothing when dragEl is null', () => {
|
|
|
|
|
const list = createList()
|
|
|
|
|
addItem(list, 1)
|
|
|
|
|
|
|
|
|
|
initSortable()
|
|
|
|
|
|
2026-03-21 10:22:33 +01:00
|
|
|
const item = list.querySelector('[data-id]')
|
2026-03-21 10:12:17 +01:00
|
|
|
const endEvent = createDragEvent('dragend')
|
|
|
|
|
list.dispatchEvent(endEvent)
|
2026-03-21 10:22:33 +01:00
|
|
|
expect(item.classList.contains('opacity-50')).toBe(false)
|
2026-03-21 10:12:17 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('moves element before target on dragover above midpoint', () => {
|
|
|
|
|
const list = createList()
|
|
|
|
|
const item1 = addItem(list, 1)
|
|
|
|
|
const item2 = addItem(list, 2)
|
|
|
|
|
|
|
|
|
|
initSortable()
|
|
|
|
|
|
|
|
|
|
// Start dragging item2
|
|
|
|
|
const startEvent = createDragEvent('dragstart')
|
|
|
|
|
item2.dispatchEvent(startEvent)
|
|
|
|
|
|
|
|
|
|
// Dragover item1 above midpoint
|
|
|
|
|
vi.spyOn(item1, 'getBoundingClientRect').mockReturnValue({
|
|
|
|
|
top: 100, height: 50, left: 0, right: 100, bottom: 150, width: 100,
|
|
|
|
|
})
|
|
|
|
|
const overEvent = createDragEvent('dragover', { clientY: 110 })
|
|
|
|
|
item1.dispatchEvent(overEvent)
|
|
|
|
|
|
|
|
|
|
expect(overEvent.preventDefault).toHaveBeenCalled()
|
|
|
|
|
// item2 should be before item1
|
|
|
|
|
const items = list.querySelectorAll('[data-id]')
|
|
|
|
|
expect(items[0].dataset.id).toBe('2')
|
|
|
|
|
expect(items[1].dataset.id).toBe('1')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('moves element after target on dragover below midpoint', () => {
|
|
|
|
|
const list = createList()
|
|
|
|
|
const item1 = addItem(list, 1)
|
|
|
|
|
const item2 = addItem(list, 2)
|
|
|
|
|
const item3 = addItem(list, 3)
|
|
|
|
|
|
|
|
|
|
initSortable()
|
|
|
|
|
|
|
|
|
|
// Start dragging item1
|
|
|
|
|
const startEvent = createDragEvent('dragstart')
|
|
|
|
|
item1.dispatchEvent(startEvent)
|
|
|
|
|
|
|
|
|
|
// Dragover item2 below midpoint
|
|
|
|
|
vi.spyOn(item2, 'getBoundingClientRect').mockReturnValue({
|
|
|
|
|
top: 100, height: 50, left: 0, right: 100, bottom: 150, width: 100,
|
|
|
|
|
})
|
|
|
|
|
const overEvent = createDragEvent('dragover', { clientY: 140 })
|
|
|
|
|
item2.dispatchEvent(overEvent)
|
|
|
|
|
|
|
|
|
|
// item1 should be after item2 (between item2 and item3)
|
|
|
|
|
const items = list.querySelectorAll('[data-id]')
|
|
|
|
|
expect(items[0].dataset.id).toBe('2')
|
|
|
|
|
expect(items[1].dataset.id).toBe('1')
|
|
|
|
|
expect(items[2].dataset.id).toBe('3')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('dragover does nothing when target is dragEl', () => {
|
|
|
|
|
const list = createList()
|
|
|
|
|
const item = addItem(list, 1)
|
|
|
|
|
|
|
|
|
|
initSortable()
|
|
|
|
|
|
|
|
|
|
const startEvent = createDragEvent('dragstart')
|
|
|
|
|
item.dispatchEvent(startEvent)
|
|
|
|
|
|
|
|
|
|
const overEvent = createDragEvent('dragover', { clientY: 100 })
|
|
|
|
|
item.dispatchEvent(overEvent)
|
|
|
|
|
|
|
|
|
|
// Should still just have one item, no error
|
|
|
|
|
expect(list.querySelectorAll('[data-id]').length).toBe(1)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('dragover does nothing when target has no data-id', () => {
|
|
|
|
|
const list = createList()
|
|
|
|
|
addItem(list, 1)
|
|
|
|
|
const span = document.createElement('span')
|
|
|
|
|
list.appendChild(span)
|
|
|
|
|
|
|
|
|
|
initSortable()
|
|
|
|
|
|
|
|
|
|
const startEvent = createDragEvent('dragstart')
|
|
|
|
|
list.querySelector('[data-id]').dispatchEvent(startEvent)
|
|
|
|
|
|
|
|
|
|
const overEvent = createDragEvent('dragover', { clientY: 100 })
|
|
|
|
|
span.dispatchEvent(overEvent)
|
|
|
|
|
|
|
|
|
|
expect(overEvent.preventDefault).toHaveBeenCalled()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('sends reorder request on drop', () => {
|
|
|
|
|
const fetchMock = vi.fn().mockResolvedValue({ ok: true })
|
|
|
|
|
globalThis.fetch = fetchMock
|
|
|
|
|
|
|
|
|
|
const list = createList('/api/reorder')
|
|
|
|
|
addItem(list, 3)
|
|
|
|
|
addItem(list, 1)
|
|
|
|
|
addItem(list, 2)
|
|
|
|
|
|
|
|
|
|
initSortable()
|
|
|
|
|
|
|
|
|
|
const dropEvent = createDragEvent('drop')
|
|
|
|
|
list.dispatchEvent(dropEvent)
|
|
|
|
|
|
|
|
|
|
expect(dropEvent.preventDefault).toHaveBeenCalled()
|
|
|
|
|
expect(fetchMock).toHaveBeenCalledWith('/api/reorder', {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: { 'Content-Type': 'application/json' },
|
|
|
|
|
body: JSON.stringify([3, 1, 2]),
|
|
|
|
|
})
|
|
|
|
|
})
|
2026-03-21 12:27:00 +01:00
|
|
|
|
Complete TASK_CHECKUP: security, UX, tests, coverage, accessibility, config externalization
Billetterie:
- Partial refund support (STATUS_PARTIALLY_REFUNDED, refundedAmount field, migration)
- Race condition fix: PESSIMISTIC_WRITE lock on stock decrement in transaction
- Idempotency key on PaymentIntent::create, reuse existing PI if stripeSessionId set
- Disable checkout when event ended (server 400 + template hide)
- Webhook deduplication via cache (24h TTL on stripe event.id)
- Email validation (filter_var) in OrderController guest flow
- JSON cart validation (structure check before processing)
- Invitation expiration after 7 days (isExpired method + landing page message)
- Stripe Checkout fallback when JS fails to load (noscript + redirect)
Config externalization:
- Move Stripe fees (STRIPE_FEE_RATE, STRIPE_FEE_FIXED) and admin email (ADMIN_EMAIL) to .env/services.yaml
- Replace all hardcoded contact@e-cosplay.fr across 13 files
- MailerService: getAdminEmail()/getAdminFrom(), default $from=null resolves to admin
UX & Accessibility:
- ARIA tabs: role=tablist/tab/tabpanel, aria-selected, keyboard nav (arrows, Home, End)
- aria-label on cart +/- buttons and editor toolbar buttons
- tabindex=0 on editor toolbar buttons for keyboard access
- data-confirm handler in app.js (was only in admin.js)
- Cart error feedback on checkout failure
- Billet designer save feedback (loading/success/error states)
- Stock polling every 30s with rupture/low stock badges
- Back to event link on payment page
Security:
- HTML sanitizer: BLOCKED_TAGS list (script, style, iframe, svg, etc.) - content fully removed
- Stripe polling timeout (15s max) with fallback redirect
- Rate limiting on public order access (20/5min)
- .catch() on all fetch() calls (sortable, billet-designer)
Tests (92% PHP, 100% JS lines):
- PCOV added to dev Dockerfile
- Test DB setup: .env.test with DATABASE_URL, Redis auth, Meilisearch key
- Rate limiter disabled in test env
- Makefile: test_db_setup, test_db_reset, run_test_php, run_test_coverage_php/js
- New tests: InvitationFlowTest (21), AuditServiceTest (4), ExportServiceTest (9), InvoiceServiceTest (4)
- New tests: SuspendedUserSubscriberTest, RateLimiterSubscriberTest, MeilisearchServiceTest
- New tests: Stripe webhook payment_failed (6) + charge.refunded (6)
- New tests: BilletBuyer refund, User suspended, OrganizerInvitation expiration
- JS tests: stock polling (6), data-confirm (2), copy-url restore (1), editor ARIA (2), XSS (9), tabs keyboard (9)
- ESLint + PHP CS Fixer: 0 errors
- SonarQube exclusions aligned with vitest coverage config
Infra:
- Meilisearch consistency command (app:meilisearch:check-consistency --fix) + cron daily 3am
- MeilisearchService: getAllDocumentIds(), listIndexes()
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 11:14:06 +01:00
|
|
|
it('reloads page on fetch error during drop', async () => {
|
|
|
|
|
const fetchMock = vi.fn().mockRejectedValue(new Error('Network'))
|
|
|
|
|
globalThis.fetch = fetchMock
|
|
|
|
|
const reloadMock = vi.fn()
|
|
|
|
|
globalThis.location = { reload: reloadMock }
|
|
|
|
|
|
|
|
|
|
const list = createList('/api/reorder')
|
|
|
|
|
addItem(list, 1)
|
|
|
|
|
|
|
|
|
|
initSortable()
|
|
|
|
|
|
|
|
|
|
const dropEvent = createDragEvent('drop')
|
|
|
|
|
list.dispatchEvent(dropEvent)
|
|
|
|
|
|
|
|
|
|
await new Promise(r => setTimeout(r, 10))
|
|
|
|
|
|
|
|
|
|
expect(reloadMock).toHaveBeenCalled()
|
|
|
|
|
})
|
|
|
|
|
|
2026-03-21 12:27:00 +01:00
|
|
|
it('initializes billets-list sortable', () => {
|
|
|
|
|
const list = document.createElement('div')
|
|
|
|
|
list.classList.add('billets-list')
|
|
|
|
|
list.dataset.reorderUrl = '/billet-reorder'
|
|
|
|
|
document.body.appendChild(list)
|
|
|
|
|
|
|
|
|
|
const el1 = document.createElement('div')
|
|
|
|
|
el1.dataset.billetId = '10'
|
|
|
|
|
list.appendChild(el1)
|
|
|
|
|
|
|
|
|
|
const el2 = document.createElement('div')
|
|
|
|
|
el2.dataset.billetId = '20'
|
|
|
|
|
list.appendChild(el2)
|
|
|
|
|
|
|
|
|
|
initSortable()
|
|
|
|
|
|
|
|
|
|
expect(el1.getAttribute('draggable')).toBe('true')
|
|
|
|
|
expect(el2.getAttribute('draggable')).toBe('true')
|
|
|
|
|
})
|
2026-03-21 10:12:17 +01:00
|
|
|
})
|