-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathtest-storage-aliases.ts
More file actions
45 lines (34 loc) · 1.15 KB
/
test-storage-aliases.ts
File metadata and controls
45 lines (34 loc) · 1.15 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
import { defineHandler } from 'nitro/h3';
import { useStorage } from 'nitro/storage';
export default defineHandler(async () => {
const storage = useStorage('cache');
const results: Record<string, unknown> = {};
// Test set (alias for setItem)
await storage.set('alias:user', { name: 'Jane Doe', role: 'admin' });
results.set = 'success';
// Test get (alias for getItem)
const user = await storage.get('alias:user');
results.get = user;
// Test has (alias for hasItem)
const hasUser = await storage.has('alias:user');
results.has = hasUser;
// Setup for delete tests
await storage.set('alias:temp1', 'temp1');
await storage.set('alias:temp2', 'temp2');
// Test del (alias for removeItem)
await storage.del('alias:temp1');
results.del = 'success';
// Test remove (alias for removeItem)
await storage.remove('alias:temp2');
results.remove = 'success';
// Verify deletions worked
const hasTemp1 = await storage.has('alias:temp1');
const hasTemp2 = await storage.has('alias:temp2');
results.verifyDeletions = !hasTemp1 && !hasTemp2;
// Clean up
await storage.clear();
return {
success: true,
results,
};
});