From d525fc399a14a8b16eaad6d4c0bc0a9c4093c3c9 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 20 Jul 2018 14:35:18 +0200 Subject: Add videos list filters --- server/tests/utils/index.ts | 1 + server/tests/utils/requests/check-api-params.ts | 13 ++-- server/tests/utils/search/videos.ts | 77 ++++++++++++++++++++++ server/tests/utils/videos/videos.ts | 86 ++++++++----------------- 4 files changed, 111 insertions(+), 66 deletions(-) create mode 100644 server/tests/utils/search/videos.ts (limited to 'server/tests/utils') diff --git a/server/tests/utils/index.ts b/server/tests/utils/index.ts index 5b560ca39..391db18cf 100644 --- a/server/tests/utils/index.ts +++ b/server/tests/utils/index.ts @@ -14,3 +14,4 @@ export * from './videos/video-blacklist' export * from './videos/video-channels' export * from './videos/videos' export * from './feeds/feeds' +export * from './search/videos' diff --git a/server/tests/utils/requests/check-api-params.ts b/server/tests/utils/requests/check-api-params.ts index 7550eb3d8..edb47e0e9 100644 --- a/server/tests/utils/requests/check-api-params.ts +++ b/server/tests/utils/requests/check-api-params.ts @@ -1,31 +1,32 @@ import { makeGetRequest } from './requests' +import { immutableAssign } from '..' -function checkBadStartPagination (url: string, path: string, token?: string) { +function checkBadStartPagination (url: string, path: string, token?: string, query = {}) { return makeGetRequest({ url, path, token, - query: { start: 'hello' }, + query: immutableAssign(query, { start: 'hello' }), statusCodeExpected: 400 }) } -function checkBadCountPagination (url: string, path: string, token?: string) { +function checkBadCountPagination (url: string, path: string, token?: string, query = {}) { return makeGetRequest({ url, path, token, - query: { count: 'hello' }, + query: immutableAssign(query, { count: 'hello' }), statusCodeExpected: 400 }) } -function checkBadSortPagination (url: string, path: string, token?: string) { +function checkBadSortPagination (url: string, path: string, token?: string, query = {}) { return makeGetRequest({ url, path, token, - query: { sort: 'hello' }, + query: immutableAssign(query, { sort: 'hello' }), statusCodeExpected: 400 }) } diff --git a/server/tests/utils/search/videos.ts b/server/tests/utils/search/videos.ts new file mode 100644 index 000000000..3a0c10e42 --- /dev/null +++ b/server/tests/utils/search/videos.ts @@ -0,0 +1,77 @@ +/* tslint:disable:no-unused-expression */ + +import * as request from 'supertest' +import { VideosSearchQuery } from '../../../../shared/models/search' +import { immutableAssign } from '..' + +function searchVideo (url: string, search: string) { + const path = '/api/v1/search/videos' + const req = request(url) + .get(path) + .query({ sort: '-publishedAt', search }) + .set('Accept', 'application/json') + + return req.expect(200) + .expect('Content-Type', /json/) +} + +function searchVideoWithToken (url: string, search: string, token: string, query: { nsfw?: boolean } = {}) { + const path = '/api/v1/search/videos' + const req = request(url) + .get(path) + .set('Authorization', 'Bearer ' + token) + .query(immutableAssign(query, { sort: '-publishedAt', search })) + .set('Accept', 'application/json') + + return req.expect(200) + .expect('Content-Type', /json/) +} + +function searchVideoWithPagination (url: string, search: string, start: number, count: number, sort?: string) { + const path = '/api/v1/search/videos' + + const req = request(url) + .get(path) + .query({ start }) + .query({ search }) + .query({ count }) + + if (sort) req.query({ sort }) + + return req.set('Accept', 'application/json') + .expect(200) + .expect('Content-Type', /json/) +} + +function searchVideoWithSort (url: string, search: string, sort: string) { + const path = '/api/v1/search/videos' + + return request(url) + .get(path) + .query({ search }) + .query({ sort }) + .set('Accept', 'application/json') + .expect(200) + .expect('Content-Type', /json/) +} + +function advancedVideosSearch (url: string, options: VideosSearchQuery) { + const path = '/api/v1/search/videos' + + return request(url) + .get(path) + .query(options) + .set('Accept', 'application/json') + .expect(200) + .expect('Content-Type', /json/) +} + +// --------------------------------------------------------------------------- + +export { + searchVideo, + advancedVideosSearch, + searchVideoWithToken, + searchVideoWithPagination, + searchVideoWithSort +} diff --git a/server/tests/utils/videos/videos.ts b/server/tests/utils/videos/videos.ts index a42d0f043..8c49eb02b 100644 --- a/server/tests/utils/videos/videos.ts +++ b/server/tests/utils/videos/videos.ts @@ -7,7 +7,7 @@ import { extname, join } from 'path' import * as request from 'supertest' import { buildAbsoluteFixturePath, - getMyUserInformation, + getMyUserInformation, immutableAssign, makeGetRequest, makePutBodyRequest, makeUploadRequest, @@ -133,13 +133,13 @@ function getVideosList (url: string) { .expect('Content-Type', /json/) } -function getVideosListWithToken (url: string, token: string) { +function getVideosListWithToken (url: string, token: string, query: { nsfw?: boolean } = {}) { const path = '/api/v1/videos' return request(url) .get(path) .set('Authorization', 'Bearer ' + token) - .query({ sort: 'name' }) + .query(immutableAssign(query, { sort: 'name' })) .set('Accept', 'application/json') .expect(200) .expect('Content-Type', /json/) @@ -172,17 +172,25 @@ function getMyVideos (url: string, accessToken: string, start: number, count: nu .expect('Content-Type', /json/) } -function getAccountVideos (url: string, accessToken: string, accountName: string, start: number, count: number, sort?: string) { +function getAccountVideos ( + url: string, + accessToken: string, + accountName: string, + start: number, + count: number, + sort?: string, + query: { nsfw?: boolean } = {} +) { const path = '/api/v1/accounts/' + accountName + '/videos' return makeGetRequest({ url, path, - query: { + query: immutableAssign(query, { start, count, sort - }, + }), token: accessToken, statusCodeExpected: 200 }) @@ -194,18 +202,19 @@ function getVideoChannelVideos ( videoChannelId: number | string, start: number, count: number, - sort?: string + sort?: string, + query: { nsfw?: boolean } = {} ) { const path = '/api/v1/video-channels/' + videoChannelId + '/videos' return makeGetRequest({ url, path, - query: { + query: immutableAssign(query, { start, count, sort - }, + }), token: accessToken, statusCodeExpected: 200 }) @@ -237,65 +246,25 @@ function getVideosListSort (url: string, sort: string) { .expect('Content-Type', /json/) } -function removeVideo (url: string, token: string, id: number | string, expectedStatus = 204) { +function getVideosWithFilters (url: string, query: { tagsAllOf: string[], categoryOneOf: number[] | number }) { const path = '/api/v1/videos' return request(url) - .delete(path + '/' + id) - .set('Accept', 'application/json') - .set('Authorization', 'Bearer ' + token) - .expect(expectedStatus) -} - -function searchVideo (url: string, search: string) { - const path = '/api/v1/search/videos' - const req = request(url) .get(path) - .query({ search }) + .query(query) .set('Accept', 'application/json') - - return req.expect(200) + .expect(200) .expect('Content-Type', /json/) } -function searchVideoWithToken (url: string, search: string, token: string) { +function removeVideo (url: string, token: string, id: number | string, expectedStatus = 204) { const path = '/api/v1/videos' - const req = request(url) - .get(path + '/search') - .set('Authorization', 'Bearer ' + token) - .query({ search }) - .set('Accept', 'application/json') - - return req.expect(200) - .expect('Content-Type', /json/) -} - -function searchVideoWithPagination (url: string, search: string, start: number, count: number, sort?: string) { - const path = '/api/v1/search/videos' - - const req = request(url) - .get(path) - .query({ start }) - .query({ search }) - .query({ count }) - - if (sort) req.query({ sort }) - - return req.set('Accept', 'application/json') - .expect(200) - .expect('Content-Type', /json/) -} - -function searchVideoWithSort (url: string, search: string, sort: string) { - const path = '/api/v1/search/videos' return request(url) - .get(path) - .query({ search }) - .query({ sort }) + .delete(path + '/' + id) .set('Accept', 'application/json') - .expect(200) - .expect('Content-Type', /json/) + .set('Authorization', 'Bearer ' + token) + .expect(expectedStatus) } async function checkVideoFilesWereRemoved (videoUUID: string, serverNumber: number) { @@ -581,18 +550,15 @@ export { getMyVideos, getAccountVideos, getVideoChannelVideos, - searchVideoWithToken, getVideo, getVideoWithToken, getVideosList, getVideosListPagination, getVideosListSort, removeVideo, - searchVideo, - searchVideoWithPagination, - searchVideoWithSort, getVideosListWithToken, uploadVideo, + getVideosWithFilters, updateVideo, rateVideo, viewVideo, -- cgit v1.2.3