18 Commits

Author SHA1 Message Date
7da99efc85 release: 1.0.11
All checks were successful
Tests / Backend - Tests skipped: 8, passed: 74
Backend Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 78.38% (551/703) * Lines of Code: 703 #### Quality Gates Summary No active quality gates.
Tests / Frontend - Lint, Tests et Build passed: 88
Frontend Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 84.57% (581/687) * Lines of Code: 687 #### Quality Gates Summary No active quality gates.
THE-TIP-TOP-MULTIBRANCH/pipeline/head This commit looks good
2026-09-20 02:18:40 +00:00
f4786e970a fix: properly cleanup turnstile on unmount
All checks were successful
Tests / Backend - Tests skipped: 8, passed: 74
Backend Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 78.38% (551/703) * Lines of Code: 703 #### Quality Gates Summary No active quality gates.
Tests / Frontend - Lint, Tests et Build passed: 88
Frontend Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 84.57% (581/687) * Lines of Code: 687 #### Quality Gates Summary No active quality gates.
THE-TIP-TOP-MULTIBRANCH/pipeline/head This commit looks good
2026-09-20 02:12:14 +00:00
d207b0221a fix: properly cleanup turnstile on unmount 2026-09-20 02:09:54 +00:00
361cf46905 fix: reload turnstile on SPA navigation
Some checks failed
Tests / Backend - Tests skipped: 8, passed: 74
Backend Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 78.66% (553/703) * Lines of Code: 703 #### Quality Gates Summary No active quality gates.
Tests / Frontend - Lint, Tests et Build passed: 83
Frontend Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 80.20% (555/692) * Lines of Code: 692 #### Quality Gates Summary No active quality gates.
THE-TIP-TOP-MULTIBRANCH/pipeline/head There was a failure building this commit
2026-09-20 01:53:31 +00:00
9492cea1a8 release: 1.0.10
All checks were successful
Tests / Backend - Tests skipped: 8, passed: 74
Backend Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 78.38% (551/703) * Lines of Code: 703 #### Quality Gates Summary No active quality gates.
Tests / Frontend - Lint, Tests et Build passed: 83
Frontend Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 80.90% (555/686) * Lines of Code: 686 #### Quality Gates Summary No active quality gates.
THE-TIP-TOP-MULTIBRANCH/pipeline/head This commit looks good
2026-09-20 01:38:42 +00:00
d56b91479f fix: prevent turnstile during prerender
All checks were successful
Tests / Backend - Tests skipped: 8, passed: 74
Backend Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 78.38% (551/703) * Lines of Code: 703 #### Quality Gates Summary No active quality gates.
Tests / Frontend - Lint, Tests et Build passed: 83
Frontend Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 80.90% (555/686) * Lines of Code: 686 #### Quality Gates Summary No active quality gates.
THE-TIP-TOP-MULTIBRANCH/pipeline/head This commit looks good
2026-09-20 01:25:06 +00:00
7c1e4cf3e2 fix: load Turnstile site key in frontend build
Some checks failed
Tests / Backend - Tests skipped: 8, passed: 74
Backend Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 78.66% (553/703) * Lines of Code: 703 #### Quality Gates Summary No active quality gates.
Tests / Frontend - Lint, Tests et Build passed: 83
Frontend Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 80.85% (553/684) * Lines of Code: 684 #### Quality Gates Summary No active quality gates.
THE-TIP-TOP-MULTIBRANCH/pipeline/head There was a failure building this commit
2026-09-20 01:07:37 +00:00
3a5eed6b96 fix: load Turnstile without onload callback
All checks were successful
Tests / Backend - Tests skipped: 8, passed: 74
Backend Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 78.38% (551/703) * Lines of Code: 703 #### Quality Gates Summary No active quality gates.
Tests / Frontend - Lint, Tests et Build passed: 83
Frontend Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 80.85% (553/684) * Lines of Code: 684 #### Quality Gates Summary No active quality gates.
THE-TIP-TOP-MULTIBRANCH/pipeline/head This commit looks good
2026-09-20 00:49:03 +00:00
e8080be405 fix: explicitly load Cloudflare Turnstile
All checks were successful
Tests / Backend - Tests skipped: 8, passed: 74
Backend Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 78.38% (551/703) * Lines of Code: 703 #### Quality Gates Summary No active quality gates.
Tests / Frontend - Lint, Tests et Build passed: 83
Frontend Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 80.85% (553/684) * Lines of Code: 684 #### Quality Gates Summary No active quality gates.
THE-TIP-TOP-MULTIBRANCH/pipeline/head This commit looks good
2026-09-20 00:43:04 +00:00
16bcbd731c fix: explicitly load Cloudflare Turnstile
Some checks reported errors
Tests / Backend - Tests skipped: 8, passed: 74
Backend Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 78.66% (553/703) * Lines of Code: 703 #### Quality Gates Summary No active quality gates.
Tests / Frontend - Lint, Tests et Build passed: 83
Frontend Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 80.85% (553/684) * Lines of Code: 684 #### Quality Gates Summary No active quality gates.
THE-TIP-TOP-MULTIBRANCH/pipeline/head Something is wrong with the build of this commit
2026-09-20 00:37:37 +00:00
246303139d release: 1.0.9
All checks were successful
Tests / Backend - Tests skipped: 8, passed: 74
THE-TIP-TOP-MULTIBRANCH/pipeline/head This commit looks good
Backend Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 78.38% (551/703) * Lines of Code: 703 #### Quality Gates Summary No active quality gates.
Tests / Frontend - Lint, Tests et Build passed: 83
Frontend Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 84.94% (547/644) * Lines of Code: 644 #### Quality Gates Summary No active quality gates.
2026-09-19 23:29:13 +00:00
82d3daf20f fix(ci): inject Turnstile site key into frontend build
All checks were successful
Tests / Backend - Tests skipped: 8, passed: 74
Backend Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 78.38% (551/703) * Lines of Code: 703 #### Quality Gates Summary No active quality gates.
Tests / Frontend - Lint, Tests et Build passed: 83
Frontend Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 84.94% (547/644) * Lines of Code: 644 #### Quality Gates Summary No active quality gates.
THE-TIP-TOP-MULTIBRANCH/pipeline/head This commit looks good
2026-09-19 23:23:18 +00:00
13584d2b0f fix: improve admin game date form on mobile
All checks were successful
Tests / Backend - Tests skipped: 8, passed: 74
Backend Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 78.38% (551/703) * Lines of Code: 703 #### Quality Gates Summary No active quality gates.
Tests / Frontend - Lint, Tests et Build passed: 83
Frontend Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 84.94% (547/644) * Lines of Code: 644 #### Quality Gates Summary No active quality gates.
THE-TIP-TOP-MULTIBRANCH/pipeline/head This commit looks good
2026-09-19 23:02:18 +00:00
1e09420705 release: 1.0.7
All checks were successful
Tests / Backend - Tests skipped: 8, passed: 74
Backend Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 78.38% (551/703) * Lines of Code: 703 #### Quality Gates Summary No active quality gates.
Tests / Frontend - Lint, Tests et Build passed: 83
Frontend Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 84.94% (547/644) * Lines of Code: 644 #### Quality Gates Summary No active quality gates.
THE-TIP-TOP-MULTIBRANCH/pipeline/head This commit looks good
2026-09-18 02:43:53 +00:00
9bf038278a fix credentials
All checks were successful
Tests / Backend - Tests skipped: 8, passed: 74
Backend Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 78.66% (553/703) * Lines of Code: 703 #### Quality Gates Summary No active quality gates.
Tests / Frontend - Lint, Tests et Build passed: 83
Frontend Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 84.94% (547/644) * Lines of Code: 644 #### Quality Gates Summary No active quality gates.
THE-TIP-TOP-MULTIBRANCH/pipeline/head This commit looks good
2026-09-18 02:39:27 +00:00
10cffd77cb fix: configure frontend prerender and Google OAuth
All checks were successful
Tests / Backend - Tests skipped: 8, passed: 74
Backend Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 78.66% (553/703) * Lines of Code: 703 #### Quality Gates Summary No active quality gates.
Tests / Frontend - Lint, Tests et Build passed: 83
Frontend Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 84.94% (547/644) * Lines of Code: 644 #### Quality Gates Summary No active quality gates.
THE-TIP-TOP-MULTIBRANCH/pipeline/head This commit looks good
2026-09-18 02:24:50 +00:00
cc495f3b87 release: promote 1.0.5 to production
All checks were successful
Tests / Backend - Tests skipped: 7, passed: 27
Backend Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 60.55% (333/550) * Lines of Code: 550 #### Quality Gates Summary No active quality gates.
Tests / Frontend - Lint, Tests et Build passed: 45
Frontend Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 86.14% (230/267) * Lines of Code: 267 #### Quality Gates Summary No active quality gates.
THE-TIP-TOP-MULTIBRANCH/pipeline/head This commit looks good
2026-08-28 09:10:03 +00:00
570f5d44f5 security: remove hardcoded admin credentials
All checks were successful
Tests / Backend - Tests skipped: 7, passed: 27
Backend Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 60.55% (333/550) * Lines of Code: 550 #### Quality Gates Summary No active quality gates.
Tests / Frontend - Lint, Tests et Build passed: 45
Frontend Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 86.14% (230/267) * Lines of Code: 267 #### Quality Gates Summary No active quality gates.
THE-TIP-TOP-MULTIBRANCH/pipeline/head This commit looks good
2026-08-28 09:00:51 +00:00
7 changed files with 290 additions and 30 deletions

12
Jenkinsfile vendored
View File

@@ -83,12 +83,17 @@ pipeline {
env.FRONTEND_API_URL = '' env.FRONTEND_API_URL = ''
env.FRONTEND_GA_ID = "" env.FRONTEND_GA_ID = ""
} }
env.TURNSTILE_SITE_KEY = sh(
script: "grep '^TURNSTILE_SITE_KEY=' /opt/furious-ducks/secrets/tiptop-mail.env | cut -d= -f2-",
returnStdout: true
).trim()
echo "Branche : ${env.BRANCH_NAME}" echo "Branche : ${env.BRANCH_NAME}"
echo "Tag Docker : ${env.IMAGE_TAG}" echo "Tag Docker : ${env.IMAGE_TAG}"
echo "Environnement : ${env.DEPLOY_ENV}" echo "Environnement : ${env.DEPLOY_ENV}"
echo "Déploiement activé : ${env.DEPLOY_ENABLED}" echo "Déploiement activé : ${env.DEPLOY_ENABLED}"
echo "API frontend : ${env.FRONTEND_API_URL}" echo "API frontend : ${env.FRONTEND_API_URL}"
echo "Turnstile : ${env.TURNSTILE_SITE_KEY ? '[SET]' : '[EMPTY]'}"
} }
} }
} }
@@ -329,6 +334,13 @@ stage('SonarQube Quality Gate') {
steps { steps {
sh ''' sh '''
set -a
. /opt/furious-ducks/secrets/tiptop-mail.env
set +a
test -n "${TURNSTILE_SITE_KEY}"
echo "Turnstile site key chargée (longueur: ${#TURNSTILE_SITE_KEY})"
docker build \ docker build \
-t "${BACKEND_IMAGE}:${IMAGE_TAG}" \ -t "${BACKEND_IMAGE}:${IMAGE_TAG}" \
backend backend

View File

@@ -42,12 +42,12 @@ services:
# Injectés par le pipeline, jamais commités. Vides, les routes de # Injectés par le pipeline, jamais commités. Vides, les routes de
# connexion externe répondent 503 sans bloquer le démarrage. # connexion externe répondent 503 sans bloquer le démarrage.
GOOGLE_CLIENT_ID: "${GOOGLE_CLIENT_ID:-}" GOOGLE_CLIENT_ID: "${GOOGLE_CLIENT_ID}"
GOOGLE_CLIENT_SECRET: "${GOOGLE_CLIENT_SECRET:-}" GOOGLE_CLIENT_SECRET: "${GOOGLE_CLIENT_SECRET}"
FACEBOOK_APP_ID: "${FACEBOOK_APP_ID:-}" FACEBOOK_APP_ID: "${FACEBOOK_APP_ID}"
FACEBOOK_APP_SECRET: "${FACEBOOK_APP_SECRET:-}" FACEBOOK_APP_SECRET: "${FACEBOOK_APP_SECRET}"
# Vide, la vérification anti-robot Turnstile est désactivée. # Vide, la vérification anti-robot Turnstile est désactivée.
TURNSTILE_SECRET_KEY: "${TURNSTILE_SECRET_KEY:-}" TURNSTILE_SECRET_KEY: "${TURNSTILE_SECRET_KEY}"
command: > command: >
sh -c " sh -c "

View File

@@ -42,12 +42,12 @@ services:
# Injectés par le pipeline, jamais commités. Vides, les routes de # Injectés par le pipeline, jamais commités. Vides, les routes de
# connexion externe répondent 503 sans bloquer le démarrage. # connexion externe répondent 503 sans bloquer le démarrage.
GOOGLE_CLIENT_ID: "${GOOGLE_CLIENT_ID:-}" GOOGLE_CLIENT_ID: "${GOOGLE_CLIENT_ID}"
GOOGLE_CLIENT_SECRET: "${GOOGLE_CLIENT_SECRET:-}" GOOGLE_CLIENT_SECRET: "${GOOGLE_CLIENT_SECRET}"
FACEBOOK_APP_ID: "${FACEBOOK_APP_ID:-}" FACEBOOK_APP_ID: "${FACEBOOK_APP_ID}"
FACEBOOK_APP_SECRET: "${FACEBOOK_APP_SECRET:-}" FACEBOOK_APP_SECRET: "${FACEBOOK_APP_SECRET}"
# Vide, la vérification anti-robot Turnstile est désactivée. # Vide, la vérification anti-robot Turnstile est désactivée.
TURNSTILE_SECRET_KEY: "${TURNSTILE_SECRET_KEY:-}" TURNSTILE_SECRET_KEY: "${TURNSTILE_SECRET_KEY}"
command: > command: >
sh -c " sh -c "

View File

@@ -42,12 +42,12 @@ services:
# Injectés par le pipeline, jamais commités. Vides, les routes de # Injectés par le pipeline, jamais commités. Vides, les routes de
# connexion externe répondent 503 sans bloquer le démarrage. # connexion externe répondent 503 sans bloquer le démarrage.
GOOGLE_CLIENT_ID: "${GOOGLE_CLIENT_ID:-}" GOOGLE_CLIENT_ID: "${GOOGLE_CLIENT_ID}"
GOOGLE_CLIENT_SECRET: "${GOOGLE_CLIENT_SECRET:-}" GOOGLE_CLIENT_SECRET: "${GOOGLE_CLIENT_SECRET}"
FACEBOOK_APP_ID: "${FACEBOOK_APP_ID:-}" FACEBOOK_APP_ID: "${FACEBOOK_APP_ID}"
FACEBOOK_APP_SECRET: "${FACEBOOK_APP_SECRET:-}" FACEBOOK_APP_SECRET: "${FACEBOOK_APP_SECRET}"
# Vide, la vérification anti-robot Turnstile est désactivée. # Vide, la vérification anti-robot Turnstile est désactivée.
TURNSTILE_SECRET_KEY: "${TURNSTILE_SECRET_KEY:-}" TURNSTILE_SECRET_KEY: "${TURNSTILE_SECRET_KEY}"
command: > command: >
sh -c " sh -c "

View File

@@ -1,19 +1,125 @@
import { Turnstile } from '@marsidev/react-turnstile' import { useEffect, useRef } from 'react'
import { CAPTCHA_ENABLED, TURNSTILE_SITE_KEY } from '../config/captcha' import { CAPTCHA_ENABLED, TURNSTILE_SITE_KEY } from '../config/captcha'
// `ref` expose reset() : un jeton Turnstile n'est valable qu'une fois, il faut const TURNSTILE_SCRIPT_ID = 'cf-turnstile-script'
// en redemander un après chaque envoi refusé. const TURNSTILE_SCRIPT_URL =
export default function Captcha({ ref, onToken }) { 'https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit'
if (!CAPTCHA_ENABLED) return null
export default function Captcha({ onToken }) {
const containerRef = useRef(null)
const widgetIdRef = useRef(null)
useEffect(() => {
if (!CAPTCHA_ENABLED || !TURNSTILE_SITE_KEY || !containerRef.current) {
return
}
let cancelled = false
let localWidgetId = null
const renderWidget = () => {
if (
cancelled ||
!containerRef.current ||
!window.turnstile
) {
return
}
// Nettoyage d'un éventuel widget précédent.
if (localWidgetId !== null) {
try {
window.turnstile.remove(localWidgetId)
} catch {
// Widget déjà supprimé.
}
localWidgetId = null
widgetIdRef.current = null
}
containerRef.current.innerHTML = ''
localWidgetId = window.turnstile.render(
containerRef.current,
{
sitekey: TURNSTILE_SITE_KEY,
language: 'fr',
size: 'flexible',
appearance: 'always',
callback: (token) => {
onToken(token)
},
'expired-callback': () => {
onToken('')
},
'error-callback': () => {
onToken('')
},
}
)
widgetIdRef.current = localWidgetId
}
const existingScript = document.getElementById(
TURNSTILE_SCRIPT_ID
)
if (window.turnstile) {
renderWidget()
} else if (existingScript) {
existingScript.addEventListener('load', renderWidget, {
once: true,
})
} else {
const script = document.createElement('script')
script.id = TURNSTILE_SCRIPT_ID
script.src = TURNSTILE_SCRIPT_URL
script.async = true
script.defer = true
script.addEventListener('load', renderWidget, {
once: true,
})
document.head.appendChild(script)
}
return () => {
cancelled = true
const widgetId =
localWidgetId !== null
? localWidgetId
: widgetIdRef.current
if (widgetId !== null && window.turnstile) {
try {
window.turnstile.remove(widgetId)
} catch {
// Widget déjà supprimé.
}
}
localWidgetId = null
widgetIdRef.current = null
}
}, [onToken])
if (!CAPTCHA_ENABLED || !TURNSTILE_SITE_KEY) {
return null
}
return ( return (
<Turnstile <div
ref={ref} ref={containerRef}
siteKey={TURNSTILE_SITE_KEY} id="turnstile-captcha"
options={{ language: 'fr', size: 'flexible' }} className="w-full min-h-[65px] flex justify-center"
onSuccess={onToken}
onExpire={() => onToken('')}
onError={() => onToken('')}
/> />
) )
} }

View File

@@ -236,8 +236,11 @@ export default function Admin() {
</span> </span>
</div> </div>
<form onSubmit={handleSaveGameSettings} className="mt-4 pt-4 border-t border-gray-200 flex flex-wrap items-end gap-3"> <form
<div className="flex-1 min-w-[220px]"> onSubmit={handleSaveGameSettings}
className="mt-4 pt-4 border-t border-gray-200 flex flex-col sm:flex-row sm:items-end gap-3"
>
<div className="w-full sm:flex-1 sm:min-w-[220px]">
<label htmlFor="game-start" className="block text-xs font-medium text-gray-700 mb-1"> <label htmlFor="game-start" className="block text-xs font-medium text-gray-700 mb-1">
{stats.gameWindow.configured ? 'Corriger la date de début' : 'Date de début du jeu-concours'} {stats.gameWindow.configured ? 'Corriger la date de début' : 'Date de début du jeu-concours'}
</label> </label>
@@ -253,7 +256,7 @@ export default function Admin() {
<button <button
type="submit" type="submit"
disabled={settingsSaving || !startDateInput} disabled={settingsSaving || !startDateInput}
className="bg-[#006B6B] hover:bg-[#005959] disabled:opacity-50 text-white font-semibold px-4 py-2 rounded-lg transition-colors text-xs sm:text-sm" className="w-full sm:w-auto bg-[#006B6B] hover:bg-[#005959] disabled:opacity-50 text-white font-semibold px-4 py-2 rounded-lg transition-colors text-xs sm:text-sm whitespace-nowrap"
> >
{settingsSaving ? 'Enregistrement…' : stats.gameWindow.configured ? 'Mettre à jour' : 'Lancer le jeu'} {settingsSaving ? 'Enregistrement…' : stats.gameWindow.configured ? 'Mettre à jour' : 'Lancer le jeu'}
</button> </button>

View File

@@ -0,0 +1,139 @@
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
import { render, cleanup, waitFor } from '@testing-library/react'
vi.mock('../../config/captcha', () => ({
CAPTCHA_ENABLED: true,
TURNSTILE_SITE_KEY: '0x4AAAAAAE0AF9mR2Y1luOeG',
}))
import Captcha from '../../components/Captcha'
describe('Captcha', () => {
let originalTurnstile
beforeEach(() => {
originalTurnstile = window.turnstile
document.head
.querySelectorAll('#cf-turnstile-script')
.forEach((script) => script.remove())
window.turnstile = undefined
})
afterEach(() => {
cleanup()
window.turnstile = originalTurnstile
vi.restoreAllMocks()
})
it('rend le widget lorsque Turnstile est déjà disponible', async () => {
const onToken = vi.fn()
window.turnstile = {
render: vi.fn((container, options) => {
options.callback('token-test')
return 'widget-1'
}),
remove: vi.fn(),
}
render(<Captcha onToken={onToken} />)
await waitFor(() => {
expect(window.turnstile.render).toHaveBeenCalled()
})
expect(onToken).toHaveBeenCalledWith('token-test')
})
it('gère expiration et erreur du widget', async () => {
const onToken = vi.fn()
let options
window.turnstile = {
render: vi.fn((container, opts) => {
options = opts
return 'widget-2'
}),
remove: vi.fn(),
}
render(<Captcha onToken={onToken} />)
await waitFor(() => {
expect(options).toBeDefined()
})
options['expired-callback']()
options['error-callback']()
expect(onToken).toHaveBeenNthCalledWith(1, '')
expect(onToken).toHaveBeenNthCalledWith(2, '')
})
it('charge Turnstile lorsque le script existe déjà', async () => {
const onToken = vi.fn()
const script = document.createElement('script')
script.id = 'cf-turnstile-script'
document.head.appendChild(script)
render(<Captcha onToken={onToken} />)
window.turnstile = {
render: vi.fn(() => 'widget-3'),
remove: vi.fn(),
}
script.dispatchEvent(new Event('load'))
await waitFor(() => {
expect(window.turnstile.render).toHaveBeenCalled()
})
})
it('supprime le widget au démontage', async () => {
const onToken = vi.fn()
const remove = vi.fn()
window.turnstile = {
render: vi.fn(() => 'widget-4'),
remove,
}
const { unmount } = render(<Captcha onToken={onToken} />)
await waitFor(() => {
expect(window.turnstile.render).toHaveBeenCalledTimes(1)
})
// Le widget est bien créé avant le démontage.
unmount()
expect(remove).toHaveBeenCalledWith('widget-4')
})
it('tolère une erreur lors de la suppression du widget', async () => {
const onToken = vi.fn()
const remove = vi.fn(() => {
throw new Error('widget déjà supprimé')
})
window.turnstile = {
render: vi.fn(() => 'widget-5'),
remove,
}
const { unmount } = render(<Captcha onToken={onToken} />)
await waitFor(() => {
expect(window.turnstile.render).toHaveBeenCalledTimes(1)
})
expect(() => unmount()).not.toThrow()
expect(remove).toHaveBeenCalledWith('widget-5')
})
})