aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/requests
diff options
context:
space:
mode:
Diffstat (limited to 'shared/extra-utils/requests')
-rw-r--r--shared/extra-utils/requests/requests.ts58
1 files changed, 30 insertions, 28 deletions
diff --git a/shared/extra-utils/requests/requests.ts b/shared/extra-utils/requests/requests.ts
index 3532fb429..61167f212 100644
--- a/shared/extra-utils/requests/requests.ts
+++ b/shared/extra-utils/requests/requests.ts
@@ -1,25 +1,27 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */
2
1import * as request from 'supertest' 3import * as request from 'supertest'
2import { buildAbsoluteFixturePath, root } from '../miscs/miscs' 4import { buildAbsoluteFixturePath, root } from '../miscs/miscs'
3import { isAbsolute, join } from 'path' 5import { isAbsolute, join } from 'path'
4import { parse } from 'url' 6import { URL } from 'url'
5 7
6function get4KFileUrl () { 8function get4KFileUrl () {
7 return 'https://download.cpy.re/peertube/4k_file.txt' 9 return 'https://download.cpy.re/peertube/4k_file.txt'
8} 10}
9 11
10function makeRawRequest (url: string, statusCodeExpected?: number, range?: string) { 12function makeRawRequest (url: string, statusCodeExpected?: number, range?: string) {
11 const { host, protocol, pathname } = parse(url) 13 const { host, protocol, pathname } = new URL(url)
12 14
13 return makeGetRequest({ url: `${protocol}//${host}`, path: pathname, statusCodeExpected, range }) 15 return makeGetRequest({ url: `${protocol}//${host}`, path: pathname, statusCodeExpected, range })
14} 16}
15 17
16function makeGetRequest (options: { 18function makeGetRequest (options: {
17 url: string, 19 url: string
18 path?: string, 20 path?: string
19 query?: any, 21 query?: any
20 token?: string, 22 token?: string
21 statusCodeExpected?: number, 23 statusCodeExpected?: number
22 contentType?: string, 24 contentType?: string
23 range?: string 25 range?: string
24}) { 26}) {
25 if (!options.statusCodeExpected) options.statusCodeExpected = 400 27 if (!options.statusCodeExpected) options.statusCodeExpected = 400
@@ -36,9 +38,9 @@ function makeGetRequest (options: {
36} 38}
37 39
38function makeDeleteRequest (options: { 40function makeDeleteRequest (options: {
39 url: string, 41 url: string
40 path: string, 42 path: string
41 token?: string, 43 token?: string
42 statusCodeExpected?: number 44 statusCodeExpected?: number
43}) { 45}) {
44 if (!options.statusCodeExpected) options.statusCodeExpected = 400 46 if (!options.statusCodeExpected) options.statusCodeExpected = 400
@@ -53,12 +55,12 @@ function makeDeleteRequest (options: {
53} 55}
54 56
55function makeUploadRequest (options: { 57function makeUploadRequest (options: {
56 url: string, 58 url: string
57 method?: 'POST' | 'PUT', 59 method?: 'POST' | 'PUT'
58 path: string, 60 path: string
59 token?: string, 61 token?: string
60 fields: { [ fieldName: string ]: any }, 62 fields: { [ fieldName: string ]: any }
61 attaches: { [ attachName: string ]: any | any[] }, 63 attaches: { [ attachName: string ]: any | any[] }
62 statusCodeExpected?: number 64 statusCodeExpected?: number
63}) { 65}) {
64 if (!options.statusCodeExpected) options.statusCodeExpected = 400 66 if (!options.statusCodeExpected) options.statusCodeExpected = 400
@@ -101,10 +103,10 @@ function makeUploadRequest (options: {
101} 103}
102 104
103function makePostBodyRequest (options: { 105function makePostBodyRequest (options: {
104 url: string, 106 url: string
105 path: string, 107 path: string
106 token?: string, 108 token?: string
107 fields?: { [ fieldName: string ]: any }, 109 fields?: { [ fieldName: string ]: any }
108 statusCodeExpected?: number 110 statusCodeExpected?: number
109}) { 111}) {
110 if (!options.fields) options.fields = {} 112 if (!options.fields) options.fields = {}
@@ -121,10 +123,10 @@ function makePostBodyRequest (options: {
121} 123}
122 124
123function makePutBodyRequest (options: { 125function makePutBodyRequest (options: {
124 url: string, 126 url: string
125 path: string, 127 path: string
126 token?: string, 128 token?: string
127 fields: { [ fieldName: string ]: any }, 129 fields: { [ fieldName: string ]: any }
128 statusCodeExpected?: number 130 statusCodeExpected?: number
129}) { 131}) {
130 if (!options.statusCodeExpected) options.statusCodeExpected = 400 132 if (!options.statusCodeExpected) options.statusCodeExpected = 400
@@ -147,9 +149,9 @@ function makeHTMLRequest (url: string, path: string) {
147} 149}
148 150
149function updateAvatarRequest (options: { 151function updateAvatarRequest (options: {
150 url: string, 152 url: string
151 path: string, 153 path: string
152 accessToken: string, 154 accessToken: string
153 fixture: string 155 fixture: string
154}) { 156}) {
155 let filePath = '' 157 let filePath = ''