aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/feeds/feeds.ts
blob: ce0a98c6d65dc4a9e1e86ffe4259227f886bb257 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import * as request from 'supertest'
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'

type FeedType = 'videos' | 'video-comments' | 'subscriptions'

function getXMLfeed (url: string, feed: FeedType, format?: string) {
  const path = '/feeds/' + feed + '.xml'

  return request(url)
          .get(path)
          .query((format) ? { format: format } : {})
          .set('Accept', 'application/xml')
          .expect(HttpStatusCode.OK_200)
          .expect('Content-Type', /xml/)
}

function getJSONfeed (url: string, feed: FeedType, query: any = {}, statusCodeExpected = HttpStatusCode.OK_200) {
  const path = '/feeds/' + feed + '.json'

  return request(url)
          .get(path)
          .query(query)
          .set('Accept', 'application/json')
          .expect(statusCodeExpected)
          .expect('Content-Type', /json/)
}

// ---------------------------------------------------------------------------

export {
  getXMLfeed,
  getJSONfeed
}