Audit qualité : corrections de bugs, nettoyage, lint 0 erreur, tests #4

Merged
cedric merged 20 commits from fix/audit-2026-07-04 into master 2026-07-04 17:01:35 +00:00
2 changed files with 45 additions and 2 deletions
Showing only changes of commit 24f4f65853 - Show all commits
+37
View File
@@ -0,0 +1,37 @@
import {describe, it, expect, vi, afterEach} from 'vitest'
import {jwennAnTeks} from '../oki-api'
describe('request (via jwennAnTeks)', () => {
const originalFetch = global.fetch
afterEach(() => {
global.fetch = originalFetch
vi.restoreAllMocks()
})
it('returns the parsed body on a successful response', async () => {
global.fetch = vi.fn().mockResolvedValue({
ok: true,
json: async () => ({id: 1, titre: 'Test'})
})
const result = await jwennAnTeks(1, 'token')
expect(result).toEqual({id: 1, titre: 'Test'})
})
it('throws a clear error when Strapi returns an error response', async () => {
global.fetch = vi.fn().mockResolvedValue({
ok: false,
status: 400,
json: async () => ({data: null, error: {status: 400, name: 'ValidationError', message: 'Invalid key'}})
})
await expect(jwennAnTeks(1, 'token')).rejects.toThrow('Eshwe pu jwenn done-a')
})
it('throws when the network request itself fails', async () => {
global.fetch = vi.fn().mockRejectedValue(new TypeError('network down'))
await expect(jwennAnTeks(1, 'token')).rejects.toThrow('Eshwe pu jwenn done-a')
})
})
+8 -2
View File
@@ -14,12 +14,18 @@ const headers = {
async function request(url, opts = {}) { async function request(url, opts = {}) {
const {...options} = opts const {...options} = opts
let res
try { try {
const res = await fetch(`${OKI_API}${url}`, options) res = await fetch(`${OKI_API}${url}`, options)
return res.json()
} catch { } catch {
throw new Error('Eshwe pu jwenn done-a') throw new Error('Eshwe pu jwenn done-a')
} }
if (!res.ok) {
throw new Error('Eshwe pu jwenn done-a')
}
return res.json()
} }
export async function jwennTeksEpiSlug(slug) { export async function jwennTeksEpiSlug(slug) {