import { Store } from 'vuex'
import VuexORM from '@vuex-orm/core'
import VueCompositionAPI from '@vue/composition-api';
import { mount, createLocalVue } from '@vue/test-utils'
import { AnyJson } from '~/types/interfaces'

const localVue = createLocalVue()
localVue.use(VueCompositionAPI);

export function initLocalVue (ctx:AnyJson) {
  localVue.prototype.$nuxt = {
    context: ctx
  }
}

export function mountComposition (cb: () => any) {
  return mount(
    {
      setup () {
        return cb()
      },
      render (h) {
        return h('div')
      }
    },
    { localVue }
  )
}

export function createStore (): Store<any> {
  return new Store({
    plugins: [VuexORM.install()],
    strict: true
  })
}
