From d57d6f2605f4ac4a81f9a8594433bb7b65f108b9 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Sun, 21 Aug 2016 10:08:40 +0200 Subject: Server: fix makefriends validation and tests --- server/helpers/custom-validators/index.js | 2 ++ server/helpers/custom-validators/misc.js | 11 +---------- server/helpers/custom-validators/pods.js | 21 +++++++++++++++++++++ 3 files changed, 24 insertions(+), 10 deletions(-) create mode 100644 server/helpers/custom-validators/pods.js (limited to 'server/helpers/custom-validators') diff --git a/server/helpers/custom-validators/index.js b/server/helpers/custom-validators/index.js index ab3066822..96b5b20b9 100644 --- a/server/helpers/custom-validators/index.js +++ b/server/helpers/custom-validators/index.js @@ -1,11 +1,13 @@ 'use strict' const miscValidators = require('./misc') +const podsValidators = require('./pods') const usersValidators = require('./users') const videosValidators = require('./videos') const validators = { misc: miscValidators, + pods: podsValidators, users: usersValidators, videos: videosValidators } diff --git a/server/helpers/custom-validators/misc.js b/server/helpers/custom-validators/misc.js index 13904ea1b..782ae3dee 100644 --- a/server/helpers/custom-validators/misc.js +++ b/server/helpers/custom-validators/misc.js @@ -1,11 +1,8 @@ 'use strict' -const validator = require('express-validator').validator - const miscValidators = { exists: exists, - isArray: isArray, - isEachUrl: isEachUrl + isArray: isArray } function exists (value) { @@ -16,12 +13,6 @@ function isArray (value) { return Array.isArray(value) } -function isEachUrl (urls) { - return urls.every(function (url) { - return validator.isURL(url) - }) -} - // --------------------------------------------------------------------------- module.exports = miscValidators diff --git a/server/helpers/custom-validators/pods.js b/server/helpers/custom-validators/pods.js new file mode 100644 index 000000000..28d04a05d --- /dev/null +++ b/server/helpers/custom-validators/pods.js @@ -0,0 +1,21 @@ +'use strict' + +const validator = require('express-validator').validator + +const miscValidators = require('./misc') + +const podsValidators = { + isEachUniqueUrlValid: isEachUniqueUrlValid +} + +function isEachUniqueUrlValid (urls) { + return miscValidators.isArray(urls) && + urls.length !== 0 && + urls.every(function (url) { + return validator.isURL(url) && urls.indexOf(url) === urls.lastIndexOf(url) + }) +} + +// --------------------------------------------------------------------------- + +module.exports = podsValidators -- cgit v1.2.3