Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bodies): replace SHOULD with MUST for mandatory requirements #414

Merged
merged 3 commits into from
Dec 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions models/AccessToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ const AccessToken = sequelize.define('access_token', {
value: {
type: Sequelize.TEXT,
allowNull: false,
defaultValue: '',
validate: {
notEmpty: { msg: 'Value should be set.' },
notEmpty: { msg: 'Value must be set.' },
},
unique: true
},
Expand Down
29 changes: 13 additions & 16 deletions models/Body.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@ const Body = sequelize.define('body', {
name: {
type: Sequelize.STRING,
allowNull: false,
defaultValue: '',
validate: {
notEmpty: { msg: 'Name should be set.' },
notEmpty: { msg: 'Name must be set.' },
}
},
description: {
type: Sequelize.TEXT,
allowNull: false,
defaultValue: '',
validate: {
notEmpty: { msg: 'Description should be set.' },
notEmpty: { msg: 'Description must be set.' },
}
},
task_description: {
Expand All @@ -26,9 +24,9 @@ const Body = sequelize.define('body', {
type: Sequelize.STRING,
allowNull: false,
validate: {
notEmpty: { msg: 'Code should be set.' },
isAlpha: { msg: 'Code should contains only letters.' },
len: { args: [3, 3], msg: 'Code should be 3 letters long.' }
notEmpty: { msg: 'Code must be set.' },
isAlpha: { msg: 'Code must contain only letters.' },
len: { args: [3, 3], msg: 'Code must be 3 letters long.' }
},
unique: true
},
Expand All @@ -40,24 +38,23 @@ const Body = sequelize.define('body', {
email: {
type: Sequelize.STRING,
allowNull: false,
defaultValue: '',
validate: {
notEmpty: { msg: 'Email should be set.' },
isEmail: { msg: 'Email should be valid.' }
notEmpty: { msg: 'Email must be set.' },
isEmail: { msg: 'Email must be valid.' }
}
},
phone: {
type: Sequelize.STRING,
allowNull: true,
validate: {
notEmpty: { msg: 'Phone should be set.' },
notEmpty: { msg: 'Phone must be set.' },
}
},
address: {
type: Sequelize.TEXT,
allowNull: true,
validate: {
notEmpty: { msg: 'Address should be set.' },
notEmpty: { msg: 'Address must be set.' },
}
},
postal_address: {
Expand All @@ -71,7 +68,7 @@ const Body = sequelize.define('body', {
validate: {
isIn: {
args: [['antenna', 'contact antenna', 'contact', 'interest group', 'working group', 'commission', 'committee', 'project', 'partner', 'other']],
msg: 'Type should be one of these: "antenna", "contact antenna", "contact", "interest group", "working group", "commission", "committee", "project", "partner", "other".'
msg: 'Type must be one of these: "antenna", "contact antenna", "contact", "interest group", "working group", "commission", "committee", "project", "partner", "other".'
}
}
},
Expand All @@ -91,7 +88,7 @@ const Body = sequelize.define('body', {
validate: {
isValid(value) {
if (['antenna', 'contact antenna', 'contact'].includes(this.type) && value === null) {
throw new Error('Foundation date should be set');
throw new Error('Foundation date must be set');
}
}
}
Expand All @@ -103,7 +100,7 @@ const Body = sequelize.define('body', {
validate: {
isIn: {
args: [['active', 'deleted']],
msg: 'Status should be one of these: "active", "deleted".'
msg: 'Status must be one of these: "active", "deleted".'
}
}
},
Expand All @@ -119,7 +116,7 @@ const Body = sequelize.define('body', {
type: Sequelize.STRING,
allowNull: true,
validate: {
isEmail: { msg: 'GSuite ID should be a valid email.' }
isEmail: { msg: 'GSuite ID must be a valid email.' }
},
unique: true
}
Expand Down
3 changes: 1 addition & 2 deletions test/unit/bodies.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,8 @@ describe('Bodies testing', () => {
expect(1).toEqual(0);
} catch (err) {
expect(err).toHaveProperty('errors');
expect(err.errors.length).toEqual(2);
expect(err.errors.length).toEqual(1);
expect(err.errors[0].path).toEqual('email');
expect(err.errors[1].path).toEqual('email');
}
});

Expand Down