-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-undo-endpoint.js
More file actions
57 lines (53 loc) · 1.5 KB
/
test-undo-endpoint.js
File metadata and controls
57 lines (53 loc) · 1.5 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
54
55
56
57
// Simple test script to verify the undo endpoint
const { undoChange } = require('./dist/services/trackedChangesService');
// Mock environment for testing
const mockEnv = {
R2: {
list: async () => ({
objects: [
{ key: 'tracked-changes/submission/test-submission/test-change' }
]
}),
get: async () => ({
json: async () => ({
id: 'test-change',
submissionId: 'test-submission',
field: 'content',
oldValue: 'old content',
newValue: 'new content',
changedBy: 'user1',
changedByName: 'User One',
timestamp: new Date().toISOString(),
status: 'approved',
approvedBy: 'user2',
approvedByName: 'User Two',
approvedAt: new Date().toISOString()
})
}),
put: async () => undefined,
delete: async () => undefined
},
CACHE: {
get: async () => null,
put: async () => undefined,
delete: async () => undefined,
list: async () => ({ keys: [] })
}
};
async function testUndo() {
try {
console.log('Testing undo functionality...');
const result = await undoChange('test-change', mockEnv);
if (result) {
console.log('✅ Undo successful!');
console.log('Status:', result.status);
console.log('Approved by:', result.approvedBy);
console.log('Approved at:', result.approvedAt);
} else {
console.log('❌ Undo failed - returned null');
}
} catch (error) {
console.error('❌ Error testing undo:', error);
}
}
testUndo();