PeerTube/shared/extra-utils/feeds/feeds.ts

34 lines
991 B
TypeScript
Raw Normal View History

import * as request from 'supertest'
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
2020-11-09 09:25:27 -06:00
type FeedType = 'videos' | 'video-comments' | 'subscriptions'
2018-06-08 13:34:37 -05:00
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) {
2018-06-08 13:34:37 -05:00
const path = '/feeds/' + feed + '.json'
return request(url)
.get(path)
2018-09-13 02:48:34 -05:00
.query(query)
.set('Accept', 'application/json')
2020-11-25 04:04:18 -06:00
.expect(statusCodeExpected)
.expect('Content-Type', /json/)
}
// ---------------------------------------------------------------------------
export {
getXMLfeed,
getJSONfeed
}