comparison client/tests/unit/session/session.spec.js @ 165:4bf2173748f3

refactor: extracted the string to milisecondconversion Extracted the conversion of session data to string conversion to Method. SRP.
author Thomas Junk <thomas.junk@intevation.de>
date Fri, 06 Jul 2018 11:04:52 +0200
parents 7c40e9f28f94
children 79db27e3a999
comparison
equal deleted inserted replaced
164:7c40e9f28f94 165:4bf2173748f3
1 import { sessionStillActive } from "../../../src/lib/session"; 1 import {
2 sessionStillActive,
3 toMillisFromString
4 } from "../../../src/lib/session";
2 5
3 test("No session counts as expired session", () => { 6 test("No session counts as expired session", () => {
4 expect(sessionStillActive(null)).toBe(false); 7 expect(sessionStillActive(null)).toBe(false);
5 }); 8 });
6 9
7 test("Session expired", () => { 10 test("Session expired", () => {
8 const expired = Date.now() - 6000; 11 const expired = Date.now() - 60000;
9 expect(sessionStillActive(expired)).toBe(false); 12 expect(sessionStillActive(expired)).toBe(false);
10 }); 13 });
11 14
12 test("Session alive", () => { 15 test("Session alive", () => {
13 const active = Date.now() + 60000; 16 const active = Date.now() + 60000;
14 expect(sessionStillActive(active)).toBe(true); 17 expect(sessionStillActive(active)).toBe(true);
15 }); 18 });
16 19
17 test("Session alive with string", () => { 20 test("Session alive with string", () => {
18 const active = "" + Date.now() + 60000; 21 const active = "" + Date.now() / 1000 + 60000;
19 expect(sessionStillActive(active)).toBe(true); 22 expect(sessionStillActive(toMillisFromString(active))).toBe(true);
20 }); 23 });
21 24
22 test("Session expired with string", () => { 25 test("Session expired with string", () => {
23 const expired = "" + Date.now() - 60000; 26 const expired = "" + Date.now() / 1000 - 60000;
24 expect(sessionStillActive(expired)).toBe(false); 27 expect(sessionStillActive(toMillisFromString(expired))).toBe(false);
25 }); 28 });