From c1bc8ee4783d6ce3102524e6c2a02b2f0f6aab6d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Jul 2021 10:21:35 +0200 Subject: Introduce feed command --- shared/extra-utils/feeds/feeds.ts | 55 +++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 23 deletions(-) (limited to 'shared/extra-utils/feeds/feeds.ts') 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 @@ -import * as request from 'supertest' + import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' +import { AbstractCommand, OverrideCommandOptions } from '../shared' type FeedType = 'videos' | 'video-comments' | 'subscriptions' -function getXMLfeed (url: string, feed: FeedType, format?: string) { - const path = '/feeds/' + feed + '.xml' +export class FeedCommand extends AbstractCommand { - return request(url) - .get(path) - .query((format) ? { format: format } : {}) - .set('Accept', 'application/xml') - .expect(HttpStatusCode.OK_200) - .expect('Content-Type', /xml/) -} + getXML (options: OverrideCommandOptions & { + feed: FeedType + format?: string + }) { + const { feed, format } = options + const path = '/feeds/' + feed + '.xml' -function getJSONfeed (url: string, feed: FeedType, query: any = {}, statusCodeExpected = HttpStatusCode.OK_200) { - const path = '/feeds/' + feed + '.json' + return this.getRequestText({ + ...options, - return request(url) - .get(path) - .query(query) - .set('Accept', 'application/json') - .expect(statusCodeExpected) - .expect('Content-Type', /json/) -} + path, + query: format ? { format } : undefined, + accept: 'application/xml', + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + getJSON (options: OverrideCommandOptions & { + feed: FeedType + query?: { [ id: string ]: any } + }) { + const { feed, query } = options + const path = '/feeds/' + feed + '.json' -// --------------------------------------------------------------------------- + return this.getRequestText({ + ...options, -export { - getXMLfeed, - getJSONfeed + path, + query, + accept: 'application/json', + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } } -- cgit v1.2.3 From f59545d97a80bf06025bf6343a80d834c7eb237f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Jul 2021 10:22:37 +0200 Subject: Rename command files --- shared/extra-utils/feeds/feeds.ts | 42 --------------------------------------- 1 file changed, 42 deletions(-) delete mode 100644 shared/extra-utils/feeds/feeds.ts (limited to 'shared/extra-utils/feeds/feeds.ts') diff --git a/shared/extra-utils/feeds/feeds.ts b/shared/extra-utils/feeds/feeds.ts deleted file mode 100644 index 012ce6cfe..000000000 --- a/shared/extra-utils/feeds/feeds.ts +++ /dev/null @@ -1,42 +0,0 @@ - -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' -import { AbstractCommand, OverrideCommandOptions } from '../shared' - -type FeedType = 'videos' | 'video-comments' | 'subscriptions' - -export class FeedCommand extends AbstractCommand { - - getXML (options: OverrideCommandOptions & { - feed: FeedType - format?: string - }) { - const { feed, format } = options - const path = '/feeds/' + feed + '.xml' - - return this.getRequestText({ - ...options, - - path, - query: format ? { format } : undefined, - accept: 'application/xml', - defaultExpectedStatus: HttpStatusCode.OK_200 - }) - } - - getJSON (options: OverrideCommandOptions & { - feed: FeedType - query?: { [ id: string ]: any } - }) { - const { feed, query } = options - const path = '/feeds/' + feed + '.json' - - return this.getRequestText({ - ...options, - - path, - query, - accept: 'application/json', - defaultExpectedStatus: HttpStatusCode.OK_200 - }) - } -} -- cgit v1.2.3