feat(test): add settingStore tests

This commit is contained in:
Phan An 2022-07-23 13:10:41 +02:00
parent 7dc16a3883
commit 7a0c05ab47
No known key found for this signature in database
GPG key ID: A81E4477F0BB6FDC
2 changed files with 22 additions and 2 deletions

View file

@ -0,0 +1,19 @@
import { expect, it } from 'vitest'
import UnitTestCase from '@/__tests__/UnitTestCase'
import { settingStore } from '@/stores/settingStore'
import { httpService } from '@/services'
new class extends UnitTestCase {
protected test () {
it('initializes the store', () => {
settingStore.init({ media_path: '/media/path' })
expect(settingStore.state.media_path).toEqual('/media/path')
})
it('updates the media path', async () => {
this.mock(httpService, 'put')
await settingStore.update({ media_path: '/dev/null' })
expect(settingStore.state.media_path).toEqual('/dev/null')
})
}
}

View file

@ -1,5 +1,6 @@
import { reactive } from 'vue'
import { httpService } from '@/services'
import { merge } from 'lodash'
export const settingStore = {
state: reactive<Settings>({
@ -7,11 +8,11 @@ export const settingStore = {
}),
init (settings: Settings) {
Object.assign(this.state, settings)
merge(this.state, settings)
},
async update (settings: Settings) {
await httpService.put('settings', settings)
Object.assign(this.state, settings)
merge(this.state, settings)
}
}