diff --git a/src/store/mutation-types.js b/src/store/mutation-types.js deleted file mode 100644 index 5d5af67..0000000 --- a/src/store/mutation-types.js +++ /dev/null @@ -1,3 +0,0 @@ -export const LOGIN = 'LOGIN'; -export const LOGOUT = 'LOGOUT'; -export const SET_CURRENT_PASSWORD_PROFILE = 'SET_CURRENT_PASSWORD_PROFILE'; \ No newline at end of file diff --git a/src/store/mutations.js b/src/store/mutations.js index 21b4a8c..638f0f7 100644 --- a/src/store/mutations.js +++ b/src/store/mutations.js @@ -1,13 +1,20 @@ -import * as types from './mutation-types'; +import {set} from 'vue'; + +function setState(state, id, object) { + set(state, id, Object.assign({}, object)); +} export const mutations = { - [types.LOGIN](state){ + LOGIN(state){ state.authenticated = true; }, - [types.LOGOUT](state){ + LOGOUT(state){ state.authenticated = false; }, - [types.SET_CURRENT_PASSWORD_PROFILE](state, passwordProfile){ - state.currentPasswordProfile = passwordProfile; + SET_CURRENT_PASSWORD_PROFILE(state, passwordProfile){ + setState(state, 'currentPasswordProfile', passwordProfile); + }, + SET_DEFAULT_OPTIONS(state, options){ + setState(state, 'defaultOptions', options); } }; \ No newline at end of file diff --git a/test/store.js b/test/store.js index f71a2b3..7110813 100644 --- a/test/store.js +++ b/test/store.js @@ -22,6 +22,36 @@ test('SET_CURRENT_PASSWORD_PROFILE', t => { uppercase: true, version: 2 }); - t.true(state.currentPasswordProfile.version == 2); + t.is(state.currentPasswordProfile.version, 2); t.true(state.currentPasswordProfile.uppercase); +}); + +test('SET_CURRENT_PASSWORD_PROFILE immutable', t => { + const {SET_CURRENT_PASSWORD_PROFILE} = mutations; + const state = {}; + const profile = {version: 2}; + SET_CURRENT_PASSWORD_PROFILE(state, profile); + profile.version = 1; + t.is(state.currentPasswordProfile.version, 2); +}); + +test('SET_DEFAULT_OPTIONS', t => { + const {SET_DEFAULT_OPTIONS} = mutations; + const state = { + defaultOptions: { + uppercase: true, + lowercase: true, + numbers: true, + symbols: true, + length: 16, + counter: 1, + version: 2 + } + }; + SET_DEFAULT_OPTIONS(state, { + symbols: false, + length: 30 + }); + t.is(state.defaultOptions.length, 30); + t.false(state.defaultOptions.symbols); }); \ No newline at end of file