-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-org-with-extra-fields.js
More file actions
77 lines (66 loc) · 1.97 KB
/
test-org-with-extra-fields.js
File metadata and controls
77 lines (66 loc) · 1.97 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
// Test organization creation with extra fields to satisfy triggers
const { createClient } = require('@supabase/supabase-js');
async function testOrgWithExtraFields() {
console.log('Testing organization creation with extra fields...');
const supabase = createClient(
process.env.NEXT_PUBLIC_SUPABASE_URL,
process.env.SUPABASE_SERVICE_ROLE_KEY,
{
auth: {
autoRefreshToken: false,
persistSession: false,
},
}
);
try {
const orgName = `Test Org ${Date.now()}`;
const orgSlug = `test-org-${Date.now()}`;
// Try different combinations to see if we can satisfy the trigger
const testCases = [
{
name: 'With metadata',
data: {
name: orgName,
slug: orgSlug,
metadata: {},
settings: {},
}
},
{
name: 'With all optional fields',
data: {
name: orgName + '-full',
slug: orgSlug + '-full',
domain: null,
logo_url: null,
settings: {},
metadata: {},
subscription_status: 'trial',
}
}
];
for (const testCase of testCases) {
console.log(`\nTesting: ${testCase.name}`);
console.log('Data:', testCase.data);
const { data: orgData, error: orgError } = await supabase
.from('organizations')
.insert(testCase.data)
.select()
.single();
if (orgError) {
console.error(`❌ ${testCase.name} failed:`, orgError.message);
} else {
console.log(`✅ ${testCase.name} succeeded:`, orgData);
// Clean up
await supabase.from('organizations').delete().eq('id', orgData.id);
console.log('✅ Cleaned up');
break; // If one succeeds, no need to test others
}
}
} catch (error) {
console.error('General error:', error);
}
}
// Load environment variables
require('dotenv').config({ path: '.env.local' });
testOrgWithExtraFields();