import {expect, describe, vi, test, beforeEach} from 'vitest'
import ServiceOfMachines from "@services/ServiceOfMachines.js"
import {AdapterOfMachines, appModalListMachines} from "@mocks/machines.js"
import { createStore } from "vuex"
import { store as machines } from '@/store/modules/machines';

describe('test ServiceOfMachines', () => {
  const adapterOfMachines = new AdapterOfMachines('')
  const store = createStore({
    modules: {
      machines
    }
  })

  beforeEach(() => {
    store.dispatch('machines/resetStore')
  })

  const serviceOfMachines = new ServiceOfMachines(adapterOfMachines, store)

  test('test fetchModalMachines', async () => {
    const result = await serviceOfMachines.fetchModalMachines()
    expect(result).toEqual(appModalListMachines)
  })

  test('test putModalMachines', async () => {
    await serviceOfMachines.putModalMachines(appModalListMachines)
    const result = store.getters['machines/modalMachines']
    expect(result).toEqual(appModalListMachines)
  })

  test('test makeFetchAndPutModalMachines', async () => {
    const funcResult = await serviceOfMachines.makeFetchAndPutModalMachines()
    const storeResult = store.getters['machines/modalMachines']
    expect(funcResult).toEqual(appModalListMachines)
    expect(storeResult).toEqual(appModalListMachines)
  })
})