Skip to content
Snippets Groups Projects
Verified Commit aa67be90 authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Now load instance settings on page load

parent bb9a614a
No related branches found
No related tags found
No related merge requests found
......@@ -31,6 +31,9 @@ import Sidebar from '@/components/Sidebar'
export default {
name: 'app',
components: { Sidebar }
created () {
this.$store.dispatch('instance/fetchSettings')
}
}
</script>
......
......@@ -4,6 +4,7 @@ import createPersistedState from 'vuex-persistedstate'
import favorites from './favorites'
import auth from './auth'
import instance from './instance'
import queue from './queue'
import radios from './radios'
import player from './player'
......@@ -14,6 +15,7 @@ export default new Vuex.Store({
modules: {
auth,
favorites,
instance,
queue,
radios,
player
......
import axios from 'axios'
import logger from '@/logging'
import _ from 'lodash'
export default {
namespaced: true,
state: {
settings: {
raven: {
front_enabled: {
value: false
},
front_dsn: {
value: null
}
}
}
},
mutations: {
settings: (state, value) => {
_.merge(state.settings, value)
}
},
actions: {
// Send a request to the login URL and save the returned JWT
fetchSettings ({commit}) {
return axios.get('instance/settings/').then(response => {
logger.default.info('Successfully fetched instance settings')
let sections = {}
response.data.forEach(e => {
sections[e.section] = {}
})
response.data.forEach(e => {
sections[e.section][e.name] = e
})
commit('settings', sections)
}, response => {
logger.default.error('Error while fetching settings', response.data)
})
}
}
}
var sinon = require('sinon')
import moxios from 'moxios'
import store from '@/store/instance'
import { testAction } from '../../utils'
describe('store/instance', () => {
var sandbox
beforeEach(function () {
sandbox = sinon.sandbox.create()
moxios.install()
})
afterEach(function () {
sandbox.restore()
moxios.uninstall()
})
describe('mutations', () => {
it('settings', () => {
const state = {settings: {raven: {front_dsn: {value: 'test'}}}}
let settings = {raven: {front_enabled: {value: true}}}
store.mutations.settings(state, settings)
expect(state.settings).to.deep.equal({
raven: {front_dsn: {value: 'test'}, front_enabled: {value: true}}
})
})
})
describe('actions', () => {
it('fetchSettings', (done) => {
moxios.stubRequest('instance/settings/', {
status: 200,
response: [
{
section: 'raven',
name: 'front_dsn',
value: 'test'
},
{
section: 'raven',
name: 'front_enabled',
value: false
}
]
})
testAction({
action: store.actions.fetchSettings,
payload: null,
expectedMutations: [
{
type: 'settings',
payload: {
raven: {
front_dsn: {
section: 'raven',
name: 'front_dsn',
value: 'test'
},
front_enabled: {
section: 'raven',
name: 'front_enabled',
value: false
}
}
}
}
]
}, done)
})
})
})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment