Repository navigation
Expand file tree
/
Copy pathverify_backend_v2.js
More file actions
104 lines (88 loc) · 3.71 KB
/
Copy pathverify_backend_v2.js
File metadata and controls
104 lines (88 loc) · 3.71 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { createClient } from '@supabase/supabase-js';
import fs from 'fs';
import path from 'path';
// Parse .env manually from workspace
const envPath = path.resolve('.env');
const env = {};
if (fs.existsSync(envPath)) {
const envContent = fs.readFileSync(envPath, 'utf-8');
envContent.split(/\r?\n/).forEach(line => {
const parts = line.split('=');
if (parts.length >= 2) {
const key = parts[0].trim();
const val = parts.slice(1).join('=').trim().replace(/^['"]|['"]$/g, '');
if (key && val) {
env[key] = val;
}
}
});
}
const supabaseUrl = env.VITE_SUPABASE_URL;
const supabaseKey = env.VITE_SUPABASE_ANON_KEY;
if (!supabaseUrl || !supabaseKey) {
console.error("Error: Missing VITE_SUPABASE_URL or VITE_SUPABASE_ANON_KEY in .env!");
process.exit(1);
}
const supabase = createClient(supabaseUrl, supabaseKey);
async function runVerification() {
console.log('Starting Backend Verification...');
let docId = null;
try {
// 1. Test Storage Upload
console.log('\n[1/4] Testing Storage Upload...');
const fileName = `test_verification_${Date.now()}.txt`;
const { data: storageData, error: storageError } = await supabase.storage
.from('documents')
.upload(`uploads/${fileName}`, Buffer.from('verification test content')); // Node global Buffer
if (storageError) throw new Error(`Storage Upload Failed: ${storageError.message}`);
console.log('✅ Storage Upload Success:', storageData.path);
// 2. Test Document Insert (DB)
console.log('\n[2/4] Testing Database Insert (Documents)...');
const { data: docData, error: docError } = await supabase
.from('documents')
.insert({
name: 'Verification Test Doc',
file_path: storageData.path,
file_size: 1024,
file_type: 'text/plain',
share_link: Math.random().toString(36).substring(7),
allow_download: true,
is_encrypted: false
})
.select()
.single();
if (docError) throw new Error(`Document Insert Failed: ${docError.message}`);
docId = docData.id;
console.log('✅ Document Insert Success:', docId);
// 3. Test Signer Insert (DB)
console.log('\n[3/4] Testing Database Insert (Signers)...');
const { data: signerData, error: signerError } = await supabase
.from('document_signers')
.insert({
document_id: docId,
signer_name: 'Test Signer',
signer_email: 'test@example.com',
signing_order: 1,
status: 'pending',
signing_link: Math.random().toString(36).substring(7)
})
.select();
if (signerError) throw new Error(`Signer Insert Failed: ${signerError.message}`);
console.log('✅ Signer Insert Success');
// 4. Cleanup
console.log('\n[4/4] Cleaning up...');
// Delete signer
await supabase.from('document_signers').delete().eq('document_id', docId);
// Delete document (should cascade delete signers actually, but safety first)
await supabase.from('documents').delete().eq('id', docId);
// Delete file
await supabase.storage.from('documents').remove([storageData.path]);
console.log('✅ Cleanup Success');
console.log('\n🎉 ALL BACKEND FEATURES VERIFIED SUCCESSFULLY!');
} catch (error) {
console.error('\n❌ VERIFICATION FAILED:', error.message);
console.error(JSON.stringify(error, null, 2));
process.exit(1);
}
}
runVerification();