39246-vm/frontend/__tests__/listings-api.test.ts
abbashkyt-creator 7d8ce0e322 V0.1
2026-03-14 04:02:22 +03:00

23 lines
892 B
TypeScript

import { describe, it, expect } from 'vitest'
import { parseListingResponse } from '../lib/api/listings'
describe('parseListingResponse', () => {
it('parses images JSON string to array', () => {
const raw = { images: '["http://a.com/1.jpg","http://a.com/2.jpg"]', closing_alerts_sent: '[]' }
const result = parseListingResponse(raw as any)
expect(result.images).toEqual(['http://a.com/1.jpg', 'http://a.com/2.jpg'])
})
it('handles null images as empty array', () => {
const raw = { images: null, closing_alerts_sent: '[]' }
const result = parseListingResponse(raw as any)
expect(result.images).toEqual([])
})
it('parses closing_alerts_sent to number array', () => {
const raw = { images: '[]', closing_alerts_sent: '[60,30,10]' }
const result = parseListingResponse(raw as any)
expect(result.closing_alerts_sent).toEqual([60, 30, 10])
})
})