-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathtest-storage.ts
More file actions
53 lines (40 loc) · 1.31 KB
/
test-storage.ts
File metadata and controls
53 lines (40 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { defineHandler } from 'nitro/h3';
import { useStorage } from 'nitro/storage';
export default defineHandler(async () => {
const storage = useStorage('cache');
const results: Record<string, unknown> = {};
// Test setItem
await storage.setItem('user:123', { name: 'John Doe', email: '[email protected]' });
results.setItem = 'success';
// Test setItemRaw
await storage.setItemRaw('raw:data', Buffer.from('raw data'));
results.setItemRaw = 'success';
// Manually set batch items
await storage.setItem('batch:1', 'value1');
await storage.setItem('batch:2', 'value2');
// Test hasItem
const hasUser = await storage.hasItem('user:123');
results.hasItem = hasUser;
// Test getItem
const user = await storage.getItem('user:123');
results.getItem = user;
// Test getItemRaw
const rawData = await storage.getItemRaw('raw:data');
results.getItemRaw = rawData?.toString();
// Test getKeys
const keys = await storage.getKeys('batch:');
results.getKeys = keys;
// Test removeItem
await storage.removeItem('batch:1');
results.removeItem = 'success';
// Test clear
await storage.clear();
results.clear = 'success';
// Verify clear worked
const keysAfterClear = await storage.getKeys();
results.keysAfterClear = keysAfterClear;
return {
success: true,
results,
};
});