parent
468e299059
commit
3cc9ec2191
2 changed files with 12 additions and 10 deletions
|
|
@ -14,15 +14,17 @@ beforeAll(async () => {
|
|||
beforeEach(async () => {
|
||||
// Clean all tables except Sessions to avoid conflicts
|
||||
try {
|
||||
const models = Object.values(sequelize.models);
|
||||
const nonSessionModels = models.filter(
|
||||
(model) => model.name !== 'Session'
|
||||
);
|
||||
await Promise.all(
|
||||
nonSessionModels.map((model) =>
|
||||
model.destroy({ truncate: true, cascade: true })
|
||||
)
|
||||
);
|
||||
// Use raw SQL for faster cleanup
|
||||
const tableNames = [
|
||||
'users', 'areas', 'projects', 'tasks', 'tags', 'notes',
|
||||
'inbox_items', 'task_events', 'tasks_tags', 'notes_tags', 'projects_tags'
|
||||
];
|
||||
|
||||
await sequelize.query('PRAGMA foreign_keys = OFF');
|
||||
for (const tableName of tableNames) {
|
||||
await sequelize.query(`DELETE FROM ${tableName}`);
|
||||
}
|
||||
await sequelize.query('PRAGMA foreign_keys = ON');
|
||||
} catch (error) {
|
||||
// Ignore errors during cleanup
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ const { User } = require('../../models');
|
|||
const createTestUser = async (userData = {}) => {
|
||||
const defaultUser = {
|
||||
email: 'test@example.com',
|
||||
password: 'password123', // Use password field to trigger model hook
|
||||
password_digest: '$2b$10$DPcA0XSvK9FT04mLyKGza.uHb8d.bESwP.XdQfQ47.sKVT4fYzbP.', // Pre-computed hash for 'password123'
|
||||
...userData,
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue