Skip to content

Commit

Permalink
fix(application): added application consent. Fixes HELP-598
Browse files Browse the repository at this point in the history
  • Loading branch information
serge1peshcoff committed Aug 14, 2019
1 parent f8b44fb commit a952bf8
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
up: (queryInterface, Sequelize) => queryInterface.addColumn(
'applications',
'agreed_to_privacy_policy',
{ type: Sequelize.BOOLEAN, allowNull: false, defaultValue: false }
),
down: queryInterface => queryInterface.removeColumn('applications', 'agreed_to_privacy_policy')
};
12 changes: 12 additions & 0 deletions models/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,18 @@ const Application = sequelize.define('application', {
}
}
},
agreed_to_privacy_policy: {
allowNull: false,
type: Sequelize.BOOLEAN,
defaultValue: '',
validate: {
isValid(value) {
if (value !== true) {
throw new Error('You should agree to Privacy Policy.');
}
}
}
}
}, {
underscored: true,
tableName: 'applications',
Expand Down
2 changes: 1 addition & 1 deletion models/Event.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ const Event = sequelize.define('event', {
? 'open'
: 'closed'; // inclusive
}
},
}
}, {
underscored: true,
tableName: 'events',
Expand Down
71 changes: 56 additions & 15 deletions test/api/applications-setting.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ describe('Events application create/update', () => {
method: 'PUT',
body: {
body_id: 1337,
answers: ['test']
answers: ['test'],
agreed_to_privacy_policy: true
}
});

Expand Down Expand Up @@ -124,7 +125,8 @@ describe('Events application create/update', () => {
method: 'PUT',
body: {
body_id: user.bodies[0].id,
answers: ['test']
answers: ['test'],
agreed_to_privacy_policy: true
}
});

Expand All @@ -139,6 +141,32 @@ describe('Events application create/update', () => {
expect(applicationFromDb.answers[0]).toEqual('test');
});

it('should return 422 if agreed_to_privacy_policy = false', async () => {
const event = await generator.createEvent({
application_starts: moment().subtract(1, 'weeks').toDate(),
application_ends: moment().add(1, 'week').toDate(),
status: 'published',
questions: []
});

const res = await request({
uri: '/single/' + event.id + '/applications/mine',
headers: { 'X-Auth-Token': 'foobar' },
method: 'PUT',
body: {
body_id: user.bodies[0].id,
answers: [],
agreed_to_privacy_policy: false
}
});

expect(res.statusCode).toEqual(422);

expect(res.body.success).toEqual(false);
expect(res.body).toHaveProperty('errors');
expect(res.body.errors).toHaveProperty('agreed_to_privacy_policy');
});

it('should return 422 if answers is not an array', async () => {
const event = await generator.createEvent({
application_starts: moment().subtract(1, 'weeks').toDate(),
Expand All @@ -157,7 +185,8 @@ describe('Events application create/update', () => {
method: 'PUT',
body: {
body_id: user.bodies[0].id,
answers: false
answers: false,
agreed_to_privacy_policy: true
}
});

Expand Down Expand Up @@ -186,7 +215,8 @@ describe('Events application create/update', () => {
method: 'PUT',
body: {
body_id: user.bodies[0].id,
answers: []
answers: [],
agreed_to_privacy_policy: true
}
});

Expand Down Expand Up @@ -215,7 +245,8 @@ describe('Events application create/update', () => {
method: 'PUT',
body: {
body_id: user.bodies[0].id,
answers: [false]
answers: [false],
agreed_to_privacy_policy: true
}
});

Expand Down Expand Up @@ -244,7 +275,8 @@ describe('Events application create/update', () => {
method: 'PUT',
body: {
body_id: user.bodies[0].id,
answers: [false]
answers: [false],
agreed_to_privacy_policy: true
}
});

Expand Down Expand Up @@ -273,7 +305,8 @@ describe('Events application create/update', () => {
method: 'PUT',
body: {
body_id: user.bodies[0].id,
answers: ['']
answers: [''],
agreed_to_privacy_policy: true
}
});

Expand Down Expand Up @@ -302,7 +335,8 @@ describe('Events application create/update', () => {
method: 'PUT',
body: {
body_id: user.bodies[0].id,
answers: ['']
answers: [''],
agreed_to_privacy_policy: true
}
});

Expand Down Expand Up @@ -331,7 +365,8 @@ describe('Events application create/update', () => {
method: 'PUT',
body: {
body_id: user.bodies[0].id,
answers: [false]
answers: [false],
agreed_to_privacy_policy: true
}
});

Expand Down Expand Up @@ -360,7 +395,8 @@ describe('Events application create/update', () => {
method: 'PUT',
body: {
body_id: user.bodies[0].id,
answers: [1]
answers: [1],
agreed_to_privacy_policy: true
}
});

Expand Down Expand Up @@ -389,7 +425,8 @@ describe('Events application create/update', () => {
method: 'PUT',
body: {
body_id: user.bodies[0].id,
answers: ['second']
answers: ['second'],
agreed_to_privacy_policy: true
}
});

Expand Down Expand Up @@ -419,7 +456,8 @@ describe('Events application create/update', () => {
method: 'PUT',
body: {
body_id: user.bodies[0].id,
answers: ['first']
answers: ['first'],
agreed_to_privacy_policy: true
}
});

Expand Down Expand Up @@ -447,7 +485,8 @@ describe('Events application create/update', () => {
method: 'PUT',
body: {
body_id: user.bodies[0].id,
answers: ['second']
answers: ['second'],
agreed_to_privacy_policy: true
}
});

Expand Down Expand Up @@ -476,7 +515,8 @@ describe('Events application create/update', () => {
method: 'PUT',
body: {
body_id: user.bodies[0].id,
answers: [false]
answers: [false],
agreed_to_privacy_policy: true
}
});

Expand Down Expand Up @@ -505,7 +545,8 @@ describe('Events application create/update', () => {
method: 'PUT',
body: {
body_id: user.bodies[0].id,
answers: [true]
answers: [true],
agreed_to_privacy_policy: true
}
});

Expand Down
1 change: 1 addition & 0 deletions test/scripts/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ exports.generateApplication = (options = {}, event) => {
if (notSet(options.first_name)) options.first_name = faker.lorem.sentence();
if (notSet(options.last_name)) options.last_name = faker.lorem.sentence();
if (notSet(options.body_name)) options.body_name = faker.lorem.sentence();
if (notSet(options.agreed_to_privacy_policy)) options.agreed_to_privacy_policy = true;

if (notSet(options.answers)) {
const answersCount = event ? event.questions.length : Math.round(Math.random() * 5) + 1; // from 1 to 6
Expand Down

0 comments on commit a952bf8

Please sign in to comment.