mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-02-25 18:55:32 -06:00
emit more specific status codes on video upload (#3423)
- reduce http status codes list to potentially useful codes - convert more codes to typed ones - factorize html generator for error responses
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import * as request from 'supertest'
|
||||
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
|
||||
|
||||
function makeActivityPubGetRequest (url: string, path: string, expectedStatus = 200) {
|
||||
function makeActivityPubGetRequest (url: string, path: string, expectedStatus = HttpStatusCode.OK_200) {
|
||||
return request(url)
|
||||
.get(path)
|
||||
.set('Accept', 'application/activity+json,text/html;q=0.9,\\*/\\*;q=0.8')
|
||||
|
||||
@@ -2,7 +2,13 @@ import { makeDeleteRequest, makeGetRequest, makePostBodyRequest, makePutBodyRequ
|
||||
import { VideoRedundanciesTarget } from '@shared/models'
|
||||
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
|
||||
|
||||
function updateRedundancy (url: string, accessToken: string, host: string, redundancyAllowed: boolean, expectedStatus = 204) {
|
||||
function updateRedundancy (
|
||||
url: string,
|
||||
accessToken: string,
|
||||
host: string,
|
||||
redundancyAllowed: boolean,
|
||||
expectedStatus = HttpStatusCode.NO_CONTENT_204
|
||||
) {
|
||||
const path = '/api/v1/server/redundancy/' + host
|
||||
|
||||
return makePutBodyRequest({
|
||||
|
||||
@@ -2,12 +2,13 @@ import * as request from 'supertest'
|
||||
|
||||
import { ServerInfo } from '../server/servers'
|
||||
import { getClient } from '../server/clients'
|
||||
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
|
||||
|
||||
type Client = { id: string, secret: string }
|
||||
type User = { username: string, password: string }
|
||||
type Server = { url: string, client: Client, user: User }
|
||||
|
||||
function login (url: string, client: Client, user: User, expectedStatus = 200) {
|
||||
function login (url: string, client: Client, user: User, expectedStatus = HttpStatusCode.OK_200) {
|
||||
const path = '/api/v1/users/token'
|
||||
|
||||
const body = {
|
||||
@@ -27,7 +28,7 @@ function login (url: string, client: Client, user: User, expectedStatus = 200) {
|
||||
.expect(expectedStatus)
|
||||
}
|
||||
|
||||
function logout (url: string, token: string, expectedStatus = 200) {
|
||||
function logout (url: string, token: string, expectedStatus = HttpStatusCode.OK_200) {
|
||||
const path = '/api/v1/users/revoke-token'
|
||||
|
||||
return request(url)
|
||||
@@ -38,12 +39,12 @@ function logout (url: string, token: string, expectedStatus = 200) {
|
||||
}
|
||||
|
||||
async function serverLogin (server: Server) {
|
||||
const res = await login(server.url, server.client, server.user, 200)
|
||||
const res = await login(server.url, server.client, server.user, HttpStatusCode.OK_200)
|
||||
|
||||
return res.body.access_token as string
|
||||
}
|
||||
|
||||
function refreshToken (server: ServerInfo, refreshToken: string, expectedStatus = 200) {
|
||||
function refreshToken (server: ServerInfo, refreshToken: string, expectedStatus = HttpStatusCode.OK_200) {
|
||||
const path = '/api/v1/users/token'
|
||||
|
||||
const body = {
|
||||
@@ -61,7 +62,7 @@ function refreshToken (server: ServerInfo, refreshToken: string, expectedStatus
|
||||
.expect(expectedStatus)
|
||||
}
|
||||
|
||||
async function userLogin (server: Server, user: User, expectedStatus = 200) {
|
||||
async function userLogin (server: Server, user: User, expectedStatus = HttpStatusCode.OK_200) {
|
||||
const res = await login(server.url, server.client, user, expectedStatus)
|
||||
|
||||
return res.body.access_token as string
|
||||
@@ -95,7 +96,7 @@ function setAccessTokensToServers (servers: ServerInfo[]) {
|
||||
return Promise.all(tasks)
|
||||
}
|
||||
|
||||
function loginUsingExternalToken (server: Server, username: string, externalAuthToken: string, expectedStatus = 200) {
|
||||
function loginUsingExternalToken (server: Server, username: string, externalAuthToken: string, expectedStatus = HttpStatusCode.OK_200) {
|
||||
const path = '/api/v1/users/token'
|
||||
|
||||
const body = {
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests'
|
||||
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
|
||||
|
||||
function userWatchVideo (url: string, token: string, videoId: number | string, currentTime: number, statusCodeExpected = 204) {
|
||||
function userWatchVideo (
|
||||
url: string,
|
||||
token: string,
|
||||
videoId: number | string,
|
||||
currentTime: number,
|
||||
statusCodeExpected = HttpStatusCode.NO_CONTENT_204
|
||||
) {
|
||||
const path = '/api/v1/videos/' + videoId + '/watching'
|
||||
const fields = { currentTime }
|
||||
|
||||
|
||||
@@ -155,7 +155,7 @@ function getVideosListWithToken (url: string, token: string, query: { nsfw?: boo
|
||||
.set('Authorization', 'Bearer ' + token)
|
||||
.query(immutableAssign(query, { sort: 'name' }))
|
||||
.set('Accept', 'application/json')
|
||||
.expect(200)
|
||||
.expect(HttpStatusCode.OK_200)
|
||||
.expect('Content-Type', /json/)
|
||||
}
|
||||
|
||||
@@ -166,7 +166,7 @@ function getLocalVideos (url: string) {
|
||||
.get(path)
|
||||
.query({ sort: 'name', filter: 'local' })
|
||||
.set('Accept', 'application/json')
|
||||
.expect(200)
|
||||
.expect(HttpStatusCode.OK_200)
|
||||
.expect('Content-Type', /json/)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user