annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
165
4bf2173748f3 refactor: extracted the string to milisecondconversion
Thomas Junk <thomas.junk@intevation.de>
parents: 164
diff changeset
1 import {
4bf2173748f3 refactor: extracted the string to milisecondconversion
Thomas Junk <thomas.junk@intevation.de>
parents: 164
diff changeset
2 sessionStillActive,
4bf2173748f3 refactor: extracted the string to milisecondconversion
Thomas Junk <thomas.junk@intevation.de>
parents: 164
diff changeset
3 toMillisFromString
4bf2173748f3 refactor: extracted the string to milisecondconversion
Thomas Junk <thomas.junk@intevation.de>
parents: 164
diff changeset
4 } from "../../../src/lib/session";
162
9908260d1e6a Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
5
9908260d1e6a Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
6 test("No session counts as expired session", () => {
9908260d1e6a Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
7 expect(sessionStillActive(null)).toBe(false);
9908260d1e6a Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
8 });
9908260d1e6a Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
9
9908260d1e6a Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
10 test("Session expired", () => {
165
4bf2173748f3 refactor: extracted the string to milisecondconversion
Thomas Junk <thomas.junk@intevation.de>
parents: 164
diff changeset
11 const expired = Date.now() - 60000;
162
9908260d1e6a Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
12 expect(sessionStillActive(expired)).toBe(false);
9908260d1e6a Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
13 });
9908260d1e6a Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
14
9908260d1e6a Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
15 test("Session alive", () => {
9908260d1e6a Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
16 const active = Date.now() + 60000;
9908260d1e6a Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
17 expect(sessionStillActive(active)).toBe(true);
9908260d1e6a Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
18 });
163
30c212a6f580 fix: Bugfix for session evaluation
Thomas Junk <thomas.junk@intevation.de>
parents: 162
diff changeset
19
30c212a6f580 fix: Bugfix for session evaluation
Thomas Junk <thomas.junk@intevation.de>
parents: 162
diff changeset
20 test("Session alive with string", () => {
165
4bf2173748f3 refactor: extracted the string to milisecondconversion
Thomas Junk <thomas.junk@intevation.de>
parents: 164
diff changeset
21 const active = "" + Date.now() / 1000 + 60000;
4bf2173748f3 refactor: extracted the string to milisecondconversion
Thomas Junk <thomas.junk@intevation.de>
parents: 164
diff changeset
22 expect(sessionStillActive(toMillisFromString(active))).toBe(true);
163
30c212a6f580 fix: Bugfix for session evaluation
Thomas Junk <thomas.junk@intevation.de>
parents: 162
diff changeset
23 });
30c212a6f580 fix: Bugfix for session evaluation
Thomas Junk <thomas.junk@intevation.de>
parents: 162
diff changeset
24
30c212a6f580 fix: Bugfix for session evaluation
Thomas Junk <thomas.junk@intevation.de>
parents: 162
diff changeset
25 test("Session expired with string", () => {
165
4bf2173748f3 refactor: extracted the string to milisecondconversion
Thomas Junk <thomas.junk@intevation.de>
parents: 164
diff changeset
26 const expired = "" + Date.now() / 1000 - 60000;
4bf2173748f3 refactor: extracted the string to milisecondconversion
Thomas Junk <thomas.junk@intevation.de>
parents: 164
diff changeset
27 expect(sessionStillActive(toMillisFromString(expired))).toBe(false);
163
30c212a6f580 fix: Bugfix for session evaluation
Thomas Junk <thomas.junk@intevation.de>
parents: 162
diff changeset
28 });