diff --git a/src/store/mutations.js b/src/store/mutations.js index fc2fa48..69a4319 100644 --- a/src/store/mutations.js +++ b/src/store/mutations.js @@ -42,11 +42,9 @@ export default { state.baseURL = baseURL; }, [types.SET_VERSION](state, {version}){ - if (state.password === null) { - state.password = {version}; - } else { - state.password.version = version; - } + const length = version === 1 ? 12 : 16; + state.password.version = version; + state.password.length = length; }, [types.LOAD_PASSWORD_FIRST_TIME](state){ const tenMinutesAgo = new Date().getTime() - 60 * 1000; diff --git a/test/store.mutations.js b/test/store.mutations.js index 966feeb..227cb68 100644 --- a/test/store.mutations.js +++ b/test/store.mutations.js @@ -150,13 +150,22 @@ test('SET_VERSION', t => { t.is(state.password.version, 1); }); -test('SET_VERSION password null', t => { +test('SET_VERSION 1 should modify length to 12', t => { const SET_VERSION = mutations[types.SET_VERSION]; const state = { - password: null, + password: {length: 16, version: 2}, + }; + SET_VERSION(state, {version: 1}); + t.is(state.password.length, 12); +}); + +test('SET_VERSION 2 should modify length to 16', t => { + const SET_VERSION = mutations[types.SET_VERSION]; + const state = { + password: {length: 12, version: 1}, }; SET_VERSION(state, {version: 2}); - t.is(state.password.version, 2); + t.is(state.password.length, 16); }); test('LOAD_PASSWORD_FIRST_TIME 30 seconds after last use', t => {