blob: 6c10d9a5a8eb37b82952f1982163ada287bed0c3 [file] [log] [blame]
Akron7650eaa2020-10-19 17:10:30 +02001define(['session'], function (sessionClass) {
2
3 beforeEach(
4 function () {
5 document.cookie.split(';').forEach(
6 function (i) {
7 var pair = i.split('=');
8 var name = pair[0].trim().toLowerCase();
9
10 }
11 );
12 }
13 );
14
15 describe('KorAP.Session', function () {
16 it('should be initializable', function () {
17 let s = sessionClass.create();
18
19 expect(s).toBeTruthy();
20
21 expect(s.toString().startsWith('korap=')).toBeTruthy();
22
23 s = sessionClass.create('kalamar');
24
25 expect(s).toBeTruthy();
26
27 expect(s.toString().startsWith('kalamar=')).toBeTruthy();
28 });
29
30 it('should settable and gettable', function () {
31 let s = sessionClass.create('koraptest');
32 s.set("test1", "works");
33
34 expect(s.get("test1")).toEqual("works");
35
36 s.set("test2", "\"wor}ks\"");
37
38 expect(s.get("test1")).toEqual("works");
39 expect(s.get("test2")).toEqual("\"wor}ks\"");
40
41 expect(s.toString().includes("test1")).toBeTruthy();
42 expect(s.toString().includes("test2")).toBeTruthy();
43 expect(s.toString().includes("works")).toBeTruthy();
44 expect(s.toString().includes("%5C%22wor%7Dks%5C%22")).toBeTruthy();
45 });
46
47 it('should write to cookie', function () {
48 let s = sessionClass.create('koraptest');
49 s.clear();
50 expect(s.toString().includes("koraptest=%7B%7D;")).toBeTruthy();
51 expect(document.cookie.includes("koraptest=")).toBeTruthy();
52 s.set("test3", "works");
53 expect(s.toString().includes("koraptest=%7B%7D;")).toBeFalsy();
54 expect(s.toString().includes("koraptest=%7B%22test3%22%3A%22works%22%7D")).toBeTruthy();
55 expect(document.cookie.includes("koraptest=%7B%22test3%22%3A%22works%22%7D")).toBeTruthy();
56 s.clear();
57 expect(document.cookie.includes("koraptest=")).toBeTruthy();
Helge9c0a19c2024-10-08 13:14:44 +020058 expect(s.toString()).toEqual("koraptest=%7B%7D;SameSite=Lax;path=/");
59 });
60
61 /*
62 * The cookie path should by default be '/'. The path should be settable.
63 */
64 it('cookie path should have default and be settable', function(){
65 //cookie should be created with the default path=/
66 let c = sessionClass.create("cookwithoutp");
67 c.clear();
68 expect(c.toString().includes("path=/")).toBeTruthy();
69 //the path should be settable
70 let d = sessionClass.create("cookwithp", "/instance/blub");
71 d.clear();
72 expect(d.toString().includes("path=/instance/blub")).toBeTruthy();
73 });
74
Akron7650eaa2020-10-19 17:10:30 +020075 })
Helge9c0a19c2024-10-08 13:14:44 +020076
Akron7650eaa2020-10-19 17:10:30 +020077});