@uploadista/client-browser 0.0.20 → 0.1.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -7
- package/src/__tests__/setup.ts +135 -0
- package/src/framework-utils.test.ts +519 -0
- package/src/http-client.test.ts +402 -0
- package/src/http-client.ts +11 -0
- package/src/services/abort-controller-factory.test.ts +163 -0
- package/src/services/checksum-service.test.ts +70 -0
- package/src/services/create-browser-services.test.ts +248 -0
- package/src/services/file-reader.test.ts +171 -0
- package/src/services/fingerprint-service.test.ts +123 -0
- package/src/services/id-generation/id-generation.test.ts +54 -0
- package/src/services/platform-service.test.ts +169 -0
- package/src/services/storage/local-storage-service.test.ts +168 -0
- package/src/services/storage/session-storage-service.test.ts +168 -0
- package/src/services/websocket-factory.test.ts +245 -0
- package/src/utils/hash-util.test.ts +84 -0
- package/vitest.config.ts +3 -1
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { createBrowserPlatformService } from "./platform-service";
|
|
3
|
+
|
|
4
|
+
describe("createBrowserPlatformService", () => {
|
|
5
|
+
it("should create a platform service", () => {
|
|
6
|
+
const service = createBrowserPlatformService();
|
|
7
|
+
expect(service).toBeDefined();
|
|
8
|
+
expect(service.setTimeout).toBeDefined();
|
|
9
|
+
expect(service.clearTimeout).toBeDefined();
|
|
10
|
+
expect(service.isBrowser).toBeDefined();
|
|
11
|
+
expect(service.isOnline).toBeDefined();
|
|
12
|
+
expect(service.isFileLike).toBeDefined();
|
|
13
|
+
expect(service.getFileName).toBeDefined();
|
|
14
|
+
expect(service.getFileType).toBeDefined();
|
|
15
|
+
expect(service.getFileSize).toBeDefined();
|
|
16
|
+
expect(service.getFileLastModified).toBeDefined();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
describe("setTimeout", () => {
|
|
20
|
+
it("should schedule a callback", async () => {
|
|
21
|
+
const service = createBrowserPlatformService();
|
|
22
|
+
const callback = vi.fn();
|
|
23
|
+
|
|
24
|
+
service.setTimeout(callback, 10);
|
|
25
|
+
|
|
26
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
27
|
+
expect(callback).toHaveBeenCalled();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("should return a timeout ID", () => {
|
|
31
|
+
const service = createBrowserPlatformService();
|
|
32
|
+
const callback = vi.fn();
|
|
33
|
+
|
|
34
|
+
const id = service.setTimeout(callback, 1000);
|
|
35
|
+
expect(id).toBeDefined();
|
|
36
|
+
|
|
37
|
+
// Clean up
|
|
38
|
+
service.clearTimeout(id);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe("clearTimeout", () => {
|
|
43
|
+
it("should cancel a scheduled callback", async () => {
|
|
44
|
+
const service = createBrowserPlatformService();
|
|
45
|
+
const callback = vi.fn();
|
|
46
|
+
|
|
47
|
+
const id = service.setTimeout(callback, 50);
|
|
48
|
+
service.clearTimeout(id);
|
|
49
|
+
|
|
50
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
51
|
+
expect(callback).not.toHaveBeenCalled();
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe("isBrowser", () => {
|
|
56
|
+
it("should return true in browser environment", () => {
|
|
57
|
+
const service = createBrowserPlatformService();
|
|
58
|
+
// In happy-dom test environment, window should be defined
|
|
59
|
+
expect(service.isBrowser()).toBe(true);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe("isOnline", () => {
|
|
64
|
+
it("should return online status", () => {
|
|
65
|
+
const service = createBrowserPlatformService();
|
|
66
|
+
// In happy-dom, navigator.onLine should be available
|
|
67
|
+
const result = service.isOnline();
|
|
68
|
+
expect(typeof result).toBe("boolean");
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
describe("isFileLike", () => {
|
|
73
|
+
it("should return true for File objects", () => {
|
|
74
|
+
const service = createBrowserPlatformService();
|
|
75
|
+
const file = new File(["content"], "test.txt", { type: "text/plain" });
|
|
76
|
+
|
|
77
|
+
expect(service.isFileLike(file)).toBe(true);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("should return false for Blob objects", () => {
|
|
81
|
+
const service = createBrowserPlatformService();
|
|
82
|
+
const blob = new Blob(["content"], { type: "text/plain" });
|
|
83
|
+
|
|
84
|
+
expect(service.isFileLike(blob)).toBe(false);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("should return false for non-file values", () => {
|
|
88
|
+
const service = createBrowserPlatformService();
|
|
89
|
+
|
|
90
|
+
expect(service.isFileLike("string")).toBe(false);
|
|
91
|
+
expect(service.isFileLike(123)).toBe(false);
|
|
92
|
+
expect(service.isFileLike(null)).toBe(false);
|
|
93
|
+
expect(service.isFileLike(undefined)).toBe(false);
|
|
94
|
+
expect(service.isFileLike({})).toBe(false);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe("getFileName", () => {
|
|
99
|
+
it("should return file name for File objects", () => {
|
|
100
|
+
const service = createBrowserPlatformService();
|
|
101
|
+
const file = new File(["content"], "test.txt", { type: "text/plain" });
|
|
102
|
+
|
|
103
|
+
expect(service.getFileName(file)).toBe("test.txt");
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("should return undefined for non-File objects", () => {
|
|
107
|
+
const service = createBrowserPlatformService();
|
|
108
|
+
const blob = new Blob(["content"], { type: "text/plain" });
|
|
109
|
+
|
|
110
|
+
expect(service.getFileName(blob)).toBeUndefined();
|
|
111
|
+
expect(service.getFileName("string")).toBeUndefined();
|
|
112
|
+
expect(service.getFileName(null)).toBeUndefined();
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
describe("getFileType", () => {
|
|
117
|
+
it("should return file type for File objects", () => {
|
|
118
|
+
const service = createBrowserPlatformService();
|
|
119
|
+
const file = new File(["content"], "test.txt", { type: "text/plain" });
|
|
120
|
+
|
|
121
|
+
expect(service.getFileType(file)).toBe("text/plain");
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("should return undefined for non-File objects", () => {
|
|
125
|
+
const service = createBrowserPlatformService();
|
|
126
|
+
const blob = new Blob(["content"], { type: "text/plain" });
|
|
127
|
+
|
|
128
|
+
expect(service.getFileType(blob)).toBeUndefined();
|
|
129
|
+
expect(service.getFileType("string")).toBeUndefined();
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
describe("getFileSize", () => {
|
|
134
|
+
it("should return file size for File objects", () => {
|
|
135
|
+
const service = createBrowserPlatformService();
|
|
136
|
+
const content = "Hello, World!";
|
|
137
|
+
const file = new File([content], "test.txt", { type: "text/plain" });
|
|
138
|
+
|
|
139
|
+
expect(service.getFileSize(file)).toBe(content.length);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("should return undefined for non-File objects", () => {
|
|
143
|
+
const service = createBrowserPlatformService();
|
|
144
|
+
const blob = new Blob(["content"], { type: "text/plain" });
|
|
145
|
+
|
|
146
|
+
expect(service.getFileSize(blob)).toBeUndefined();
|
|
147
|
+
expect(service.getFileSize("string")).toBeUndefined();
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
describe("getFileLastModified", () => {
|
|
152
|
+
it("should return last modified for File objects", () => {
|
|
153
|
+
const service = createBrowserPlatformService();
|
|
154
|
+
const file = new File(["content"], "test.txt", { type: "text/plain" });
|
|
155
|
+
|
|
156
|
+
const lastModified = service.getFileLastModified(file);
|
|
157
|
+
expect(typeof lastModified).toBe("number");
|
|
158
|
+
expect(lastModified).toBeGreaterThan(0);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("should return undefined for non-File objects", () => {
|
|
162
|
+
const service = createBrowserPlatformService();
|
|
163
|
+
const blob = new Blob(["content"], { type: "text/plain" });
|
|
164
|
+
|
|
165
|
+
expect(service.getFileLastModified(blob)).toBeUndefined();
|
|
166
|
+
expect(service.getFileLastModified("string")).toBeUndefined();
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
});
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
import { createLocalStorageService } from "./local-storage-service";
|
|
3
|
+
|
|
4
|
+
describe("createLocalStorageService", () => {
|
|
5
|
+
beforeEach(() => {
|
|
6
|
+
localStorage.clear();
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
localStorage.clear();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("should create a storage service", () => {
|
|
14
|
+
const service = createLocalStorageService();
|
|
15
|
+
expect(service).toBeDefined();
|
|
16
|
+
expect(service.getItem).toBeDefined();
|
|
17
|
+
expect(service.setItem).toBeDefined();
|
|
18
|
+
expect(service.removeItem).toBeDefined();
|
|
19
|
+
expect(service.findAll).toBeDefined();
|
|
20
|
+
expect(service.find).toBeDefined();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe("setItem", () => {
|
|
24
|
+
it("should store a value", async () => {
|
|
25
|
+
const service = createLocalStorageService();
|
|
26
|
+
|
|
27
|
+
await service.setItem("key", "value");
|
|
28
|
+
|
|
29
|
+
expect(localStorage.getItem("key")).toBe("value");
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("should overwrite existing value", async () => {
|
|
33
|
+
const service = createLocalStorageService();
|
|
34
|
+
|
|
35
|
+
await service.setItem("key", "value1");
|
|
36
|
+
await service.setItem("key", "value2");
|
|
37
|
+
|
|
38
|
+
expect(localStorage.getItem("key")).toBe("value2");
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe("getItem", () => {
|
|
43
|
+
it("should retrieve a stored value", async () => {
|
|
44
|
+
const service = createLocalStorageService();
|
|
45
|
+
localStorage.setItem("key", "value");
|
|
46
|
+
|
|
47
|
+
const result = await service.getItem("key");
|
|
48
|
+
|
|
49
|
+
expect(result).toBe("value");
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("should return null for non-existent key", async () => {
|
|
53
|
+
const service = createLocalStorageService();
|
|
54
|
+
|
|
55
|
+
const result = await service.getItem("nonexistent");
|
|
56
|
+
|
|
57
|
+
expect(result).toBeNull();
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe("removeItem", () => {
|
|
62
|
+
it("should remove a stored value", async () => {
|
|
63
|
+
const service = createLocalStorageService();
|
|
64
|
+
localStorage.setItem("key", "value");
|
|
65
|
+
|
|
66
|
+
await service.removeItem("key");
|
|
67
|
+
|
|
68
|
+
expect(localStorage.getItem("key")).toBeNull();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("should not throw for non-existent key", async () => {
|
|
72
|
+
const service = createLocalStorageService();
|
|
73
|
+
|
|
74
|
+
await expect(service.removeItem("nonexistent")).resolves.not.toThrow();
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe("findAll", () => {
|
|
79
|
+
it("should return all stored items", async () => {
|
|
80
|
+
const service = createLocalStorageService();
|
|
81
|
+
localStorage.setItem("key1", "value1");
|
|
82
|
+
localStorage.setItem("key2", "value2");
|
|
83
|
+
|
|
84
|
+
const result = await service.findAll();
|
|
85
|
+
|
|
86
|
+
expect(result).toEqual({
|
|
87
|
+
key1: "value1",
|
|
88
|
+
key2: "value2",
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("should return empty object when storage is empty", async () => {
|
|
93
|
+
const service = createLocalStorageService();
|
|
94
|
+
|
|
95
|
+
const result = await service.findAll();
|
|
96
|
+
|
|
97
|
+
expect(result).toEqual({});
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe("find", () => {
|
|
102
|
+
it("should return items matching prefix", async () => {
|
|
103
|
+
const service = createLocalStorageService();
|
|
104
|
+
localStorage.setItem("upload:1", "data1");
|
|
105
|
+
localStorage.setItem("upload:2", "data2");
|
|
106
|
+
localStorage.setItem("other:1", "other");
|
|
107
|
+
|
|
108
|
+
const result = await service.find("upload:");
|
|
109
|
+
|
|
110
|
+
expect(result).toEqual({
|
|
111
|
+
"upload:1": "data1",
|
|
112
|
+
"upload:2": "data2",
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("should return empty object when no matches", async () => {
|
|
117
|
+
const service = createLocalStorageService();
|
|
118
|
+
localStorage.setItem("key", "value");
|
|
119
|
+
|
|
120
|
+
const result = await service.find("nonexistent:");
|
|
121
|
+
|
|
122
|
+
expect(result).toEqual({});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("should return all items with empty prefix", async () => {
|
|
126
|
+
const service = createLocalStorageService();
|
|
127
|
+
localStorage.setItem("key1", "value1");
|
|
128
|
+
localStorage.setItem("key2", "value2");
|
|
129
|
+
|
|
130
|
+
const result = await service.find("");
|
|
131
|
+
|
|
132
|
+
expect(result).toEqual({
|
|
133
|
+
key1: "value1",
|
|
134
|
+
key2: "value2",
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
describe("integration", () => {
|
|
140
|
+
it("should handle JSON data", async () => {
|
|
141
|
+
const service = createLocalStorageService();
|
|
142
|
+
const data = { name: "test", count: 42, items: [1, 2, 3] };
|
|
143
|
+
|
|
144
|
+
await service.setItem("json-key", JSON.stringify(data));
|
|
145
|
+
const retrieved = await service.getItem("json-key");
|
|
146
|
+
|
|
147
|
+
expect(JSON.parse(retrieved!)).toEqual(data);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("should handle multiple operations", async () => {
|
|
151
|
+
const service = createLocalStorageService();
|
|
152
|
+
|
|
153
|
+
await service.setItem("a", "1");
|
|
154
|
+
await service.setItem("b", "2");
|
|
155
|
+
await service.setItem("c", "3");
|
|
156
|
+
|
|
157
|
+
expect(await service.getItem("a")).toBe("1");
|
|
158
|
+
expect(await service.getItem("b")).toBe("2");
|
|
159
|
+
expect(await service.getItem("c")).toBe("3");
|
|
160
|
+
|
|
161
|
+
await service.removeItem("b");
|
|
162
|
+
|
|
163
|
+
const all = await service.findAll();
|
|
164
|
+
expect(Object.keys(all)).toHaveLength(2);
|
|
165
|
+
expect(all.b).toBeUndefined();
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
});
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
import { createSessionStorageService } from "./session-storage-service";
|
|
3
|
+
|
|
4
|
+
describe("createSessionStorageService", () => {
|
|
5
|
+
beforeEach(() => {
|
|
6
|
+
sessionStorage.clear();
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
sessionStorage.clear();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("should create a storage service", () => {
|
|
14
|
+
const service = createSessionStorageService();
|
|
15
|
+
expect(service).toBeDefined();
|
|
16
|
+
expect(service.getItem).toBeDefined();
|
|
17
|
+
expect(service.setItem).toBeDefined();
|
|
18
|
+
expect(service.removeItem).toBeDefined();
|
|
19
|
+
expect(service.findAll).toBeDefined();
|
|
20
|
+
expect(service.find).toBeDefined();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe("setItem", () => {
|
|
24
|
+
it("should store a value", async () => {
|
|
25
|
+
const service = createSessionStorageService();
|
|
26
|
+
|
|
27
|
+
await service.setItem("key", "value");
|
|
28
|
+
|
|
29
|
+
expect(sessionStorage.getItem("key")).toBe("value");
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("should overwrite existing value", async () => {
|
|
33
|
+
const service = createSessionStorageService();
|
|
34
|
+
|
|
35
|
+
await service.setItem("key", "value1");
|
|
36
|
+
await service.setItem("key", "value2");
|
|
37
|
+
|
|
38
|
+
expect(sessionStorage.getItem("key")).toBe("value2");
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe("getItem", () => {
|
|
43
|
+
it("should retrieve a stored value", async () => {
|
|
44
|
+
const service = createSessionStorageService();
|
|
45
|
+
sessionStorage.setItem("key", "value");
|
|
46
|
+
|
|
47
|
+
const result = await service.getItem("key");
|
|
48
|
+
|
|
49
|
+
expect(result).toBe("value");
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("should return null for non-existent key", async () => {
|
|
53
|
+
const service = createSessionStorageService();
|
|
54
|
+
|
|
55
|
+
const result = await service.getItem("nonexistent");
|
|
56
|
+
|
|
57
|
+
expect(result).toBeNull();
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe("removeItem", () => {
|
|
62
|
+
it("should remove a stored value", async () => {
|
|
63
|
+
const service = createSessionStorageService();
|
|
64
|
+
sessionStorage.setItem("key", "value");
|
|
65
|
+
|
|
66
|
+
await service.removeItem("key");
|
|
67
|
+
|
|
68
|
+
expect(sessionStorage.getItem("key")).toBeNull();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("should not throw for non-existent key", async () => {
|
|
72
|
+
const service = createSessionStorageService();
|
|
73
|
+
|
|
74
|
+
await expect(service.removeItem("nonexistent")).resolves.not.toThrow();
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe("findAll", () => {
|
|
79
|
+
it("should return all stored items", async () => {
|
|
80
|
+
const service = createSessionStorageService();
|
|
81
|
+
sessionStorage.setItem("key1", "value1");
|
|
82
|
+
sessionStorage.setItem("key2", "value2");
|
|
83
|
+
|
|
84
|
+
const result = await service.findAll();
|
|
85
|
+
|
|
86
|
+
expect(result).toEqual({
|
|
87
|
+
key1: "value1",
|
|
88
|
+
key2: "value2",
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("should return empty object when storage is empty", async () => {
|
|
93
|
+
const service = createSessionStorageService();
|
|
94
|
+
|
|
95
|
+
const result = await service.findAll();
|
|
96
|
+
|
|
97
|
+
expect(result).toEqual({});
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe("find", () => {
|
|
102
|
+
it("should return items matching prefix", async () => {
|
|
103
|
+
const service = createSessionStorageService();
|
|
104
|
+
sessionStorage.setItem("temp:1", "data1");
|
|
105
|
+
sessionStorage.setItem("temp:2", "data2");
|
|
106
|
+
sessionStorage.setItem("other:1", "other");
|
|
107
|
+
|
|
108
|
+
const result = await service.find("temp:");
|
|
109
|
+
|
|
110
|
+
expect(result).toEqual({
|
|
111
|
+
"temp:1": "data1",
|
|
112
|
+
"temp:2": "data2",
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("should return empty object when no matches", async () => {
|
|
117
|
+
const service = createSessionStorageService();
|
|
118
|
+
sessionStorage.setItem("key", "value");
|
|
119
|
+
|
|
120
|
+
const result = await service.find("nonexistent:");
|
|
121
|
+
|
|
122
|
+
expect(result).toEqual({});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("should return all items with empty prefix", async () => {
|
|
126
|
+
const service = createSessionStorageService();
|
|
127
|
+
sessionStorage.setItem("key1", "value1");
|
|
128
|
+
sessionStorage.setItem("key2", "value2");
|
|
129
|
+
|
|
130
|
+
const result = await service.find("");
|
|
131
|
+
|
|
132
|
+
expect(result).toEqual({
|
|
133
|
+
key1: "value1",
|
|
134
|
+
key2: "value2",
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
describe("integration", () => {
|
|
140
|
+
it("should handle JSON data", async () => {
|
|
141
|
+
const service = createSessionStorageService();
|
|
142
|
+
const data = { name: "test", count: 42, items: [1, 2, 3] };
|
|
143
|
+
|
|
144
|
+
await service.setItem("json-key", JSON.stringify(data));
|
|
145
|
+
const retrieved = await service.getItem("json-key");
|
|
146
|
+
|
|
147
|
+
expect(JSON.parse(retrieved!)).toEqual(data);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("should handle multiple operations", async () => {
|
|
151
|
+
const service = createSessionStorageService();
|
|
152
|
+
|
|
153
|
+
await service.setItem("a", "1");
|
|
154
|
+
await service.setItem("b", "2");
|
|
155
|
+
await service.setItem("c", "3");
|
|
156
|
+
|
|
157
|
+
expect(await service.getItem("a")).toBe("1");
|
|
158
|
+
expect(await service.getItem("b")).toBe("2");
|
|
159
|
+
expect(await service.getItem("c")).toBe("3");
|
|
160
|
+
|
|
161
|
+
await service.removeItem("b");
|
|
162
|
+
|
|
163
|
+
const all = await service.findAll();
|
|
164
|
+
expect(Object.keys(all)).toHaveLength(2);
|
|
165
|
+
expect(all.b).toBeUndefined();
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
});
|