Pārlūkot izejas kodu

simplify password getter

pull/342/head
Guillaume Vincent pirms 7 gadiem
vecāks
revīzija
21cc3a9d4f
2 mainītis faili ar 2 papildinājumiem un 69 dzēšanām
  1. +2
    -8
      src/store/getters.js
  2. +0
    -61
      test/store.getters.js

+ 2
- 8
src/store/getters.js Parādīt failu

@@ -1,19 +1,13 @@
export const passwords = state => state.passwords;

export const password = state => state.password;

export const isAuthenticated = state => state.authenticated;

export const isGuest = state => !state.authenticated;

export const passwordStatus = state => state.passwordStatus;

export const password = state => {
const tenMinutesAgo = new Date().getTime() - 10 * 60 * 1000;
if (state.lastUse < tenMinutesAgo) {
return Object.assign({}, state.defaultPassword);
}
return Object.assign({}, state.defaultPassword, state.password);
};

export const version = state => {
if(state.password === null){
return state.defaultPassword.version;


+ 0
- 61
test/store.getters.js Parādīt failu

@@ -1,67 +1,6 @@
import test from 'ava';
import timekeeper from 'timekeeper';

import * as getters from '../src/store/getters';

test('password 5 minutes after last use', t => {
const now = 1485989236;
const time = new Date(now * 1000);
timekeeper.freeze(time);
const fiveMinutesBefore = (now - 5 * 60) * 1000;
const state = {
lastUse: fiveMinutesBefore,
password: {
login: 'test@example.org',
length: 30
},
defaultPassword: {
site: '',
login: '',
uppercase: true,
lowercase: true,
numbers: true,
symbols: true,
length: 16,
counter: 1,
version: 2
}
};
const password = getters.password(state);
t.is(password.login, 'test@example.org');
t.is(password.length, 30);
timekeeper.reset();
});

test('password more than 10 minutes after last use', t => {
const now = 1485989236;
const time = new Date(now * 1000);
timekeeper.freeze(time);
const fifteenMinutesBefore = (now - 15 * 60) * 1000;
const state = {
lastUse: fifteenMinutesBefore,
password: {
login: 'test@example.org',
length: 30
},
defaultPassword: {
site: '',
login: '',
uppercase: true,
lowercase: true,
numbers: true,
symbols: true,
length: 16,
counter: 1,
version: 2
}
};
const password = getters.password(state);
t.is('', password.login);
t.is('', password.site);
t.is(16, password.length);
timekeeper.reset();
});

test('version', t => {
const state = {
password: {version: 2},


Notiek ielāde…
Atcelt
Saglabāt