import {expect, describe, test, beforeEach} from 'vitest'
import ServiceOfPacks from "@services/ServiceOfPacks.js"
import {resPacks, resFreePacks, defaultParams, freePacksParams, ApiOfPacks} from "@mocks/packs.js"
import { createStore } from "vuex"
import { store as packs } from '@/store/modules/packs'

describe('test ServiceOfPacks', () => {

  const apiOfPacks = new ApiOfPacks()
  const store = createStore({
    modules: {
      packs
    }
  })

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

  const serviceOfPacks = new ServiceOfPacks(apiOfPacks, store)

  test('Get last packs with func fetchLastPacks', async () => {
    const result = await serviceOfPacks.fetchLastPacks(defaultParams.imei, defaultParams.dtStart, defaultParams.dtFinish)
    expect(result).toEqual(resPacks)
  })

  test('Get last packs in store with func fetchAndSetLastPacks', async () => {
    const funcResult = await serviceOfPacks.fetchAndSetLastPacks(defaultParams.imei, defaultParams.dtStart, defaultParams.dtFinish)
    const storeResult = store.getters['packs/lastPacks']
    expect(funcResult).toEqual(resPacks)
    expect(storeResult).toEqual(resPacks)
  })

  test('Get free packs with func fetchFreePacks', async () => {
    const result = await serviceOfPacks.fetchFreePacks(freePacksParams)
    expect(result).toEqual(resFreePacks)
  })

  test('Get free packs in store with func fetchAndSetFreePacks', async () => {
    const funcResult = await serviceOfPacks.fetchAndSetFreePacks(freePacksParams)
    const storeResult = store.getters['packs/freePacks']
    expect(funcResult).toEqual(resFreePacks)
    expect(storeResult).toEqual(resFreePacks)
  })

})