aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/feeds
diff options
context:
space:
mode:
Diffstat (limited to 'shared/extra-utils/feeds')
-rw-r--r--shared/extra-utils/feeds/feeds.ts55
-rw-r--r--shared/extra-utils/feeds/index.ts1
2 files changed, 33 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}
diff --git a/shared/extra-utils/feeds/index.ts b/shared/extra-utils/feeds/index.ts
new file mode 100644
index 000000000..4634cb163
--- /dev/null
+++ b/shared/extra-utils/feeds/index.ts
@@ -0,0 +1 @@
export * from './feeds'