2019-03-25 15:50:11 +01:00
|
|
|
import { createLocalVue } from '@vue/test-utils'
|
|
|
|
import Vuex from 'vuex'
|
|
|
|
import { ipcMain } from '~/spec/mock/electron'
|
2019-04-06 15:08:29 +02:00
|
|
|
import Account, { AccountState } from '@/store/Preferences/Account'
|
2019-04-14 16:25:10 +02:00
|
|
|
import LocalAccount from '~/src/types/localAccount'
|
2019-03-25 15:50:11 +01:00
|
|
|
|
2019-04-14 16:21:08 +02:00
|
|
|
const account: LocalAccount = {
|
2019-04-06 15:08:29 +02:00
|
|
|
_id: 'sample',
|
|
|
|
baseURL: 'http://example.com',
|
|
|
|
domain: 'example.com',
|
|
|
|
clientId: 'hoge',
|
|
|
|
clientSecret: 'hogehoge',
|
|
|
|
accessToken: null,
|
|
|
|
refreshToken: null,
|
|
|
|
username: null,
|
|
|
|
accountId: null,
|
|
|
|
avatar: null,
|
|
|
|
order: 1
|
|
|
|
}
|
|
|
|
|
|
|
|
const state = (): AccountState => {
|
2019-03-25 15:50:11 +01:00
|
|
|
return {
|
|
|
|
accounts: [],
|
|
|
|
accountLoading: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const initStore = () => {
|
|
|
|
return {
|
|
|
|
namespaced: true,
|
|
|
|
state: state(),
|
|
|
|
actions: Account.actions,
|
|
|
|
mutations: Account.mutations
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('Account', () => {
|
|
|
|
let store
|
|
|
|
let localVue
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
localVue = createLocalVue()
|
|
|
|
localVue.use(Vuex)
|
|
|
|
store = new Vuex.Store({
|
|
|
|
modules: {
|
|
|
|
Account: initStore()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('loadAccounts', () => {
|
|
|
|
it('error', async () => {
|
2019-04-06 15:08:29 +02:00
|
|
|
ipcMain.once('list-accounts', (event: any, _) => {
|
2019-03-25 15:50:11 +01:00
|
|
|
event.sender.send('error-list-accounts', new Error())
|
|
|
|
})
|
|
|
|
|
|
|
|
await store.dispatch('Account/loadAccounts')
|
|
|
|
.catch((err: Error) => {
|
|
|
|
expect(err instanceof Error).toEqual(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
it('success', async () => {
|
2019-04-06 15:08:29 +02:00
|
|
|
ipcMain.once('list-accounts', (event: any, _) => {
|
|
|
|
event.sender.send('response-list-accounts', [account])
|
2019-03-25 15:50:11 +01:00
|
|
|
})
|
|
|
|
await store.dispatch('Account/loadAccounts')
|
2019-04-06 15:08:29 +02:00
|
|
|
expect(store.state.Account.accounts).toEqual([account])
|
2019-03-25 15:50:11 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('removeAccount', () => {
|
|
|
|
it('error', async () => {
|
2019-04-06 15:08:29 +02:00
|
|
|
ipcMain.once('remove-account', (event: any, _) => {
|
2019-03-25 15:50:11 +01:00
|
|
|
event.sender.send('error-remove-account', new Error())
|
|
|
|
})
|
2019-04-06 15:08:29 +02:00
|
|
|
await store.dispatch('Account/removeAccount', account)
|
2019-03-25 15:50:11 +01:00
|
|
|
.catch((err: Error) => {
|
|
|
|
expect(err instanceof Error).toEqual(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
it('success', async () => {
|
2019-04-06 15:08:29 +02:00
|
|
|
ipcMain.once('remove-account', (event: any, _) => {
|
|
|
|
event.sender.send('response-remove-account')
|
2019-03-25 15:50:11 +01:00
|
|
|
})
|
2019-04-06 15:08:29 +02:00
|
|
|
const res = await store.dispatch('Account/removeAccount', account)
|
2019-03-25 15:50:11 +01:00
|
|
|
expect(res).toEqual(undefined)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('forwardAccount', () => {
|
|
|
|
it('error', async () => {
|
2019-04-06 15:08:29 +02:00
|
|
|
ipcMain.once('forward-account', (event: any, _) => {
|
2019-03-25 15:50:11 +01:00
|
|
|
event.sender.send('error-forward-account', new Error())
|
|
|
|
})
|
2019-04-06 15:08:29 +02:00
|
|
|
await store.dispatch('Account/forwardAccount', account)
|
2019-03-25 15:50:11 +01:00
|
|
|
.catch((err: Error) => {
|
|
|
|
expect(err instanceof Error).toEqual(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
it('success', async () => {
|
2019-04-06 15:08:29 +02:00
|
|
|
ipcMain.once('forward-account', (event: any, _) => {
|
|
|
|
event.sender.send('response-forward-account')
|
2019-03-25 15:50:11 +01:00
|
|
|
})
|
2019-04-06 15:08:29 +02:00
|
|
|
const res = await store.dispatch('Account/forwardAccount', account)
|
2019-03-25 15:50:11 +01:00
|
|
|
expect(res).toEqual(undefined)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('backwardAccount', () => {
|
|
|
|
it('error', async () => {
|
2019-04-06 15:08:29 +02:00
|
|
|
ipcMain.once('backward-account', (event: any, _) => {
|
2019-03-25 15:50:11 +01:00
|
|
|
event.sender.send('error-backward-account', new Error())
|
|
|
|
})
|
2019-04-06 15:08:29 +02:00
|
|
|
await store.dispatch('Account/backwardAccount', account)
|
2019-03-25 15:50:11 +01:00
|
|
|
.catch((err: Error) => {
|
|
|
|
expect(err instanceof Error).toEqual(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
it('success', async () => {
|
2019-04-06 15:08:29 +02:00
|
|
|
ipcMain.once('backward-account', (event: any, _) => {
|
|
|
|
event.sender.send('response-backward-account')
|
2019-03-25 15:50:11 +01:00
|
|
|
})
|
2019-04-06 15:08:29 +02:00
|
|
|
const res = await store.dispatch('Account/backwardAccount', account)
|
2019-03-25 15:50:11 +01:00
|
|
|
expect(res).toEqual(undefined)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('removeAllAccounts', () => {
|
|
|
|
it('error', async () => {
|
2019-04-06 15:08:29 +02:00
|
|
|
ipcMain.once('remove-all-accounts', (event: any, _) => {
|
2019-03-25 15:50:11 +01:00
|
|
|
event.sender.send('error-remove-all-accounts', new Error())
|
|
|
|
})
|
2019-04-06 15:08:29 +02:00
|
|
|
await store.dispatch('Account/removeAllAccounts', account)
|
2019-03-25 15:50:11 +01:00
|
|
|
.catch((err: Error) => {
|
|
|
|
expect(err instanceof Error).toEqual(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
it('success', async () => {
|
2019-04-06 15:08:29 +02:00
|
|
|
ipcMain.once('remove-all-accounts', (event: any, _) => {
|
|
|
|
event.sender.send('response-remove-all-accounts')
|
2019-03-25 15:50:11 +01:00
|
|
|
})
|
2019-04-06 15:08:29 +02:00
|
|
|
const res = await store.dispatch('Account/removeAllAccounts', account)
|
2019-03-25 15:50:11 +01:00
|
|
|
expect(res).toEqual(undefined)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|