+/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */
+
import * as request from 'supertest'
import { buildAbsoluteFixturePath, root } from '../miscs/miscs'
import { isAbsolute, join } from 'path'
-import { parse } from 'url'
+import { URL } from 'url'
+import { decode } from 'querystring'
function get4KFileUrl () {
return 'https://download.cpy.re/peertube/4k_file.txt'
}
function makeRawRequest (url: string, statusCodeExpected?: number, range?: string) {
- const { host, protocol, pathname } = parse(url)
+ const { host, protocol, pathname } = new URL(url)
return makeGetRequest({ url: `${protocol}//${host}`, path: pathname, statusCodeExpected, range })
}
function makeGetRequest (options: {
- url: string,
- path?: string,
- query?: any,
- token?: string,
- statusCodeExpected?: number,
- contentType?: string,
+ url: string
+ path?: string
+ query?: any
+ token?: string
+ statusCodeExpected?: number
+ contentType?: string
range?: string
+ redirects?: number
}) {
if (!options.statusCodeExpected) options.statusCodeExpected = 400
if (options.contentType === undefined) options.contentType = 'application/json'
if (options.token) req.set('Authorization', 'Bearer ' + options.token)
if (options.query) req.query(options.query)
if (options.range) req.set('Range', options.range)
+ if (options.redirects) req.redirects(options.redirects)
return req.expect(options.statusCodeExpected)
}
function makeDeleteRequest (options: {
- url: string,
- path: string,
- token?: string,
+ url: string
+ path: string
+ token?: string
statusCodeExpected?: number
}) {
if (!options.statusCodeExpected) options.statusCodeExpected = 400
}
function makeUploadRequest (options: {
- url: string,
- method?: 'POST' | 'PUT',
- path: string,
- token?: string,
- fields: { [ fieldName: string ]: any },
- attaches: { [ attachName: string ]: any | any[] },
+ url: string
+ method?: 'POST' | 'PUT'
+ path: string
+ token?: string
+ fields: { [ fieldName: string ]: any }
+ attaches?: { [ attachName: string ]: any | any[] }
statusCodeExpected?: number
}) {
if (!options.statusCodeExpected) options.statusCodeExpected = 400
}
})
- Object.keys(options.attaches).forEach(attach => {
+ Object.keys(options.attaches || {}).forEach(attach => {
const value = options.attaches[attach]
if (Array.isArray(value)) {
req.attach(attach, buildAbsoluteFixturePath(value[0]), value[1])
}
function makePostBodyRequest (options: {
- url: string,
- path: string,
- token?: string,
- fields?: { [ fieldName: string ]: any },
+ url: string
+ path: string
+ token?: string
+ fields?: { [ fieldName: string ]: any }
statusCodeExpected?: number
}) {
if (!options.fields) options.fields = {}
}
function makePutBodyRequest (options: {
- url: string,
- path: string,
- token?: string,
- fields: { [ fieldName: string ]: any },
+ url: string
+ path: string
+ token?: string
+ fields: { [ fieldName: string ]: any }
statusCodeExpected?: number
}) {
if (!options.statusCodeExpected) options.statusCodeExpected = 400
}
function updateAvatarRequest (options: {
- url: string,
- path: string,
- accessToken: string,
+ url: string
+ path: string
+ accessToken: string
fixture: string
}) {
let filePath = ''
})
}
+function decodeQueryString (path: string) {
+ return decode(path.split('?')[1])
+}
+
// ---------------------------------------------------------------------------
export {
get4KFileUrl,
makeHTMLRequest,
makeGetRequest,
+ decodeQueryString,
makeUploadRequest,
makePostBodyRequest,
makePutBodyRequest,