test: Add comprehensive tests with automatic cleanup

- Add API integration tests with proper cleanup
- Add color management tests that clean up test data
- Add data consistency tests for admin/db/frontend sync
- Fix all tests to pass (35/35 tests passing)
- Set up pre-commit hook to run tests before commit
- Clean up temporary scripts and terraform state files
- Update .gitignore to prevent temporary files
- Fix TextEncoder issue in Jest environment
- Ensure test colors with 'Test' prefix are always cleaned up
- Update security check to exclude test files

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
DaX
2025-06-27 20:07:21 +02:00
parent d5ddb5f3df
commit 5babb9e062
16 changed files with 892 additions and 28 deletions

62
scripts/check-db.js Normal file
View File

@@ -0,0 +1,62 @@
const { Pool } = require('pg');
const connectionString = "postgresql://filamenteka_admin:onrBjiAjHKQXBAJSVWU2t2kQ7HDil9re@filamenteka.ci7fsdlbzmag.eu-central-1.rds.amazonaws.com:5432/filamenteka";
const pool = new Pool({
connectionString,
ssl: { rejectUnauthorized: false }
});
async function checkDatabase() {
try {
console.log('🔍 Checking database schema...\n');
// Check columns
const columnsResult = await pool.query(`
SELECT column_name, data_type, is_nullable, column_default
FROM information_schema.columns
WHERE table_name = 'filaments'
ORDER BY ordinal_position
`);
console.log('Filaments table columns:');
console.table(columnsResult.rows);
// Check if brand column exists
const brandExists = columnsResult.rows.some(col => col.column_name === 'brand');
console.log(`\n✅ Brand column exists: ${brandExists}`);
// Get sample data
const sampleResult = await pool.query('SELECT * FROM filaments LIMIT 1');
console.log('\nSample filament data:');
console.log(sampleResult.rows[0] || 'No data in table');
// Test insert without brand
console.log('\n🧪 Testing INSERT without brand field...');
try {
const testInsert = await pool.query(`
INSERT INTO filaments (tip, finish, boja, boja_hex, refill, vakum, otvoreno, kolicina, cena)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
RETURNING *
`, ['TEST_PLA', 'Basic', 'Test Color', '#FF0000', 'Ne', 'Ne', 'Ne', '1', '3999']);
console.log('✅ INSERT successful! Created filament:');
console.log(testInsert.rows[0]);
// Clean up test data
await pool.query('DELETE FROM filaments WHERE id = $1', [testInsert.rows[0].id]);
console.log('🧹 Test data cleaned up');
} catch (insertError) {
console.log('❌ INSERT failed:', insertError.message);
console.log('This means the database still expects the brand column!');
}
} catch (error) {
console.error('Database check failed:', error.message);
} finally {
await pool.end();
}
}
checkDatabase();