fix(ui): directives use client et correctifs qualité (lint, format, typecheck, tests)
This commit is contained in:
1 parent
9a62743e6f
commit
5f4596578f
11 files changed
+77
-38
No files matched your search
@@ -22,10 +22,7 @@ beforeEach(() => {
|
||||
})
|
||||
|
||||
function expectRequest(method: string, path: string) {
|
||||
expect(fetchMock).toHaveBeenCalledWith(
|
||||
path,
|
||||
expect.objectContaining({ method }),
|
||||
)
|
||||
expect(fetchMock).toHaveBeenCalledWith(path, expect.objectContaining({ method }))
|
||||
}
|
||||
|
||||
describe('cardsApi', () => {
|
||||
@@ -43,8 +40,10 @@ describe('cardsApi', () => {
|
||||
|
||||
it('create() envoie POST avec un corps JSON', async () => {
|
||||
fetchMock.mockResolvedValue(jsonResponse(CARD, 201))
|
||||
await expect(cardsApi.create({ question: 'Q ?', response: 'R', theme: 'git' } as never)).resolves.toEqual(CARD)
|
||||
const [_, init] = fetchMock.mock.calls[0]
|
||||
await expect(
|
||||
cardsApi.create({ question: 'Q ?', response: 'R', theme: 'git' } as never),
|
||||
).resolves.toEqual(CARD)
|
||||
const [, init] = fetchMock.mock.calls[0]
|
||||
expect(init.method).toBe('POST')
|
||||
expect(JSON.parse(init.body)).toEqual({ question: 'Q ?', response: 'R', theme: 'git' })
|
||||
})
|
||||
@@ -76,7 +75,9 @@ describe('cardsApi', () => {
|
||||
})
|
||||
|
||||
it('lève ApiClientError avec le message de l API sur une erreur 404', async () => {
|
||||
fetchMock.mockResolvedValue(jsonResponse({ error: 'NotFoundError', message: 'Carte inconnue' }, 404))
|
||||
fetchMock.mockResolvedValue(
|
||||
jsonResponse({ error: 'NotFoundError', message: 'Carte inconnue' }, 404),
|
||||
)
|
||||
await expect(cardsApi.get('nope')).rejects.toMatchObject({
|
||||
name: 'NotFoundError',
|
||||
message: 'Carte inconnue',
|
||||
@@ -85,7 +86,9 @@ describe('cardsApi', () => {
|
||||
})
|
||||
|
||||
it('lève ApiClientError sur une réponse invalide', async () => {
|
||||
fetchMock.mockResolvedValue(jsonResponse({ error: 'ValidationError', message: 'Payload invalide' }, 400))
|
||||
fetchMock.mockResolvedValue(
|
||||
jsonResponse({ error: 'ValidationError', message: 'Payload invalide' }, 400),
|
||||
)
|
||||
await expect(cardsApi.create({} as never)).rejects.toBeInstanceOf(ApiClientError)
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user