import Vue from 'vue'
import VueRouter from 'vue-router'
import originalCreateStore from '~/store'
import { merge } from 'lodash'
import { RouterLinkStub as NuxtLink } from '@vue/test-utils'
import axiosMock from './axios-mock'
import fixtures from './fixtures'

beforeEach(() => {
  Vue.prototype.$toast = {
    error: jest.fn(),
    success: jest.fn()
  }
})

function createStore() {
  const store = originalCreateStore()
  store.replaceState({
    auth: {
      loggedIn: false,
      user: null
    }
  })
  return store
}

const authedUserCreateStore = () => {
  const store = createStore()
  store.replaceState({
    auth: {
      loggedIn: true,
      user: {
        data: {
          user: {
            username: 'foo',
            id: '1'
          },
          storage: {
            available: 1
          }
        }
      }
    }
  })
  return store
}

const baseMountOpts = (...overrides) =>
  merge(
    {},
    {
      stubs: {
        NuxtLink
      }
    },
    ...overrides
  )

export {
  createStore,
  VueRouter,
  authedUserCreateStore,
  baseMountOpts,
  axiosMock,
  fixtures
}

export * from '@vue/test-utils'

@@ -351,16 +351,94 @@
 n()%0A  %7D%0A
+  Vue.prototype.$auth = %7B%0A    loginWith: jest.fn(),%0A    logout: jest.fn()%0A  %7D%0A
 %7D)%0A%0Afunc

Add $auth mock