From 95d36b89d792dd362f7d0c7fdb6c34c0afaf4fd7 Mon Sep 17 00:00:00 2001 From: ivaosthu Date: Wed, 17 Jan 2018 09:27:47 +0100 Subject: [PATCH] Use joi instead of assert --- lib/user.js | 10 ++++++++-- lib/user.test.js | 2 +- package.json | 1 - yarn.lock | 16 ---------------- 4 files changed, 9 insertions(+), 20 deletions(-) diff --git a/lib/user.js b/lib/user.js index af102f459d17..d070bfac22ec 100644 --- a/lib/user.js +++ b/lib/user.js @@ -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 = diff --git a/lib/user.test.js b/lib/user.test.js index 7f356bc932ee..5f1c45bd6f3c 100644 --- a/lib/user.test.js +++ b/lib/user.test.js @@ -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 => { diff --git a/package.json b/package.json index 752f2295e50f..5e725bc6d6f4 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,6 @@ ] }, "dependencies": { - "assert": "^1.4.1", "async": "^2.1.5", "body-parser": "^1.18.2", "commander": "^2.9.0", diff --git a/yarn.lock b/yarn.lock index b44c7d7d82b0..979e72ac56d6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" - ast-types@0.x.x: version "0.9.14" resolved "https://registry.yarnpkg.com/ast-types/-/ast-types-0.9.14.tgz#d34ba5dffb9d15a44351fd2a9d82e4ab2838b5ba" @@ -2690,10 +2684,6 @@ inherits@2, inherits@2.0.3, 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" -inherits@2.0.1: - 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" @@ -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" -util@0.10.3: - version "0.10.3" - resolved "https://registry.yarnpkg.com/util/-/util-0.10.3.tgz#7afb1afe50805246489e3db7fe0ed379336ac0f9" - dependencies: - inherits "2.0.1" - utile@0.3.x: version "0.3.0" resolved "https://registry.yarnpkg.com/utile/-/utile-0.3.0.tgz#1352c340eb820e4d8ddba039a4fbfaa32ed4ef3a"