Add reservation flow: BilletBuyer, guest checkout, Stripe payment
- Create BilletBuyer entity: event, user (nullable for guests), firstName,
lastName, email, reference (ETICKET-XXXX-XXXX-XXXX), totalHT, status,
stripeSessionId, paidAt, items (OneToMany)
- Create BilletBuyerItem entity: billet, billetName (snapshot), quantity,
unitPriceHT, line total helpers
- OrderController with full checkout flow:
- POST /evenement/{id}/commander: create order from cart JSON
- GET/POST /commande/{id}/informations: guest form (name, email)
- GET /commande/{id}/paiement: payment page with recap
- POST /commande/{id}/stripe: Stripe Checkout on connected account
with application_fee, productId, and quantities
- GET /commande/{id}/confirmation: success page
- Cart JS: POST cart data on Commander click, redirect to guest/payment
- Templates: guest form, payment page, order summary partial, success page
- Stripe payment uses organizer connected account, application_fee based
on commissionRate, existing productId when available
- Tests: BilletBuyerTest (12), BilletBuyerItemTest (6), cart.test.js (13)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest'
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest'
|
||||
import { initCart } from '../../assets/modules/cart.js'
|
||||
|
||||
function createBilletterie(billets) {
|
||||
@@ -15,7 +15,7 @@ function createBilletterie(billets) {
|
||||
`
|
||||
}
|
||||
|
||||
html += '<span id="cart-total"></span><span id="cart-count"></span><button id="cart-checkout" disabled></button></div>'
|
||||
html += '<span id="cart-total"></span><span id="cart-count"></span><button id="cart-checkout" disabled data-order-url="/order"></button></div>'
|
||||
document.body.innerHTML = html
|
||||
}
|
||||
|
||||
@@ -128,4 +128,70 @@ describe('initCart', () => {
|
||||
document.querySelector('[data-cart-minus]').click()
|
||||
expect(document.getElementById('cart-checkout').disabled).toBe(true)
|
||||
})
|
||||
|
||||
it('posts cart data on checkout click', () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue({
|
||||
json: () => Promise.resolve({ redirect: '/commande/1/informations' }),
|
||||
})
|
||||
globalThis.fetch = fetchMock
|
||||
|
||||
createBilletterie([
|
||||
{ id: 1, price: '10.00', max: 5 },
|
||||
{ id: 2, price: '20.00', max: 3 },
|
||||
])
|
||||
initCart()
|
||||
|
||||
const plusBtns = document.querySelectorAll('[data-cart-plus]')
|
||||
plusBtns[0].click()
|
||||
plusBtns[0].click()
|
||||
plusBtns[1].click()
|
||||
|
||||
document.getElementById('cart-checkout').click()
|
||||
|
||||
expect(fetchMock).toHaveBeenCalledWith('/order', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify([
|
||||
{ billetId: '1', qty: 2 },
|
||||
{ billetId: '2', qty: 1 },
|
||||
]),
|
||||
})
|
||||
})
|
||||
|
||||
it('does not post when cart is empty on checkout', () => {
|
||||
const fetchMock = vi.fn()
|
||||
globalThis.fetch = fetchMock
|
||||
|
||||
createBilletterie([{ id: 1, price: '10.00', max: 5 }])
|
||||
initCart()
|
||||
|
||||
document.getElementById('cart-checkout').disabled = false
|
||||
document.getElementById('cart-checkout').click()
|
||||
|
||||
expect(fetchMock).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('does not post without order url', () => {
|
||||
const fetchMock = vi.fn()
|
||||
globalThis.fetch = fetchMock
|
||||
|
||||
document.body.innerHTML = `
|
||||
<div id="billetterie">
|
||||
<div data-cart-item data-billet-id="1" data-price="10" data-max="5">
|
||||
<button data-cart-minus></button>
|
||||
<input data-cart-qty type="number" min="0" max="5" value="0" readonly>
|
||||
<button data-cart-plus></button>
|
||||
<span data-cart-line-total></span>
|
||||
</div>
|
||||
<span id="cart-total"></span><span id="cart-count"></span>
|
||||
<button id="cart-checkout" disabled></button>
|
||||
</div>
|
||||
`
|
||||
initCart()
|
||||
|
||||
document.querySelector('[data-cart-plus]').click()
|
||||
document.getElementById('cart-checkout').click()
|
||||
|
||||
expect(fetchMock).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user