import { describe, test, it, expect } from 'vitest'
import ApiRequestService from "~/services/data/apiRequestService";
import EnumManager from "~/services/data/enumManager";
import {VueI18n} from "vue-i18n";

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" },
        ])
    })
})
