Add project sorting migration and a few tests (#192)
* Add necessary migrations for project model. * Add a few tests for project model new columns. --------- Co-authored-by: antanst <>
This commit is contained in:
parent
ffcab4caac
commit
1e11ab5fa4
2 changed files with 83 additions and 0 deletions
|
|
@ -0,0 +1,39 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
async up(queryInterface, Sequelize) {
|
||||
try {
|
||||
const tableInfo = await queryInterface.describeTable('projects');
|
||||
|
||||
// Check if task_show_completed column already exists
|
||||
if (!('task_show_completed' in tableInfo)) {
|
||||
await queryInterface.addColumn(
|
||||
'projects',
|
||||
'task_show_completed',
|
||||
{
|
||||
type: Sequelize.BOOLEAN,
|
||||
allowNull: true,
|
||||
defaultValue: false,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Check if task_sort_order column already exists
|
||||
if (!('task_sort_order' in tableInfo)) {
|
||||
await queryInterface.addColumn('projects', 'task_sort_order', {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: true,
|
||||
defaultValue: 'created_at:desc',
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.log('Migration error:', error.message);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
async down(queryInterface, Sequelize) {
|
||||
await queryInterface.removeColumn('projects', 'task_show_completed');
|
||||
await queryInterface.removeColumn('projects', 'task_sort_order');
|
||||
},
|
||||
};
|
||||
|
|
@ -87,6 +87,8 @@ describe('Project Model', () => {
|
|||
|
||||
expect(project.active).toBe(false);
|
||||
expect(project.pin_to_sidebar).toBe(false);
|
||||
expect(project.task_show_completed).toBe(false);
|
||||
expect(project.task_sort_order).toBe('created_at:desc');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -108,6 +110,48 @@ describe('Project Model', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('task sorting columns', () => {
|
||||
it('should create project with task_show_completed set to true', async () => {
|
||||
const project = await Project.create({
|
||||
name: 'Test Project',
|
||||
user_id: user.id,
|
||||
task_show_completed: true,
|
||||
});
|
||||
|
||||
expect(project.task_show_completed).toBe(true);
|
||||
});
|
||||
|
||||
it('should create project with custom task_sort_order', async () => {
|
||||
const project = await Project.create({
|
||||
name: 'Test Project',
|
||||
user_id: user.id,
|
||||
task_sort_order: 'priority:asc',
|
||||
});
|
||||
|
||||
expect(project.task_sort_order).toBe('priority:asc');
|
||||
});
|
||||
|
||||
it('should allow task_show_completed to be null', async () => {
|
||||
const project = await Project.create({
|
||||
name: 'Test Project',
|
||||
user_id: user.id,
|
||||
task_show_completed: null,
|
||||
});
|
||||
|
||||
expect(project.task_show_completed).toBeNull();
|
||||
});
|
||||
|
||||
it('should allow task_sort_order to be null', async () => {
|
||||
const project = await Project.create({
|
||||
name: 'Test Project',
|
||||
user_id: user.id,
|
||||
task_sort_order: null,
|
||||
});
|
||||
|
||||
expect(project.task_sort_order).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('associations', () => {
|
||||
it('should belong to a user', async () => {
|
||||
const project = await Project.create({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue