Skip to content

Commit

Permalink
Use joi instead of assert
Browse files Browse the repository at this point in the history
  • Loading branch information
ivaosthu committed Jan 17, 2018
1 parent 9eed7a0 commit a9ee3a0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 20 deletions.
10 changes: 8 additions & 2 deletions lib/user.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
'use strict';

const gravatar = require('gravatar');
const assert = require('assert');
const Joi = require('joi');

module.exports = class User {
constructor({ name, email, imageUrl } = {}) {
assert(email, 'Email is required');
Joi.assert(
email,
Joi.string()
.email()
.required(),
'Email'
);
this.email = email;
this.name = name;
this.imageUrl =
Expand Down
2 changes: 1 addition & 1 deletion lib/user.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test('should require email', t => {
const user = new User(); // eslint-disable-line
}, Error);

t.is(error.message, 'Email is required');
t.is(error.message, 'Email "value" is required');
});

test('Should create user with only email defined', t => {
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
]
},
"dependencies": {
"assert": "^1.4.1",
"async": "^2.1.5",
"body-parser": "^1.18.2",
"commander": "^2.9.0",
Expand Down
16 changes: 0 additions & 16 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -298,12 +298,6 @@ assert-plus@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/assert-plus/-/assert-plus-0.2.0.tgz#d74e1b87e7affc0db8aadb7021f3fe48101ab234"

assert@^1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/assert/-/assert-1.4.1.tgz#99912d591836b5a6f5b345c0f07eefc08fc65d91"
dependencies:
util "0.10.3"

[email protected]:
version "0.9.14"
resolved "https://registry.yarnpkg.com/ast-types/-/ast-types-0.9.14.tgz#d34ba5dffb9d15a44351fd2a9d82e4ab2838b5ba"
Expand Down Expand Up @@ -2690,10 +2684,6 @@ inherits@2, [email protected], inherits@^2.0.1, inherits@^2.0.3, inherits@~2.0.0, i
version "2.0.3"
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"

[email protected]:
version "2.0.1"
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.1.tgz#b17d08d326b4423e568eff719f91b0b1cbdf69f1"

ini@^1.3.4, ini@~1.3.0:
version "1.3.4"
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.4.tgz#0537cb79daf59b59a1a517dff706c86ec039162e"
Expand Down Expand Up @@ -5838,12 +5828,6 @@ util-deprecate@~1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"

[email protected]:
version "0.10.3"
resolved "https://registry.yarnpkg.com/util/-/util-0.10.3.tgz#7afb1afe50805246489e3db7fe0ed379336ac0f9"
dependencies:
inherits "2.0.1"

[email protected]:
version "0.3.0"
resolved "https://registry.yarnpkg.com/utile/-/utile-0.3.0.tgz#1352c340eb820e4d8ddba039a4fbfaa32ed4ef3a"
Expand Down

0 comments on commit a9ee3a0

Please sign in to comment.