videos.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* tslint:disable:no-unused-expression */
  2. import * as request from 'supertest'
  3. import { VideosSearchQuery } from '../../models/search'
  4. import { immutableAssign } from '../miscs/miscs'
  5. function searchVideo (url: string, search: string) {
  6. const path = '/api/v1/search/videos'
  7. const query = { sort: '-publishedAt', search: search }
  8. const req = request(url)
  9. .get(path)
  10. .query(query)
  11. .set('Accept', 'application/json')
  12. return req.expect(200)
  13. .expect('Content-Type', /json/)
  14. }
  15. function searchVideoWithToken (url: string, search: string, token: string, query: { nsfw?: boolean } = {}) {
  16. const path = '/api/v1/search/videos'
  17. const req = request(url)
  18. .get(path)
  19. .set('Authorization', 'Bearer ' + token)
  20. .query(immutableAssign(query, { sort: '-publishedAt', search }))
  21. .set('Accept', 'application/json')
  22. return req.expect(200)
  23. .expect('Content-Type', /json/)
  24. }
  25. function searchVideoWithSort (url: string, search: string, sort: string) {
  26. const path = '/api/v1/search/videos'
  27. const query = { search, sort }
  28. return request(url)
  29. .get(path)
  30. .query(query)
  31. .set('Accept', 'application/json')
  32. .expect(200)
  33. .expect('Content-Type', /json/)
  34. }
  35. function advancedVideosSearch (url: string, options: VideosSearchQuery) {
  36. const path = '/api/v1/search/videos'
  37. return request(url)
  38. .get(path)
  39. .query(options)
  40. .set('Accept', 'application/json')
  41. .expect(200)
  42. .expect('Content-Type', /json/)
  43. }
  44. // ---------------------------------------------------------------------------
  45. export {
  46. searchVideo,
  47. advancedVideosSearch,
  48. searchVideoWithToken,
  49. searchVideoWithSort
  50. }