From 94565d52bb2883e09f16d1363170ac9c0dccb7a1 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 15 Apr 2019 15:26:15 +0200 Subject: Shared utils -> extra-utils Because they need dev dependencies --- shared/extra-utils/search/video-channels.ts | 22 +++++++++ shared/extra-utils/search/videos.ts | 77 +++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 shared/extra-utils/search/video-channels.ts create mode 100644 shared/extra-utils/search/videos.ts (limited to 'shared/extra-utils/search') diff --git a/shared/extra-utils/search/video-channels.ts b/shared/extra-utils/search/video-channels.ts new file mode 100644 index 000000000..0532134ae --- /dev/null +++ b/shared/extra-utils/search/video-channels.ts @@ -0,0 +1,22 @@ +import { makeGetRequest } from '../requests/requests' + +function searchVideoChannel (url: string, search: string, token?: string, statusCodeExpected = 200) { + const path = '/api/v1/search/video-channels' + + return makeGetRequest({ + url, + path, + query: { + sort: '-createdAt', + search + }, + token, + statusCodeExpected + }) +} + +// --------------------------------------------------------------------------- + +export { + searchVideoChannel +} diff --git a/shared/extra-utils/search/videos.ts b/shared/extra-utils/search/videos.ts new file mode 100644 index 000000000..ba4627017 --- /dev/null +++ b/shared/extra-utils/search/videos.ts @@ -0,0 +1,77 @@ +/* tslint:disable:no-unused-expression */ + +import * as request from 'supertest' +import { VideosSearchQuery } from '../../models/search' +import { immutableAssign } from '../miscs/miscs' + +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 +} -- cgit v1.2.3