import {expect, describe, test, beforeEach} from 'vitest'
import ServiceOfMachines from "@services/ServiceOfMachines.js"
import {appModalListMachines, resLastMachines, AdapterOfMachines} 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('Get machines for modal with func getModalMachines', async () => {
    const result = await serviceOfMachines.fetchModalMachines()
    expect(result).toEqual(appModalListMachines)
  })

  test('Get machines for modal in store with func getAndPutModalMachines', async () => {
    const funcResult = await serviceOfMachines.fetchAndSetModalMachines()
    const storeResult = store.getters['machines/modalMachines']
    expect(funcResult).toEqual(appModalListMachines)
    expect(storeResult).toEqual(appModalListMachines)
  })

  test('Get last machines by pack number with func getLastMachinesByPackNum', async () => {
    const result = await serviceOfMachines.fetchLastMachinesByPackNum([7683])
    expect(result[0]).toEqual(resLastMachines[0])
  })

  test('Get last machines in store with func getAndPutLastMachinesByPackNum', async () => {
    const funcResult = await serviceOfMachines.fetchAndSetLastMachinesByPackNum([7683])
    const storeResult = store.getters['machines/lastMachinesByPackNumber']
    expect(funcResult[0]).toEqual(resLastMachines[0])
    expect(storeResult[0]).toEqual(resLastMachines[0])
  })

})