refactor(helcim): normalize listHelcimCustomerCards return shape
This commit is contained in:
parent
5f93d4c2e3
commit
0a41b30db7
6 changed files with 58 additions and 33 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
|
||||
|
||||
import {
|
||||
listHelcimCustomerCards,
|
||||
listHelcimCustomerTransactions,
|
||||
updateHelcimCustomerDefaultPaymentMethod,
|
||||
updateHelcimSubscriptionPaymentMethod
|
||||
|
|
@ -25,6 +26,56 @@ function errResponse(status = 500, body = 'boom') {
|
|||
}
|
||||
}
|
||||
|
||||
describe('listHelcimCustomerCards', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
afterEach(() => {
|
||||
mockFetch.mockReset()
|
||||
})
|
||||
|
||||
it('passes through a bare array response', async () => {
|
||||
const cards = [
|
||||
{ id: 1, cardToken: 'tok-a' },
|
||||
{ id: 2, cardToken: 'tok-b' }
|
||||
]
|
||||
mockFetch.mockResolvedValue(okResponse(cards))
|
||||
|
||||
const result = await listHelcimCustomerCards('2488717')
|
||||
|
||||
expect(result).toEqual(cards)
|
||||
})
|
||||
|
||||
it('unwraps a { cards: [...] } response envelope', async () => {
|
||||
const cards = [{ id: 1, cardToken: 'tok-a' }]
|
||||
mockFetch.mockResolvedValue(okResponse({ cards }))
|
||||
|
||||
const result = await listHelcimCustomerCards('2488717')
|
||||
|
||||
expect(result).toEqual(cards)
|
||||
})
|
||||
|
||||
it('unwraps a { data: [...] } response envelope', async () => {
|
||||
const cards = [{ id: 1, cardToken: 'tok-a' }]
|
||||
mockFetch.mockResolvedValue(okResponse({ data: cards }))
|
||||
|
||||
const result = await listHelcimCustomerCards('2488717')
|
||||
|
||||
expect(result).toEqual(cards)
|
||||
})
|
||||
|
||||
it('returns an empty array for null, undefined, or unrecognized object responses', async () => {
|
||||
mockFetch.mockResolvedValueOnce(okResponse(null))
|
||||
expect(await listHelcimCustomerCards('2488717')).toEqual([])
|
||||
|
||||
mockFetch.mockResolvedValueOnce(okResponse(undefined))
|
||||
expect(await listHelcimCustomerCards('2488717')).toEqual([])
|
||||
|
||||
mockFetch.mockResolvedValueOnce(okResponse({ unexpected: 'shape' }))
|
||||
expect(await listHelcimCustomerCards('2488717')).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
describe('listHelcimCustomerTransactions', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue