| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- import { describe, test, it, expect, beforeEach } from 'vitest'
- import type { VueI18n } from 'vue-i18n'
- import type ApiRequestService from '~/services/data/apiRequestService'
- import EnumManager from '~/services/data/enumManager'
- let apiRequestService: ApiRequestService
- let i18n: VueI18n
- let enumManager: EnumManager
- beforeEach(() => {
- // @ts-ignore
- apiRequestService = vi.fn() as ApiRequestService
- // @ts-ignore
- i18n = vi.fn() as VueI18n
- enumManager = new EnumManager(apiRequestService, i18n)
- })
- describe('fetch', () => {
- test('simple call', async () => {
- const hydraData = {
- '@context': '/api/contexts/Enum',
- '@id': '/api/enum/contact_point_type',
- '@type': 'Enum',
- name: 'contact_point_type',
- items: {
- PRINCIPAL: 'PRINCIPAL',
- BILL: 'BILL',
- OTHER: 'OTHER',
- CONTACT: 'CONTACT',
- },
- }
- const translationOf = {
- PRINCIPAL: 'Principal',
- BILL: 'Facture',
- OTHER: 'Autre',
- CONTACT: 'Contact',
- }
- // @ts-ignore
- apiRequestService.get = vi.fn((url: string) => hydraData)
- // @ts-ignore
- i18n.t = vi.fn((key: string) => translationOf[key])
- const result = await enumManager.fetch('contact_point_type')
- expect(apiRequestService.get).toHaveBeenCalledWith(
- 'api/enum/contact_point_type',
- )
- expect(result).toEqual([
- { label: 'Principal', value: 'PRINCIPAL' },
- { label: 'Facture', value: 'BILL' },
- { label: 'Autre', value: 'OTHER' },
- { label: 'Contact', value: 'CONTACT' },
- ])
- })
- })
|