Skip to content

Commit

Permalink
feat: rename event types
Browse files Browse the repository at this point in the history
  • Loading branch information
maaikeheijdenrijk committed Mar 8, 2020
1 parent 00d2a8c commit 649ca96
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 31 deletions.
2 changes: 1 addition & 1 deletion lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ module.exports = {
'application_status',
'status'
],
EVENT_TYPES: ['wu', 'es', 'nwm', 'ltc', 'rtc', 'european'],
EVENT_TYPES: ['training', 'nwm', 'conference', 'cultural'],
CURRENT_USER_PREFIX: 'me'
};
33 changes: 33 additions & 0 deletions migrations/20200307165339-change-event-names.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.changeColumn(
'events',
'type',
{ type: Sequelize.TEXT }
);
await queryInterface.sequelize.query('drop type enum_events_type;');
await queryInterface.sequelize.query('update events set type = \'training\' where type in (\'es\', \'ltc\', \'rtc\' );');
await queryInterface.sequelize.query('update events set type = \'conference\' where type in (\'european\' );');
await queryInterface.sequelize.query('update events set type = \'cultural\' where type in (\'wu\');');
await queryInterface.changeColumn(
'events',
'type',
{ type: Sequelize.ENUM('training', 'nwm', 'conference', 'cultural'), allowNull: false }
);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.changeColumn(
'events',
'type',
{ type: Sequelize.TEXT }
);
await queryInterface.sequelize.query('drop type enum_events_type;');
await queryInterface.sequelize.query('update events set type = \'european\' where type in (\'training\', \'cultural\', \'conference\' ;');
await queryInterface.changeColumn(
'events',
'type',
{ type: Sequelize.ENUM('wu', 'es', 'nwm', 'ltc', 'rtc', 'european'), allowNull: false }
);
}
};
6 changes: 3 additions & 3 deletions models/Event.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,14 @@ const Event = sequelize.define('event', {
}
},
type: {
type: Sequelize.ENUM('wu', 'es', 'nwm', 'ltc', 'rtc', 'european'),
type: Sequelize.ENUM('training', 'nwm', 'conference', 'cultural'),
allowNull: false,
defaultValue: '',
validate: {
notEmpty: { msg: 'Event type should be set.' },
isIn: {
args: [['wu', 'es', 'nwm', 'ltc', 'rtc', 'european']],
msg: 'Event type should be one of these: "wu", "es", "nwm", "ltc", "rtc", "european".'
args: [['training', 'nwm', 'conference', 'cultural']],
msg: 'Event type should be one of these: training, nwm, conference, cultural.'
}
}
},
Expand Down
8 changes: 4 additions & 4 deletions test/api/events-listing.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ describe('Events listing', () => {
});

it('should display only specified event types if specified and if multiple types are specified', async () => {
await generator.createEvent({ status: 'published', type: 'ltc' });
const event = await generator.createEvent({ status: 'published', type: 'es' });
await generator.createEvent({ status: 'published', type: 'cultural' });
const event = await generator.createEvent({ status: 'published', type: 'training' });

const res = await request({
uri: '/?type[]=es',
Expand All @@ -206,8 +206,8 @@ describe('Events listing', () => {
});

it('should display only specified event types if specified and if single type is specified', async () => {
await generator.createEvent({ status: 'published', type: 'ltc' });
const event = await generator.createEvent({ status: 'published', type: 'es' });
await generator.createEvent({ status: 'published', type: 'cultural' });
const event = await generator.createEvent({ status: 'published', type: 'training' });

const res = await request({
uri: '/?type=es',
Expand Down
84 changes: 62 additions & 22 deletions test/assets/oms-core-permissions-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,7 @@
"circles": null,
"always_assigned": false,
"action": "manage_event"
}, {
"scope": "global",
"object": "ltc",
"id": 71,
"filters": [],
"description": "Manage event",
"combined": "global:manage_event:ltc",
"circles": null,
"always_assigned": false,
"action": "manage_event"
}, {
}, {
"scope": "global",
"object": "rtc",
"id": 71,
Expand Down Expand Up @@ -230,16 +220,6 @@
"circles": null,
"always_assigned": false,
"action": "approve_event"
}, {
"scope": "global",
"object": "ltc",
"id": 71,
"filters": [],
"description": "Approve event",
"combined": "global:approve_event:ltc",
"circles": null,
"always_assigned": false,
"action": "approve_event"
}, {
"scope": "global",
"object": "rtc",
Expand Down Expand Up @@ -310,5 +290,65 @@
"circles": null,
"always_assigned": false,
"action": "manage_event"
}]
}, {
"scope": "global",
"object": "training",
"id": 71,
"filters": [],
"description": "Approve event",
"combined": "global:approve_event:training",
"circles": null,
"always_assigned": false,
"action": "approve_event"
}, {
"scope": "global",
"object": "training",
"id": 71,
"filters": [],
"description": "Manage event",
"combined": "global:manage_event:training",
"circles": null,
"always_assigned": false,
"action": "manage_event"
}, {
"scope": "global",
"object": "conference",
"id": 71,
"filters": [],
"description": "Approve event",
"combined": "global:approve_event:conference",
"circles": null,
"always_assigned": false,
"action": "approve_event"
}, {
"scope": "global",
"object": "conference",
"id": 71,
"filters": [],
"description": "Manage event",
"combined": "global:manage_event:conference",
"circles": null,
"always_assigned": false,
"action": "manage_event"
}, {
"scope": "global",
"object": "cultural",
"id": 71,
"filters": [],
"description": "Approve event",
"combined": "global:approve_event:cultural",
"circles": null,
"always_assigned": false,
"action": "approve_event"
},{
"scope": "global",
"object": "cultural",
"id": 71,
"filters": [],
"description": "Manage event",
"combined": "global:manage_event:cultural",
"circles": null,
"always_assigned": false,
"action": "manage_event"
}]
}
2 changes: 1 addition & 1 deletion test/scripts/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ exports.generateEvent = (options = {}) => {
if (notSet(options.application_ends)) options.application_ends = faker.date.future(null, options.application_starts);
if (notSet(options.starts)) options.starts = faker.date.future(null, options.application_ends);
if (notSet(options.ends)) options.ends = faker.date.future(null, options.starts);
if (notSet(options.type)) options.type = faker.random.arrayElement(['wu', 'es', 'nwm', 'ltc', 'rtc', 'european']);
if (notSet(options.type)) options.type = faker.random.arrayElement(['training', 'nwm', 'conference', 'cultural']);
if (notSet(options.fee)) options.fee = faker.random.number({ min: 0, max: 100 });
if (notSet(options.organizing_bodies)) {
options.organizing_bodies = [{
Expand Down

0 comments on commit 649ca96

Please sign in to comment.