feeds.ts 991 B

123456789101112131415161718192021222324252627282930313233
  1. import * as request from 'supertest'
  2. import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
  3. type FeedType = 'videos' | 'video-comments' | 'subscriptions'
  4. function getXMLfeed (url: string, feed: FeedType, format?: string) {
  5. const path = '/feeds/' + feed + '.xml'
  6. return request(url)
  7. .get(path)
  8. .query((format) ? { format: format } : {})
  9. .set('Accept', 'application/xml')
  10. .expect(HttpStatusCode.OK_200)
  11. .expect('Content-Type', /xml/)
  12. }
  13. function getJSONfeed (url: string, feed: FeedType, query: any = {}, statusCodeExpected = HttpStatusCode.OK_200) {
  14. const path = '/feeds/' + feed + '.json'
  15. return request(url)
  16. .get(path)
  17. .query(query)
  18. .set('Accept', 'application/json')
  19. .expect(statusCodeExpected)
  20. .expect('Content-Type', /json/)
  21. }
  22. // ---------------------------------------------------------------------------
  23. export {
  24. getXMLfeed,
  25. getJSONfeed
  26. }