diff options
author | Chocobozzz <me@florianbigard.com> | 2019-03-05 10:58:44 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2019-03-18 11:17:59 +0100 |
commit | df0b219d36bf6852cdf2a7ad09ed4a41c6bccefa (patch) | |
tree | c4984e854f5dc18e5c27afd73b843bd52c143034 /server/helpers/custom-validators | |
parent | 07b1a18aa678d260009a93e36606c5c5f585723d (diff) | |
download | PeerTube-df0b219d36bf6852cdf2a7ad09ed4a41c6bccefa.tar.gz PeerTube-df0b219d36bf6852cdf2a7ad09ed4a41c6bccefa.tar.zst PeerTube-df0b219d36bf6852cdf2a7ad09ed4a41c6bccefa.zip |
Add playlist rest tests
Diffstat (limited to 'server/helpers/custom-validators')
-rw-r--r-- | server/helpers/custom-validators/activitypub/playlist.ts | 6 | ||||
-rw-r--r-- | server/helpers/custom-validators/video-playlists.ts | 17 |
2 files changed, 17 insertions, 6 deletions
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 @@ | |||
1 | import { exists } from '../misc' | 1 | import { exists, isDateValid } from '../misc' |
2 | import { PlaylistObject } from '../../../../shared/models/activitypub/objects/playlist-object' | 2 | import { PlaylistObject } from '../../../../shared/models/activitypub/objects/playlist-object' |
3 | import * as validator from 'validator' | 3 | import * as validator from 'validator' |
4 | import { PlaylistElementObject } from '../../../../shared/models/activitypub/objects/playlist-element-object' | 4 | import { PlaylistElementObject } from '../../../../shared/models/activitypub/objects/playlist-element-object' |
@@ -7,7 +7,9 @@ import { isActivityPubUrlValid } from './misc' | |||
7 | function isPlaylistObjectValid (object: PlaylistObject) { | 7 | function isPlaylistObjectValid (object: PlaylistObject) { |
8 | return exists(object) && | 8 | return exists(object) && |
9 | object.type === 'Playlist' && | 9 | object.type === 'Playlist' && |
10 | validator.isInt(object.totalItems + '') | 10 | validator.isInt(object.totalItems + '') && |
11 | isDateValid(object.published) && | ||
12 | isDateValid(object.updated) | ||
11 | } | 13 | } |
12 | 14 | ||
13 | function isPlaylistElementObjectValid (object: PlaylistElementObject) { | 15 | 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 @@ | |||
1 | import { exists } from './misc' | 1 | import { exists } from './misc' |
2 | import * as validator from 'validator' | 2 | import * as validator from 'validator' |
3 | import { CONSTRAINTS_FIELDS, VIDEO_PLAYLIST_PRIVACIES } from '../../initializers' | 3 | import { CONSTRAINTS_FIELDS, VIDEO_PLAYLIST_PRIVACIES, VIDEO_PLAYLIST_TYPES } from '../../initializers' |
4 | import * as express from 'express' | 4 | import * as express from 'express' |
5 | import { VideoPlaylistModel } from '../../models/video/video-playlist' | 5 | import { VideoPlaylistModel } from '../../models/video/video-playlist' |
6 | import { VideoPlaylistElementModel } from '../../models/video/video-playlist-element' | ||
7 | 6 | ||
8 | const PLAYLISTS_CONSTRAINT_FIELDS = CONSTRAINTS_FIELDS.VIDEO_PLAYLISTS | 7 | const PLAYLISTS_CONSTRAINT_FIELDS = CONSTRAINTS_FIELDS.VIDEO_PLAYLISTS |
9 | 8 | ||
@@ -19,8 +18,16 @@ function isVideoPlaylistPrivacyValid (value: number) { | |||
19 | return validator.isInt(value + '') && VIDEO_PLAYLIST_PRIVACIES[ value ] !== undefined | 18 | return validator.isInt(value + '') && VIDEO_PLAYLIST_PRIVACIES[ value ] !== undefined |
20 | } | 19 | } |
21 | 20 | ||
21 | function isVideoPlaylistTimestampValid (value: any) { | ||
22 | return value === null || (exists(value) && validator.isInt('' + value, { min: 0 })) | ||
23 | } | ||
24 | |||
25 | function isVideoPlaylistTypeValid (value: any) { | ||
26 | return exists(value) && VIDEO_PLAYLIST_TYPES[ value ] !== undefined | ||
27 | } | ||
28 | |||
22 | async function isVideoPlaylistExist (id: number | string, res: express.Response) { | 29 | async function isVideoPlaylistExist (id: number | string, res: express.Response) { |
23 | const videoPlaylist = await VideoPlaylistModel.load(id, undefined) | 30 | const videoPlaylist = await VideoPlaylistModel.loadWithAccountAndChannel(id, undefined) |
24 | 31 | ||
25 | if (!videoPlaylist) { | 32 | if (!videoPlaylist) { |
26 | res.status(404) | 33 | res.status(404) |
@@ -40,5 +47,7 @@ export { | |||
40 | isVideoPlaylistExist, | 47 | isVideoPlaylistExist, |
41 | isVideoPlaylistNameValid, | 48 | isVideoPlaylistNameValid, |
42 | isVideoPlaylistDescriptionValid, | 49 | isVideoPlaylistDescriptionValid, |
43 | isVideoPlaylistPrivacyValid | 50 | isVideoPlaylistPrivacyValid, |
51 | isVideoPlaylistTimestampValid, | ||
52 | isVideoPlaylistTypeValid | ||
44 | } | 53 | } |