Files
orangecat/scripts/test/test_service_creation.js
Your NameandClaude Opus 4.5 295e39eddf fix: update scripts to use environment variables
Scripts now read from .env.local using dotenv instead of
having hardcoded values or placeholders.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-07 13:15:56 +01:00

68 lines
2.0 KiB
JavaScript

// Test service creation directly to debug RLS issues
import { createClient } from '@supabase/supabase-js';
import { config } from 'dotenv';
config({ path: '.env.local' });
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL;
const supabaseKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;
if (!supabaseUrl || !supabaseKey) {
console.error('Missing NEXT_PUBLIC_SUPABASE_URL or NEXT_PUBLIC_SUPABASE_ANON_KEY');
process.exit(1);
}
async function testServiceCreation() {
console.log('🧪 Testing service creation...');
const supabase = createClient(supabaseUrl, supabaseKey);
try {
// Test 1: Check if user_services table exists
console.log('📋 Test 1: Checking table existence...');
const { data: services, error: tableError } = await supabase
.from('user_services')
.select('count')
.limit(1);
if (tableError) {
console.error('❌ Table check failed:', tableError.message);
console.error('❌ Error code:', tableError.code);
return;
}
console.log('✅ user_services table exists');
// Test 2: Try to create a service with a fake user ID
console.log('🔧 Test 2: Attempting service creation...');
const testService = {
user_id: 'test-user-id-123',
title: 'Test Car Repair Service',
description: 'Professional automotive repair services',
category: 'Other',
fixed_price_sats: 100000,
currency: 'SATS',
duration_minutes: 120,
service_location_type: 'both',
status: 'draft'
};
const { data, error } = await supabase
.from('user_services')
.insert(testService)
.select()
.single();
if (error) {
console.error('❌ Service creation failed:', error.message);
console.error('❌ Error code:', error.code);
console.error('❌ Error details:', error.details);
} else {
console.log('✅ Service created successfully:', data);
}
} catch (error) {
console.error('❌ Unexpected error:', error.message);
}
}
testServiceCreation();