From df0b219d36bf6852cdf2a7ad09ed4a41c6bccefa Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 5 Mar 2019 10:58:44 +0100 Subject: Add playlist rest tests --- .../helpers/custom-validators/activitypub/playlist.ts | 6 ++++-- server/helpers/custom-validators/video-playlists.ts | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) (limited to 'server/helpers/custom-validators') diff --git a/server/helpers/custom-validators/activitypub/playlist.ts b/server/helpers/custom-validators/activitypub/playlist.ts index ecdc7975e..6c7bdb193 100644 --- a/server/helpers/custom-validators/activitypub/playlist.ts +++ b/server/helpers/custom-validators/activitypub/playlist.ts @@ -1,4 +1,4 @@ -import { exists } from '../misc' +import { exists, isDateValid } from '../misc' import { PlaylistObject } from '../../../../shared/models/activitypub/objects/playlist-object' import * as validator from 'validator' import { PlaylistElementObject } from '../../../../shared/models/activitypub/objects/playlist-element-object' @@ -7,7 +7,9 @@ import { isActivityPubUrlValid } from './misc' function isPlaylistObjectValid (object: PlaylistObject) { return exists(object) && object.type === 'Playlist' && - validator.isInt(object.totalItems + '') + validator.isInt(object.totalItems + '') && + isDateValid(object.published) && + isDateValid(object.updated) } function isPlaylistElementObjectValid (object: PlaylistElementObject) { diff --git a/server/helpers/custom-validators/video-playlists.ts b/server/helpers/custom-validators/video-playlists.ts index 0f5af4ec0..c217a39bf 100644 --- a/server/helpers/custom-validators/video-playlists.ts +++ b/server/helpers/custom-validators/video-playlists.ts @@ -1,9 +1,8 @@ import { exists } from './misc' import * as validator from 'validator' -import { CONSTRAINTS_FIELDS, VIDEO_PLAYLIST_PRIVACIES } from '../../initializers' +import { CONSTRAINTS_FIELDS, VIDEO_PLAYLIST_PRIVACIES, VIDEO_PLAYLIST_TYPES } from '../../initializers' import * as express from 'express' import { VideoPlaylistModel } from '../../models/video/video-playlist' -import { VideoPlaylistElementModel } from '../../models/video/video-playlist-element' const PLAYLISTS_CONSTRAINT_FIELDS = CONSTRAINTS_FIELDS.VIDEO_PLAYLISTS @@ -19,8 +18,16 @@ function isVideoPlaylistPrivacyValid (value: number) { return validator.isInt(value + '') && VIDEO_PLAYLIST_PRIVACIES[ value ] !== undefined } +function isVideoPlaylistTimestampValid (value: any) { + return value === null || (exists(value) && validator.isInt('' + value, { min: 0 })) +} + +function isVideoPlaylistTypeValid (value: any) { + return exists(value) && VIDEO_PLAYLIST_TYPES[ value ] !== undefined +} + async function isVideoPlaylistExist (id: number | string, res: express.Response) { - const videoPlaylist = await VideoPlaylistModel.load(id, undefined) + const videoPlaylist = await VideoPlaylistModel.loadWithAccountAndChannel(id, undefined) if (!videoPlaylist) { res.status(404) @@ -40,5 +47,7 @@ export { isVideoPlaylistExist, isVideoPlaylistNameValid, isVideoPlaylistDescriptionValid, - isVideoPlaylistPrivacyValid + isVideoPlaylistPrivacyValid, + isVideoPlaylistTimestampValid, + isVideoPlaylistTypeValid } -- cgit v1.2.3