Verified Commit a34b1afd authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Store for fetching user playlists

parent 15300e25
...@@ -91,6 +91,7 @@ export default { ...@@ -91,6 +91,7 @@ export default {
commit('profile', data) commit('profile', data)
commit('username', data.username) commit('username', data.username)
dispatch('favorites/fetch', null, {root: true}) dispatch('favorites/fetch', null, {root: true})
dispatch('playlists/fetchOwn', null, {root: true})
Object.keys(data.permissions).forEach(function (key) { Object.keys(data.permissions).forEach(function (key) {
// this makes it easier to check for permissions in templates // this makes it easier to check for permissions in templates
commit('permission', {key, status: data.permissions[String(key)].status}) commit('permission', {key, status: data.permissions[String(key)].status})
......
...@@ -8,6 +8,7 @@ import instance from './instance' ...@@ -8,6 +8,7 @@ import instance from './instance'
import queue from './queue' import queue from './queue'
import radios from './radios' import radios from './radios'
import player from './player' import player from './player'
import playlists from './playlists'
import ui from './ui' import ui from './ui'
Vue.use(Vuex) Vue.use(Vuex)
...@@ -20,6 +21,7 @@ export default new Vuex.Store({ ...@@ -20,6 +21,7 @@ export default new Vuex.Store({
instance, instance,
queue, queue,
radios, radios,
playlists,
player player
}, },
plugins: [ plugins: [
......
import axios from 'axios'
export default {
namespaced: true,
state: {
playlists: []
},
mutations: {
playlists (state, value) {
state.playlists = value
}
},
actions: {
fetchOwn ({commit, rootState}) {
let userId = rootState.auth.profile.id
if (!userId) {
return
}
return axios.get('playlists/', {params: {user: userId}}).then((response) => {
commit('playlists', response.data.results)
})
}
}
}
...@@ -180,7 +180,8 @@ describe('store/auth', () => { ...@@ -180,7 +180,8 @@ describe('store/auth', () => {
{ type: 'permission', payload: {key: 'admin', status: true} } { type: 'permission', payload: {key: 'admin', status: true} }
], ],
expectedActions: [ expectedActions: [
{ type: 'favorites/fetch', payload: null, options: {root: true} } { type: 'favorites/fetch', payload: null, options: {root: true} },
{ type: 'playlists/fetchOwn', payload: null, options: {root: true} },
] ]
}, done) }, done)
}) })
......
var sinon = require('sinon')
import moxios from 'moxios'
import store from '@/store/playlists'
import { testAction } from '../../utils'
describe('store/playlists', () => {
var sandbox
beforeEach(function () {
sandbox = sinon.sandbox.create()
moxios.install()
})
afterEach(function () {
sandbox.restore()
moxios.uninstall()
})
describe('mutations', () => {
it('set playlists', () => {
const state = { playlists: [] }
store.mutations.playlists(state, [{id: 1, name: 'test'}])
expect(state.playlists).to.deep.equal([{id: 1, name: 'test'}])
})
})
describe('actions', () => {
it('fetchOwn does nothing with no user', (done) => {
testAction({
action: store.actions.fetchOwn,
payload: null,
params: {state: { playlists: [] }, rootState: {auth: {profile: {}}}},
expectedMutations: []
}, done)
})
})
})
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment