From 2d53be0267acc49cda46707b885096193a1f4e9c Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Mon, 7 Dec 2020 14:32:36 +0100 Subject: replace numbers with typed http status codes (#3409) --- shared/extra-utils/videos/live.ts | 13 ++++-- shared/extra-utils/videos/services.ts | 3 +- shared/extra-utils/videos/video-blacklist.ts | 17 +++++--- shared/extra-utils/videos/video-captions.ts | 9 ++-- .../extra-utils/videos/video-change-ownership.ts | 26 ++++++++++-- shared/extra-utils/videos/video-channels.ts | 24 +++++++---- shared/extra-utils/videos/video-comments.ts | 19 ++++++--- shared/extra-utils/videos/video-history.ts | 5 ++- shared/extra-utils/videos/video-imports.ts | 10 ++++- shared/extra-utils/videos/video-playlists.ts | 31 +++++++------- .../videos/video-streaming-playlists.ts | 9 ++-- shared/extra-utils/videos/videos.ts | 49 ++++++++++++---------- 12 files changed, 141 insertions(+), 74 deletions(-) (limited to 'shared/extra-utils/videos') diff --git a/shared/extra-utils/videos/live.ts b/shared/extra-utils/videos/live.ts index 522beb8bc..4aa66622b 100644 --- a/shared/extra-utils/videos/live.ts +++ b/shared/extra-utils/videos/live.ts @@ -10,8 +10,9 @@ import { buildAbsoluteFixturePath, buildServerDirectory, wait } from '../miscs/m import { makeGetRequest, makePutBodyRequest, makeUploadRequest } from '../requests/requests' import { ServerInfo } from '../server/servers' import { getVideoWithToken } from './videos' +import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' -function getLive (url: string, token: string, videoId: number | string, statusCodeExpected = 200) { +function getLive (url: string, token: string, videoId: number | string, statusCodeExpected = HttpStatusCode.OK_200) { const path = '/api/v1/videos/live' return makeGetRequest({ @@ -22,7 +23,13 @@ function getLive (url: string, token: string, videoId: number | string, statusCo }) } -function updateLive (url: string, token: string, videoId: number | string, fields: LiveVideoUpdate, statusCodeExpected = 204) { +function updateLive ( + url: string, + token: string, + videoId: number | string, + fields: LiveVideoUpdate, + statusCodeExpected = HttpStatusCode.NO_CONTENT_204 +) { const path = '/api/v1/videos/live' return makePutBodyRequest({ @@ -34,7 +41,7 @@ function updateLive (url: string, token: string, videoId: number | string, field }) } -function createLive (url: string, token: string, fields: LiveVideoCreate, statusCodeExpected = 200) { +function createLive (url: string, token: string, fields: LiveVideoCreate, statusCodeExpected = HttpStatusCode.OK_200) { const path = '/api/v1/videos/live' const attaches: any = {} diff --git a/shared/extra-utils/videos/services.ts b/shared/extra-utils/videos/services.ts index 1a53dd4cf..e13a788bd 100644 --- a/shared/extra-utils/videos/services.ts +++ b/shared/extra-utils/videos/services.ts @@ -1,4 +1,5 @@ import * as request from 'supertest' +import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' function getOEmbed (url: string, oembedUrl: string, format?: string, maxHeight?: number, maxWidth?: number) { const path = '/services/oembed' @@ -13,7 +14,7 @@ function getOEmbed (url: string, oembedUrl: string, format?: string, maxHeight?: .get(path) .query(query) .set('Accept', 'application/json') - .expect(200) + .expect(HttpStatusCode.OK_200) } // --------------------------------------------------------------------------- diff --git a/shared/extra-utils/videos/video-blacklist.ts b/shared/extra-utils/videos/video-blacklist.ts index ba139ef95..aa1548537 100644 --- a/shared/extra-utils/videos/video-blacklist.ts +++ b/shared/extra-utils/videos/video-blacklist.ts @@ -1,6 +1,7 @@ import * as request from 'supertest' import { VideoBlacklistType } from '../../models/videos' import { makeGetRequest } from '..' +import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' function addVideoToBlacklist ( url: string, @@ -8,7 +9,7 @@ function addVideoToBlacklist ( videoId: number | string, reason?: string, unfederate?: boolean, - specialStatus = 204 + specialStatus = HttpStatusCode.NO_CONTENT_204 ) { const path = '/api/v1/videos/' + videoId + '/blacklist' @@ -20,7 +21,13 @@ function addVideoToBlacklist ( .expect(specialStatus) } -function updateVideoBlacklist (url: string, token: string, videoId: number, reason?: string, specialStatus = 204) { +function updateVideoBlacklist ( + url: string, + token: string, + videoId: number, + reason?: string, + specialStatus = HttpStatusCode.NO_CONTENT_204 +) { const path = '/api/v1/videos/' + videoId + '/blacklist' return request(url) @@ -31,7 +38,7 @@ function updateVideoBlacklist (url: string, token: string, videoId: number, reas .expect(specialStatus) } -function removeVideoFromBlacklist (url: string, token: string, videoId: number | string, specialStatus = 204) { +function removeVideoFromBlacklist (url: string, token: string, videoId: number | string, specialStatus = HttpStatusCode.NO_CONTENT_204) { const path = '/api/v1/videos/' + videoId + '/blacklist' return request(url) @@ -46,9 +53,9 @@ function getBlacklistedVideosList (parameters: { token: string sort?: string type?: VideoBlacklistType - specialStatus?: number + specialStatus?: HttpStatusCode }) { - const { url, token, sort, type, specialStatus = 200 } = parameters + const { url, token, sort, type, specialStatus = HttpStatusCode.OK_200 } = parameters const path = '/api/v1/videos/blacklist/' const query = { sort, type } diff --git a/shared/extra-utils/videos/video-captions.ts b/shared/extra-utils/videos/video-captions.ts index 5bd533bba..62eec7b90 100644 --- a/shared/extra-utils/videos/video-captions.ts +++ b/shared/extra-utils/videos/video-captions.ts @@ -2,6 +2,7 @@ import { makeDeleteRequest, makeGetRequest, makeUploadRequest } from '../request import * as request from 'supertest' import * as chai from 'chai' import { buildAbsoluteFixturePath } from '../miscs/miscs' +import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' const expect = chai.expect @@ -28,7 +29,7 @@ function createVideoCaption (args: { attaches: { captionfile: captionfileAttach }, - statusCodeExpected: args.statusCodeExpected || 204 + statusCodeExpected: args.statusCodeExpected || HttpStatusCode.NO_CONTENT_204 }) } @@ -38,7 +39,7 @@ function listVideoCaptions (url: string, videoId: string | number) { return makeGetRequest({ url, path, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) } @@ -49,14 +50,14 @@ function deleteVideoCaption (url: string, token: string, videoId: string | numbe url, token, path, - statusCodeExpected: 204 + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) } async function testCaptionFile (url: string, captionPath: string, containsString: string) { const res = await request(url) .get(captionPath) - .expect(200) + .expect(HttpStatusCode.OK_200) expect(res.text).to.contain(containsString) } diff --git a/shared/extra-utils/videos/video-change-ownership.ts b/shared/extra-utils/videos/video-change-ownership.ts index 371d02000..ef82a7636 100644 --- a/shared/extra-utils/videos/video-change-ownership.ts +++ b/shared/extra-utils/videos/video-change-ownership.ts @@ -1,6 +1,13 @@ import * as request from 'supertest' +import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' -function changeVideoOwnership (url: string, token: string, videoId: number | string, username, expectedStatus = 204) { +function changeVideoOwnership ( + url: string, + token: string, + videoId: number | string, + username, + expectedStatus = HttpStatusCode.NO_CONTENT_204 +) { const path = '/api/v1/videos/' + videoId + '/give-ownership' return request(url) @@ -19,11 +26,17 @@ function getVideoChangeOwnershipList (url: string, token: string) { .query({ sort: '-createdAt' }) .set('Accept', 'application/json') .set('Authorization', 'Bearer ' + token) - .expect(200) + .expect(HttpStatusCode.OK_200) .expect('Content-Type', /json/) } -function acceptChangeOwnership (url: string, token: string, ownershipId: string, channelId: number, expectedStatus = 204) { +function acceptChangeOwnership ( + url: string, + token: string, + ownershipId: string, + channelId: number, + expectedStatus = HttpStatusCode.NO_CONTENT_204 +) { const path = '/api/v1/videos/ownership/' + ownershipId + '/accept' return request(url) @@ -34,7 +47,12 @@ function acceptChangeOwnership (url: string, token: string, ownershipId: string, .expect(expectedStatus) } -function refuseChangeOwnership (url: string, token: string, ownershipId: string, expectedStatus = 204) { +function refuseChangeOwnership ( + url: string, + token: string, + ownershipId: string, + expectedStatus = HttpStatusCode.NO_CONTENT_204 +) { const path = '/api/v1/videos/ownership/' + ownershipId + '/refuse' return request(url) diff --git a/shared/extra-utils/videos/video-channels.ts b/shared/extra-utils/videos/video-channels.ts index 97b68178f..3ff445c2a 100644 --- a/shared/extra-utils/videos/video-channels.ts +++ b/shared/extra-utils/videos/video-channels.ts @@ -7,6 +7,7 @@ import { makeGetRequest, updateAvatarRequest } from '../requests/requests' import { ServerInfo } from '../server/servers' import { User } from '../../models/users/user.model' import { getMyUserInformation } from '../users/users' +import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' function getVideoChannelsList (url: string, start: number, count: number, sort?: string, withStats?: boolean) { const path = '/api/v1/video-channels' @@ -20,7 +21,7 @@ function getVideoChannelsList (url: string, start: number, count: number, sort?: if (withStats) req.query({ withStats }) return req.set('Accept', 'application/json') - .expect(200) + .expect(HttpStatusCode.OK_200) .expect('Content-Type', /json/) } @@ -30,11 +31,20 @@ function getAccountVideoChannelsList (parameters: { start?: number count?: number sort?: string - specialStatus?: number + specialStatus?: HttpStatusCode withStats?: boolean search?: string }) { - const { url, accountName, start, count, sort = 'createdAt', specialStatus = 200, withStats = false, search } = parameters + const { + url, + accountName, + start, + count, + sort = 'createdAt', + specialStatus = HttpStatusCode.OK_200, + withStats = false, + search + } = parameters const path = '/api/v1/accounts/' + accountName + '/video-channels' @@ -56,7 +66,7 @@ function addVideoChannel ( url: string, token: string, videoChannelAttributesArg: VideoChannelCreate, - expectedStatus = 200 + expectedStatus = HttpStatusCode.OK_200 ) { const path = '/api/v1/video-channels/' @@ -81,7 +91,7 @@ function updateVideoChannel ( token: string, channelName: string, attributes: VideoChannelUpdate, - expectedStatus = 204 + expectedStatus = HttpStatusCode.NO_CONTENT_204 ) { const body: any = {} const path = '/api/v1/video-channels/' + channelName @@ -99,7 +109,7 @@ function updateVideoChannel ( .expect(expectedStatus) } -function deleteVideoChannel (url: string, token: string, channelName: string, expectedStatus = 204) { +function deleteVideoChannel (url: string, token: string, channelName: string, expectedStatus = HttpStatusCode.NO_CONTENT_204) { const path = '/api/v1/video-channels/' + channelName return request(url) @@ -115,7 +125,7 @@ function getVideoChannel (url: string, channelName: string) { return request(url) .get(path) .set('Accept', 'application/json') - .expect(200) + .expect(HttpStatusCode.OK_200) .expect('Content-Type', /json/) } diff --git a/shared/extra-utils/videos/video-comments.ts b/shared/extra-utils/videos/video-comments.ts index 0b0df81dc..71b9f875a 100644 --- a/shared/extra-utils/videos/video-comments.ts +++ b/shared/extra-utils/videos/video-comments.ts @@ -2,6 +2,7 @@ import * as request from 'supertest' import { makeDeleteRequest, makeGetRequest } from '../requests/requests' +import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' function getAdminVideoComments (options: { url: string @@ -33,7 +34,7 @@ function getAdminVideoComments (options: { path, token, query, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) } @@ -49,7 +50,7 @@ function getVideoCommentThreads (url: string, videoId: number | string, start: n if (token) req.set('Authorization', 'Bearer ' + token) return req.set('Accept', 'application/json') - .expect(200) + .expect(HttpStatusCode.OK_200) .expect('Content-Type', /json/) } @@ -62,11 +63,17 @@ function getVideoThreadComments (url: string, videoId: number | string, threadId if (token) req.set('Authorization', 'Bearer ' + token) - return req.expect(200) + return req.expect(HttpStatusCode.OK_200) .expect('Content-Type', /json/) } -function addVideoCommentThread (url: string, token: string, videoId: number | string, text: string, expectedStatus = 200) { +function addVideoCommentThread ( + url: string, + token: string, + videoId: number | string, + text: string, + expectedStatus = HttpStatusCode.OK_200 +) { const path = '/api/v1/videos/' + videoId + '/comment-threads' return request(url) @@ -83,7 +90,7 @@ function addVideoCommentReply ( videoId: number | string, inReplyToCommentId: number, text: string, - expectedStatus = 200 + expectedStatus = HttpStatusCode.OK_200 ) { const path = '/api/v1/videos/' + videoId + '/comments/' + inReplyToCommentId @@ -106,7 +113,7 @@ function deleteVideoComment ( token: string, videoId: number | string, commentId: number, - statusCodeExpected = 204 + statusCodeExpected = HttpStatusCode.NO_CONTENT_204 ) { const path = '/api/v1/videos/' + videoId + '/comments/' + commentId diff --git a/shared/extra-utils/videos/video-history.ts b/shared/extra-utils/videos/video-history.ts index dc7095b4d..2d751cf14 100644 --- a/shared/extra-utils/videos/video-history.ts +++ b/shared/extra-utils/videos/video-history.ts @@ -1,4 +1,5 @@ import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' +import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' function userWatchVideo (url: string, token: string, videoId: number | string, currentTime: number, statusCodeExpected = 204) { const path = '/api/v1/videos/' + videoId + '/watching' @@ -14,7 +15,7 @@ function listMyVideosHistory (url: string, token: string) { url, path, token, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) } @@ -26,7 +27,7 @@ function removeMyVideosHistory (url: string, token: string, beforeDate?: string) path, token, fields: beforeDate ? { beforeDate } : {}, - statusCodeExpected: 204 + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) } diff --git a/shared/extra-utils/videos/video-imports.ts b/shared/extra-utils/videos/video-imports.ts index 6249e8a94..52e0075fb 100644 --- a/shared/extra-utils/videos/video-imports.ts +++ b/shared/extra-utils/videos/video-imports.ts @@ -1,6 +1,7 @@ import { VideoImportCreate } from '../../models/videos' import { makeGetRequest, makeUploadRequest } from '../requests/requests' +import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' function getYoutubeVideoUrl () { return 'http://www.youtube.com/watch?v=msX3jv1XdvM' @@ -19,7 +20,12 @@ function getGoodVideoUrl () { return 'https://download.cpy.re/peertube/good_video.mp4' } -function importVideo (url: string, token: string, attributes: VideoImportCreate & { torrentfile?: string }, statusCodeExpected = 200) { +function importVideo ( + url: string, + token: string, + attributes: VideoImportCreate & { torrentfile?: string }, + statusCodeExpected = HttpStatusCode.OK_200 +) { const path = '/api/v1/videos/imports' let attaches: any = {} @@ -46,7 +52,7 @@ function getMyVideoImports (url: string, token: string, sort?: string) { query, path, token, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) } diff --git a/shared/extra-utils/videos/video-playlists.ts b/shared/extra-utils/videos/video-playlists.ts index 5bcc02570..c6f799e5d 100644 --- a/shared/extra-utils/videos/video-playlists.ts +++ b/shared/extra-utils/videos/video-playlists.ts @@ -10,6 +10,7 @@ import { root } from '..' import { readdir } from 'fs-extra' import { expect } from 'chai' import { VideoPlaylistType } from '../../models/videos/playlist/video-playlist-type.model' +import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' function getVideoPlaylistsList (url: string, start: number, count: number, sort?: string) { const path = '/api/v1/video-playlists' @@ -24,7 +25,7 @@ function getVideoPlaylistsList (url: string, start: number, count: number, sort? url, path, query, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) } @@ -41,7 +42,7 @@ function getVideoChannelPlaylistsList (url: string, videoChannelName: string, st url, path, query, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) } @@ -59,7 +60,7 @@ function getAccountPlaylistsList (url: string, accountName: string, start: numbe url, path, query, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) } @@ -86,11 +87,11 @@ function getAccountPlaylistsListWithToken ( token, path, query, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) } -function getVideoPlaylist (url: string, playlistId: number | string, statusCodeExpected = 200) { +function getVideoPlaylist (url: string, playlistId: number | string, statusCodeExpected = HttpStatusCode.OK_200) { const path = '/api/v1/video-playlists/' + playlistId return makeGetRequest({ @@ -100,7 +101,7 @@ function getVideoPlaylist (url: string, playlistId: number | string, statusCodeE }) } -function getVideoPlaylistWithToken (url: string, token: string, playlistId: number | string, statusCodeExpected = 200) { +function getVideoPlaylistWithToken (url: string, token: string, playlistId: number | string, statusCodeExpected = HttpStatusCode.OK_200) { const path = '/api/v1/video-playlists/' + playlistId return makeGetRequest({ @@ -111,7 +112,7 @@ function getVideoPlaylistWithToken (url: string, token: string, playlistId: numb }) } -function deleteVideoPlaylist (url: string, token: string, playlistId: number | string, statusCodeExpected = 204) { +function deleteVideoPlaylist (url: string, token: string, playlistId: number | string, statusCodeExpected = HttpStatusCode.NO_CONTENT_204) { const path = '/api/v1/video-playlists/' + playlistId return makeDeleteRequest({ @@ -143,7 +144,7 @@ function createVideoPlaylist (options: { token: options.token, fields, attaches, - statusCodeExpected: options.expectedStatus || 200 + statusCodeExpected: options.expectedStatus || HttpStatusCode.OK_200 }) } @@ -169,7 +170,7 @@ function updateVideoPlaylist (options: { token: options.token, fields, attaches, - statusCodeExpected: options.expectedStatus || 204 + statusCodeExpected: options.expectedStatus || HttpStatusCode.NO_CONTENT_204 }) } @@ -189,7 +190,7 @@ async function addVideoInPlaylist (options: { path, token: options.token, fields: options.elementAttrs, - statusCodeExpected: options.expectedStatus || 200 + statusCodeExpected: options.expectedStatus || HttpStatusCode.OK_200 }) } @@ -208,7 +209,7 @@ function updateVideoPlaylistElement (options: { path, token: options.token, fields: options.elementAttrs, - statusCodeExpected: options.expectedStatus || 204 + statusCodeExpected: options.expectedStatus || HttpStatusCode.NO_CONTENT_204 }) } @@ -225,7 +226,7 @@ function removeVideoFromPlaylist (options: { url: options.url, path, token: options.token, - statusCodeExpected: options.expectedStatus || 204 + statusCodeExpected: options.expectedStatus || HttpStatusCode.NO_CONTENT_204 }) } @@ -247,7 +248,7 @@ function reorderVideosPlaylist (options: { path, token: options.token, fields: options.elementAttrs, - statusCodeExpected: options.expectedStatus || 204 + statusCodeExpected: options.expectedStatus || HttpStatusCode.NO_CONTENT_204 }) } @@ -274,7 +275,7 @@ function getVideoPlaylistPrivacies (url: string) { return makeGetRequest({ url, path, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) } @@ -286,7 +287,7 @@ function doVideosExistInMyPlaylist (url: string, token: string, videoIds: number token, path, query: { videoIds }, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) } diff --git a/shared/extra-utils/videos/video-streaming-playlists.ts b/shared/extra-utils/videos/video-streaming-playlists.ts index b386e77c3..99c2e1880 100644 --- a/shared/extra-utils/videos/video-streaming-playlists.ts +++ b/shared/extra-utils/videos/video-streaming-playlists.ts @@ -2,16 +2,17 @@ import { makeRawRequest } from '../requests/requests' import { sha256 } from '../../../server/helpers/core-utils' import { VideoStreamingPlaylist } from '../../models/videos/video-streaming-playlist.model' import { expect } from 'chai' +import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' -function getPlaylist (url: string, statusCodeExpected = 200) { +function getPlaylist (url: string, statusCodeExpected = HttpStatusCode.OK_200) { return makeRawRequest(url, statusCodeExpected) } -function getSegment (url: string, statusCodeExpected = 200, range?: string) { +function getSegment (url: string, statusCodeExpected = HttpStatusCode.OK_200, range?: string) { return makeRawRequest(url, statusCodeExpected, range) } -function getSegmentSha256 (url: string, statusCodeExpected = 200) { +function getSegmentSha256 (url: string, statusCodeExpected = HttpStatusCode.OK_200) { return makeRawRequest(url, statusCodeExpected) } @@ -33,7 +34,7 @@ async function checkSegmentHash ( const offset = parseInt(matches[2], 10) const range = `${offset}-${offset + length - 1}` - const res2 = await getSegment(`${baseUrlSegment}/${videoUUID}/${videoName}`, 206, `bytes=${range}`) + const res2 = await getSegment(`${baseUrlSegment}/${videoUUID}/${videoName}`, HttpStatusCode.PARTIAL_CONTENT_206, `bytes=${range}`) const resSha = await getSegmentSha256(hlsPlaylist.segmentsSha256Url) diff --git a/shared/extra-utils/videos/videos.ts b/shared/extra-utils/videos/videos.ts index 2b8c55acb..a4b9d688e 100644 --- a/shared/extra-utils/videos/videos.ts +++ b/shared/extra-utils/videos/videos.ts @@ -1,5 +1,6 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */ +import { HttpStatusCode } from '@shared/core-utils' import { expect } from 'chai' import { pathExists, readdir, readFile } from 'fs-extra' import * as parseTorrent from 'parse-torrent' @@ -46,7 +47,7 @@ function getVideoCategories (url: string) { return makeGetRequest({ url, path, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) } @@ -56,7 +57,7 @@ function getVideoLicences (url: string) { return makeGetRequest({ url, path, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) } @@ -66,7 +67,7 @@ function getVideoLanguages (url: string) { return makeGetRequest({ url, path, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) } @@ -76,11 +77,11 @@ function getVideoPrivacies (url: string) { return makeGetRequest({ url, path, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) } -function getVideo (url: string, id: number | string, expectedStatus = 200) { +function getVideo (url: string, id: number | string, expectedStatus = HttpStatusCode.OK_200) { const path = '/api/v1/videos/' + id return request(url) @@ -99,11 +100,11 @@ function getVideoFileMetadataUrl (url: string) { return request(url) .get('/') .set('Accept', 'application/json') - .expect(200) + .expect(HttpStatusCode.OK_200) .expect('Content-Type', /json/) } -function viewVideo (url: string, id: number | string, expectedStatus = 204, xForwardedFor?: string) { +function viewVideo (url: string, id: number | string, expectedStatus = HttpStatusCode.NO_CONTENT_204, xForwardedFor?: string) { const path = '/api/v1/videos/' + id + '/views' const req = request(url) @@ -117,7 +118,7 @@ function viewVideo (url: string, id: number | string, expectedStatus = 204, xFor return req.expect(expectedStatus) } -function getVideoWithToken (url: string, token: string, id: number | string, expectedStatus = 200) { +function getVideoWithToken (url: string, token: string, id: number | string, expectedStatus = HttpStatusCode.OK_200) { const path = '/api/v1/videos/' + id return request(url) @@ -131,7 +132,7 @@ function getVideoDescription (url: string, descriptionPath: string) { return request(url) .get(descriptionPath) .set('Accept', 'application/json') - .expect(200) + .expect(HttpStatusCode.OK_200) .expect('Content-Type', /json/) } @@ -142,7 +143,7 @@ function getVideosList (url: string) { .get(path) .query({ sort: 'name' }) .set('Accept', 'application/json') - .expect(200) + .expect(HttpStatusCode.OK_200) .expect('Content-Type', /json/) } @@ -182,7 +183,7 @@ function getMyVideos (url: string, accessToken: string, start: number, count: nu return req.set('Accept', 'application/json') .set('Authorization', 'Bearer ' + accessToken) - .expect(200) + .expect(HttpStatusCode.OK_200) .expect('Content-Type', /json/) } @@ -206,7 +207,7 @@ function getAccountVideos ( sort }), token: accessToken, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) } @@ -230,7 +231,7 @@ function getVideoChannelVideos ( sort }), token: accessToken, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) } @@ -252,7 +253,7 @@ function getPlaylistVideos ( count }), token: accessToken, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) } @@ -268,7 +269,7 @@ function getVideosListPagination (url: string, start: number, count: number, sor if (skipCount) req.query({ skipCount }) return req.set('Accept', 'application/json') - .expect(200) + .expect(HttpStatusCode.OK_200) .expect('Content-Type', /json/) } @@ -279,7 +280,7 @@ function getVideosListSort (url: string, sort: string) { .get(path) .query({ sort: sort }) .set('Accept', 'application/json') - .expect(200) + .expect(HttpStatusCode.OK_200) .expect('Content-Type', /json/) } @@ -290,11 +291,11 @@ function getVideosWithFilters (url: string, query: { tagsAllOf: string[], catego .get(path) .query(query) .set('Accept', 'application/json') - .expect(200) + .expect(HttpStatusCode.OK_200) .expect('Content-Type', /json/) } -function removeVideo (url: string, token: string, id: number | string, expectedStatus = 204) { +function removeVideo (url: string, token: string, id: number | string, expectedStatus = HttpStatusCode.NO_CONTENT_204) { const path = '/api/v1/videos' return request(url) @@ -339,7 +340,7 @@ async function checkVideoFilesWereRemoved ( } } -async function uploadVideo (url: string, accessToken: string, videoAttributesArg: VideoAttributes, specialStatus = 200) { +async function uploadVideo (url: string, accessToken: string, videoAttributesArg: VideoAttributes, specialStatus = HttpStatusCode.OK_200) { const path = '/api/v1/videos/upload' let defaultChannelId = '1' @@ -423,7 +424,13 @@ async function uploadVideo (url: string, accessToken: string, videoAttributesArg .expect(specialStatus) } -function updateVideo (url: string, accessToken: string, id: number | string, attributes: VideoAttributes, statusCodeExpected = 204) { +function updateVideo ( + url: string, + accessToken: string, + id: number | string, + attributes: VideoAttributes, + statusCodeExpected = HttpStatusCode.NO_CONTENT_204 +) { const path = '/api/v1/videos/' + id const body = {} @@ -467,7 +474,7 @@ function updateVideo (url: string, accessToken: string, id: number | string, att }) } -function rateVideo (url: string, accessToken: string, id: number, rating: string, specialStatus = 204) { +function rateVideo (url: string, accessToken: string, id: number, rating: string, specialStatus = HttpStatusCode.NO_CONTENT_204) { const path = '/api/v1/videos/' + id + '/rate' return request(url) -- cgit v1.2.3