Skip to content

Commit

Permalink
fix(event): add publication_date (#603)
Browse files Browse the repository at this point in the history
* fix(event): add publication_date

* style(eslint): fix linter
  • Loading branch information
WikiRik committed Oct 22, 2021
1 parent 0bb5035 commit 25b5615
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module.exports = {
'max_participants',
'application_status',
'status',
'publication_date',
'meals_per_day',
'accommodation_type',
'optional_programme',
Expand Down
4 changes: 4 additions & 0 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,10 @@ exports.setApprovalStatus = async (req, res) => {
}
});

if (req.event.status === 'published') {
await req.event.update({ publication_date: new Date() }, { transaction: t });
}

// If the new status is submitted and the old status is draft, send a mail
// to those who have permissions (EQAC/CD)
if (oldStatus !== 'draft' || req.event.status !== 'submitted') {
Expand Down
12 changes: 12 additions & 0 deletions migrations/20211021185321-add-publication-date-to-event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.addColumn(
'events',
'publication_date',
{ type: Sequelize.DATE, allowNull: true }
);
},
down: (queryInterface) => {
queryInterface.removeColumn('events', 'publication_date');
}
};
7 changes: 7 additions & 0 deletions models/Event.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,13 @@ const Event = sequelize.define('event', {
}
}
},
publication_date: {
type: Sequelize.DATE,
allowNull: true,
validate: {
isDate: { msg: 'Event publication date should be valid.' }
}
},
deleted: {
type: Sequelize.BOOLEAN,
allowNull: false,
Expand Down
42 changes: 42 additions & 0 deletions test/api/events-approval.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,27 @@ describe('Events status change', () => {
const eventFromDb = await Event.findByPk(event.id);
expect(eventFromDb.status).not.toEqual('submitted');
});

it('should not set the publication date', async () => {
const event = await generator.createEvent({
status: 'draft',
organizers: [{ user_id: 1337, first_name: 'test', last_name: 'test' }]
});

const res = await request({
uri: '/single/' + event.id + '/status',
headers: { 'X-Auth-Token': 'foobar' },
method: 'PUT',
body: { status: 'submitted' }
});

expect(res.statusCode).toEqual(200);
expect(res.body.success).toEqual(true);
expect(res.body).toHaveProperty('message');

const eventFromDb = await Event.findByPk(event.id);
expect(eventFromDb.publication_date).toBeNull();
});
});

describe('draft -> published', () => {
Expand Down Expand Up @@ -207,6 +228,27 @@ describe('Events status change', () => {
const eventFromDb = await Event.findByPk(event.id);
expect(eventFromDb.status).not.toEqual('published');
});

it('should set the publication date', async () => {
const event = await generator.createEvent({
status: 'submitted',
organizers: [{ user_id: 1337, first_name: 'test', last_name: 'test' }]
});

const res = await request({
uri: '/single/' + event.id + '/status',
headers: { 'X-Auth-Token': 'foobar' },
method: 'PUT',
body: { status: 'published' }
});

expect(res.statusCode).toEqual(200);
expect(res.body.success).toEqual(true);
expect(res.body).toHaveProperty('message');

const eventFromDb = await Event.findByPk(event.id);
expect(eventFromDb.publication_date).not.toBeNull();
});
});

describe('submitted -> draft', () => {
Expand Down

0 comments on commit 25b5615

Please sign in to comment.