aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/feeds/feeds.ts
diff options
context:
space:
mode:
Diffstat (limited to 'shared/extra-utils/feeds/feeds.ts')
-rw-r--r--shared/extra-utils/feeds/feeds.ts55
1 files changed, 32 insertions, 23 deletions
diff --git a/shared/extra-utils/feeds/feeds.ts b/shared/extra-utils/feeds/feeds.ts
index ce0a98c6d..012ce6cfe 100644
--- a/shared/extra-utils/feeds/feeds.ts
+++ b/shared/extra-utils/feeds/feeds.ts
@@ -1,33 +1,42 @@
1import * as request from 'supertest' 1
2import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' 2import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
3import { AbstractCommand, OverrideCommandOptions } from '../shared'
3 4
4type FeedType = 'videos' | 'video-comments' | 'subscriptions' 5type FeedType = 'videos' | 'video-comments' | 'subscriptions'
5 6
6function getXMLfeed (url: string, feed: FeedType, format?: string) { 7export class FeedCommand extends AbstractCommand {
7 const path = '/feeds/' + feed + '.xml'
8 8
9 return request(url) 9 getXML (options: OverrideCommandOptions & {
10 .get(path) 10 feed: FeedType
11 .query((format) ? { format: format } : {}) 11 format?: string
12 .set('Accept', 'application/xml') 12 }) {
13 .expect(HttpStatusCode.OK_200) 13 const { feed, format } = options
14 .expect('Content-Type', /xml/) 14 const path = '/feeds/' + feed + '.xml'
15}
16 15
17function getJSONfeed (url: string, feed: FeedType, query: any = {}, statusCodeExpected = HttpStatusCode.OK_200) { 16 return this.getRequestText({
18 const path = '/feeds/' + feed + '.json' 17 ...options,
19 18
20 return request(url) 19 path,
21 .get(path) 20 query: format ? { format } : undefined,
22 .query(query) 21 accept: 'application/xml',
23 .set('Accept', 'application/json') 22 defaultExpectedStatus: HttpStatusCode.OK_200
24 .expect(statusCodeExpected) 23 })
25 .expect('Content-Type', /json/) 24 }
26} 25
26 getJSON (options: OverrideCommandOptions & {
27 feed: FeedType
28 query?: { [ id: string ]: any }
29 }) {
30 const { feed, query } = options
31 const path = '/feeds/' + feed + '.json'
27 32
28// --------------------------------------------------------------------------- 33 return this.getRequestText({
34 ...options,
29 35
30export { 36 path,
31 getXMLfeed, 37 query,
32 getJSONfeed 38 accept: 'application/json',
39 defaultExpectedStatus: HttpStatusCode.OK_200
40 })
41 }
33} 42}