diff --git a/front/src/store/auth.js b/front/src/store/auth.js index 7944cae0836f58a6eed111b2134fb9ab702123ef..e72e1968f52f1ca3593abfbbdabf4e06fda7b1d5 100644 --- a/front/src/store/auth.js +++ b/front/src/store/auth.js @@ -91,6 +91,7 @@ export default { commit('profile', data) commit('username', data.username) dispatch('favorites/fetch', null, {root: true}) + dispatch('playlists/fetchOwn', null, {root: true}) Object.keys(data.permissions).forEach(function (key) { // this makes it easier to check for permissions in templates commit('permission', {key, status: data.permissions[String(key)].status}) diff --git a/front/src/store/index.js b/front/src/store/index.js index 2453c0e7134124e3f9d9dc3ffac47d2558a9827d..298fa04ec13166fead7a12955636d3bc4340948a 100644 --- a/front/src/store/index.js +++ b/front/src/store/index.js @@ -8,6 +8,7 @@ import instance from './instance' import queue from './queue' import radios from './radios' import player from './player' +import playlists from './playlists' import ui from './ui' Vue.use(Vuex) @@ -20,6 +21,7 @@ export default new Vuex.Store({ instance, queue, radios, + playlists, player }, plugins: [ diff --git a/front/src/store/playlists.js b/front/src/store/playlists.js new file mode 100644 index 0000000000000000000000000000000000000000..75cac87ba42c48555f6ad3d30632a4fd70b67c16 --- /dev/null +++ b/front/src/store/playlists.js @@ -0,0 +1,24 @@ +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) + }) + } + } +} diff --git a/front/test/unit/specs/store/auth.spec.js b/front/test/unit/specs/store/auth.spec.js index 3271f5168f335a95f5e2799007bd3ec64cf77155..518dc10d4db29f680567d6c996853086cd6b4516 100644 --- a/front/test/unit/specs/store/auth.spec.js +++ b/front/test/unit/specs/store/auth.spec.js @@ -180,7 +180,8 @@ describe('store/auth', () => { { type: 'permission', payload: {key: 'admin', status: true} } ], 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) }) diff --git a/front/test/unit/specs/store/playlists.spec.js b/front/test/unit/specs/store/playlists.spec.js new file mode 100644 index 0000000000000000000000000000000000000000..e82af60bbb470f59bae63d1b2fe89ee30ca6bbb5 --- /dev/null +++ b/front/test/unit/specs/store/playlists.spec.js @@ -0,0 +1,36 @@ +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) + }) + }) +})