aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-06 10:21:35 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:16 +0200
commitc1bc8ee4783d6ce3102524e6c2a02b2f0f6aab6d (patch)
tree6f173749e46a79e6eca0bfd1f742054fa7276e7e /shared
parente8bd7ce7ccafe3e064b03978e9b512c1a4cc99e6 (diff)
downloadPeerTube-c1bc8ee4783d6ce3102524e6c2a02b2f0f6aab6d.tar.gz
PeerTube-c1bc8ee4783d6ce3102524e6c2a02b2f0f6aab6d.tar.zst
PeerTube-c1bc8ee4783d6ce3102524e6c2a02b2f0f6aab6d.zip
Introduce feed command
Diffstat (limited to 'shared')
-rw-r--r--shared/extra-utils/feeds/feeds.ts55
-rw-r--r--shared/extra-utils/feeds/index.ts1
-rw-r--r--shared/extra-utils/requests/requests.ts9
-rw-r--r--shared/extra-utils/server/servers.ts3
-rw-r--r--shared/extra-utils/shared/abstract-command.ts28
5 files changed, 68 insertions, 28 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'
diff --git a/shared/extra-utils/requests/requests.ts b/shared/extra-utils/requests/requests.ts
index eb59ca600..8c26a3699 100644
--- a/shared/extra-utils/requests/requests.ts
+++ b/shared/extra-utils/requests/requests.ts
@@ -182,10 +182,14 @@ function decodeQueryString (path: string) {
182 return decode(path.split('?')[1]) 182 return decode(path.split('?')[1])
183} 183}
184 184
185function unwrap <T> (test: request.Test): Promise<T> { 185function unwrapBody <T> (test: request.Test): Promise<T> {
186 return test.then(res => res.body) 186 return test.then(res => res.body)
187} 187}
188 188
189function unwrapText (test: request.Test): Promise<string> {
190 return test.then(res => res.text)
191}
192
189// --------------------------------------------------------------------------- 193// ---------------------------------------------------------------------------
190 194
191export { 195export {
@@ -198,6 +202,7 @@ export {
198 makePutBodyRequest, 202 makePutBodyRequest,
199 makeDeleteRequest, 203 makeDeleteRequest,
200 makeRawRequest, 204 makeRawRequest,
201 unwrap, 205 unwrapBody,
206 unwrapText,
202 updateImageRequest 207 updateImageRequest
203} 208}
diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts
index e07926065..b64c9eec6 100644
--- a/shared/extra-utils/server/servers.ts
+++ b/shared/extra-utils/server/servers.ts
@@ -9,6 +9,7 @@ import { VideoChannel } from '../../models/videos'
9import { BulkCommand } from '../bulk' 9import { BulkCommand } from '../bulk'
10import { CLICommand } from '../cli' 10import { CLICommand } from '../cli'
11import { CustomPagesCommand } from '../custom-pages' 11import { CustomPagesCommand } from '../custom-pages'
12import { FeedCommand } from '../feeds'
12import { buildServerDirectory, getFileSize, isGithubCI, root, wait } from '../miscs/miscs' 13import { buildServerDirectory, getFileSize, isGithubCI, root, wait } from '../miscs/miscs'
13import { makeGetRequest } from '../requests/requests' 14import { makeGetRequest } from '../requests/requests'
14 15
@@ -67,6 +68,7 @@ interface ServerInfo {
67 bulkCommand?: BulkCommand 68 bulkCommand?: BulkCommand
68 cliCommand?: CLICommand 69 cliCommand?: CLICommand
69 customPageCommand?: CustomPagesCommand 70 customPageCommand?: CustomPagesCommand
71 feedCommand?: FeedCommand
70} 72}
71 73
72function parallelTests () { 74function parallelTests () {
@@ -275,6 +277,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = []
275 server.bulkCommand = new BulkCommand(server) 277 server.bulkCommand = new BulkCommand(server)
276 server.cliCommand = new CLICommand(server) 278 server.cliCommand = new CLICommand(server)
277 server.customPageCommand = new CustomPagesCommand(server) 279 server.customPageCommand = new CustomPagesCommand(server)
280 server.feedCommand = new FeedCommand(server)
278 281
279 res(server) 282 res(server)
280 }) 283 })
diff --git a/shared/extra-utils/shared/abstract-command.ts b/shared/extra-utils/shared/abstract-command.ts
index d8eba373d..53c644124 100644
--- a/shared/extra-utils/shared/abstract-command.ts
+++ b/shared/extra-utils/shared/abstract-command.ts
@@ -1,5 +1,5 @@
1import { HttpStatusCode } from '@shared/core-utils' 1import { HttpStatusCode } from '@shared/core-utils'
2import { makeGetRequest, makePostBodyRequest, makePutBodyRequest, unwrap } from '../requests/requests' 2import { makeGetRequest, makePostBodyRequest, makePutBodyRequest, unwrap, unwrapBody, unwrapText } from '../requests/requests'
3import { ServerInfo } from '../server/servers' 3import { ServerInfo } from '../server/servers'
4 4
5export interface OverrideCommandOptions { 5export interface OverrideCommandOptions {
@@ -12,6 +12,12 @@ interface CommonCommandOptions extends OverrideCommandOptions {
12 defaultExpectedStatus: number 12 defaultExpectedStatus: number
13} 13}
14 14
15interface GetCommandOptions extends CommonCommandOptions {
16 query?: { [ id: string ]: string }
17 contentType?: string
18 accept?: string
19}
20
15abstract class AbstractCommand { 21abstract class AbstractCommand {
16 22
17 private expectedStatus: HttpStatusCode 23 private expectedStatus: HttpStatusCode
@@ -30,8 +36,12 @@ abstract class AbstractCommand {
30 this.expectedStatus = status 36 this.expectedStatus = status
31 } 37 }
32 38
33 protected getRequestBody <T> (options: CommonCommandOptions) { 39 protected getRequestBody <T> (options: GetCommandOptions) {
34 return unwrap<T>(makeGetRequest(this.buildCommonRequestOptions(options))) 40 return unwrapBody<T>(this.getRequest(options))
41 }
42
43 protected getRequestText (options: GetCommandOptions) {
44 return unwrapText(this.getRequest(options))
35 } 45 }
36 46
37 protected putBodyRequest (options: CommonCommandOptions & { 47 protected putBodyRequest (options: CommonCommandOptions & {
@@ -68,6 +78,18 @@ abstract class AbstractCommand {
68 statusCodeExpected: expectedStatus ?? this.expectedStatus ?? defaultExpectedStatus 78 statusCodeExpected: expectedStatus ?? this.expectedStatus ?? defaultExpectedStatus
69 } 79 }
70 } 80 }
81
82 private getRequest (options: GetCommandOptions) {
83 const { query, contentType, accept } = options
84
85 return makeGetRequest({
86 ...this.buildCommonRequestOptions(options),
87
88 query,
89 contentType,
90 accept
91 })
92 }
71} 93}
72 94
73export { 95export {