- Remove unused imports: LocationSubmission from types, Location/ProfanityWord from server - Remove unused variables: wordText, detectedWords in profanity rejection - Remove unused parameters: req in skip function, wordId/updates in fallback filter - Fix regex escaping and destructuring patterns - Remove unused response variables in tests - Reduce ESLint issues from 45 to 22 (eliminated all 21 errors, keeping only warnings) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
100 lines
No EOL
2.6 KiB
TypeScript
100 lines
No EOL
2.6 KiB
TypeScript
import { Database } from 'sqlite3';
|
|
|
|
// Setup test environment
|
|
process.env.NODE_ENV = 'test';
|
|
process.env.ADMIN_PASSWORD = 'test_admin_password';
|
|
process.env.MAPBOX_ACCESS_TOKEN = 'pk.test_token_here';
|
|
|
|
// Removed unused constants TEST_DB_PATH and TEST_PROFANITY_DB_PATH
|
|
// Helper function to create test database
|
|
export const createTestDatabase = (): Promise<Database> => {
|
|
return new Promise((resolve, reject) => {
|
|
const db = new Database(':memory:', (err) => {
|
|
if (err) {
|
|
reject(err);
|
|
return;
|
|
}
|
|
|
|
// Create locations table
|
|
db.run(`
|
|
CREATE TABLE IF NOT EXISTS locations (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
address TEXT NOT NULL,
|
|
latitude REAL,
|
|
longitude REAL,
|
|
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
description TEXT,
|
|
persistent INTEGER DEFAULT 0,
|
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
)
|
|
`, (err) => {
|
|
if (err) {
|
|
reject(err);
|
|
return;
|
|
}
|
|
resolve(db);
|
|
});
|
|
});
|
|
});
|
|
};
|
|
|
|
// Helper function to create test profanity database
|
|
export const createTestProfanityDatabase = (): Promise<Database> => {
|
|
return new Promise((resolve, reject) => {
|
|
const db = new Database(':memory:', (err) => {
|
|
if (err) {
|
|
reject(err);
|
|
return;
|
|
}
|
|
|
|
// Create profanity_words table
|
|
db.run(`
|
|
CREATE TABLE IF NOT EXISTS profanity_words (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
word TEXT NOT NULL UNIQUE,
|
|
severity TEXT NOT NULL,
|
|
category TEXT NOT NULL,
|
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
created_by TEXT DEFAULT 'system'
|
|
)
|
|
`, (err) => {
|
|
if (err) {
|
|
reject(err);
|
|
return;
|
|
}
|
|
resolve(db);
|
|
});
|
|
});
|
|
});
|
|
};
|
|
|
|
// Cleanup function for tests (in-memory databases don't need file cleanup)
|
|
export const cleanupTestDatabases = () => {
|
|
// Using in-memory databases (:memory:) - no file cleanup needed
|
|
};
|
|
|
|
// Global test cleanup
|
|
afterAll(() => {
|
|
cleanupTestDatabases();
|
|
});
|
|
|
|
// Console override for cleaner test output
|
|
const originalConsoleLog = console.log;
|
|
const originalConsoleError = console.error;
|
|
const originalConsoleWarn = console.warn;
|
|
|
|
beforeAll(() => {
|
|
// Suppress console output during tests unless running in verbose mode
|
|
if (!process.env.VERBOSE_TESTS) {
|
|
console.log = jest.fn();
|
|
console.error = jest.fn();
|
|
console.warn = jest.fn();
|
|
}
|
|
});
|
|
|
|
afterAll(() => {
|
|
// Restore console functions
|
|
console.log = originalConsoleLog;
|
|
console.error = originalConsoleError;
|
|
console.warn = originalConsoleWarn;
|
|
}); |