1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-05 02:39:33 +02:00

replace numbers with typed http status codes (#3409)

This commit is contained in:
Rigel Kent 2020-12-07 14:32:36 +01:00 committed by GitHub
parent adc1f09c0d
commit 2d53be0267
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
149 changed files with 1721 additions and 1108 deletions

View file

@ -47,6 +47,7 @@ import { follow } from '../../../../shared/extra-utils/server/follows'
import { logout, serverLogin, setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'
import { getMyVideos } from '../../../../shared/extra-utils/videos/videos'
import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
const expect = chai.expect
@ -86,14 +87,14 @@ describe('Test users', function () {
it('Should not login with an invalid client id', async function () {
const client = { id: 'client', secret: server.client.secret }
const res = await login(server.url, client, server.user, 400)
const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400)
expect(res.body.error).to.contain('client is invalid')
})
it('Should not login with an invalid client secret', async function () {
const client = { id: server.client.id, secret: 'coucou' }
const res = await login(server.url, client, server.user, 400)
const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400)
expect(res.body.error).to.contain('client is invalid')
})
@ -103,14 +104,14 @@ describe('Test users', function () {
it('Should not login with an invalid username', async function () {
const user = { username: 'captain crochet', password: server.user.password }
const res = await login(server.url, server.client, user, 400)
const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400)
expect(res.body.error).to.contain('credentials are invalid')
})
it('Should not login with an invalid password', async function () {
const user = { username: server.user.username, password: 'mew_three' }
const res = await login(server.url, server.client, user, 400)
const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400)
expect(res.body.error).to.contain('credentials are invalid')
})
@ -119,31 +120,31 @@ describe('Test users', function () {
accessToken = 'my_super_token'
const videoAttributes = {}
await uploadVideo(server.url, accessToken, videoAttributes, 401)
await uploadVideo(server.url, accessToken, videoAttributes, HttpStatusCode.UNAUTHORIZED_401)
})
it('Should not be able to follow', async function () {
accessToken = 'my_super_token'
await follow(server.url, [ 'http://example.com' ], accessToken, 401)
await follow(server.url, [ 'http://example.com' ], accessToken, HttpStatusCode.UNAUTHORIZED_401)
})
it('Should not be able to unfollow')
it('Should be able to login', async function () {
const res = await login(server.url, server.client, server.user, 200)
const res = await login(server.url, server.client, server.user, HttpStatusCode.OK_200)
accessToken = res.body.access_token
})
it('Should be able to login with an insensitive username', async function () {
const user = { username: 'RoOt', password: server.user.password }
await login(server.url, server.client, user, 200)
await login(server.url, server.client, user, HttpStatusCode.OK_200)
const user2 = { username: 'rOoT', password: server.user.password }
await login(server.url, server.client, user2, 200)
await login(server.url, server.client, user2, HttpStatusCode.OK_200)
const user3 = { username: 'ROOt', password: server.user.password }
await login(server.url, server.client, user3, 200)
await login(server.url, server.client, user3, HttpStatusCode.OK_200)
})
})
@ -179,7 +180,7 @@ describe('Test users', function () {
it('Should retrieve ratings list', async function () {
await rateVideo(server.url, accessToken, videoId, 'like')
const res = await getAccountRatings(server.url, server.user.username, server.accessToken, null, 200)
const res = await getAccountRatings(server.url, server.user.username, server.accessToken, null, HttpStatusCode.OK_200)
const ratings = res.body
expect(ratings.total).to.equal(1)
@ -204,7 +205,7 @@ describe('Test users', function () {
describe('Remove video', function () {
it('Should not be able to remove the video with an incorrect token', async function () {
await removeVideo(server.url, 'bad_token', videoId, 401)
await removeVideo(server.url, 'bad_token', videoId, HttpStatusCode.UNAUTHORIZED_401)
})
it('Should not be able to remove the video with the token of another account')
@ -220,11 +221,11 @@ describe('Test users', function () {
})
it('Should not be able to get the user information', async function () {
await getMyUserInformation(server.url, server.accessToken, 401)
await getMyUserInformation(server.url, server.accessToken, HttpStatusCode.UNAUTHORIZED_401)
})
it('Should not be able to upload a video', async function () {
await uploadVideo(server.url, server.accessToken, { name: 'video' }, 401)
await uploadVideo(server.url, server.accessToken, { name: 'video' }, HttpStatusCode.UNAUTHORIZED_401)
})
it('Should not be able to rate a video', async function () {
@ -238,7 +239,7 @@ describe('Test users', function () {
path: path + videoId,
token: 'wrong token',
fields: data,
statusCodeExpected: 401
statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
}
await makePutBodyRequest(options)
})
@ -534,7 +535,7 @@ describe('Test users', function () {
})
user.password = 'new password'
await userLogin(server, user, 200)
await userLogin(server, user, HttpStatusCode.OK_200)
})
it('Should be able to change the NSFW display attribute', async function () {
@ -732,7 +733,7 @@ describe('Test users', function () {
})
it('Should have removed the user token', async function () {
await getMyUserVideoQuotaUsed(server.url, accessTokenUser, 401)
await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401)
accessTokenUser = await userLogin(server, user)
})
@ -745,9 +746,9 @@ describe('Test users', function () {
password: 'password updated'
})
await getMyUserVideoQuotaUsed(server.url, accessTokenUser, 401)
await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401)
await userLogin(server, user, 400)
await userLogin(server, user, HttpStatusCode.BAD_REQUEST_400)
user.password = 'password updated'
accessTokenUser = await userLogin(server, user)
@ -766,7 +767,7 @@ describe('Test users', function () {
})
it('Should not be able to login with this user', async function () {
await userLogin(server, user, 400)
await userLogin(server, user, HttpStatusCode.BAD_REQUEST_400)
})
it('Should not have videos of this user', async function () {
@ -852,11 +853,11 @@ describe('Test users', function () {
user16AccessToken = await userLogin(server, user16)
await getMyUserInformation(server.url, user16AccessToken, 200)
await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200)
await blockUser(server.url, user16Id, server.accessToken)
await getMyUserInformation(server.url, user16AccessToken, 401)
await userLogin(server, user16, 400)
await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.UNAUTHORIZED_401)
await userLogin(server, user16, HttpStatusCode.BAD_REQUEST_400)
})
it('Should search user by banned status', async function () {
@ -884,7 +885,7 @@ describe('Test users', function () {
it('Should unblock a user', async function () {
await unblockUser(server.url, user16Id, server.accessToken)
user16AccessToken = await userLogin(server, user16)
await getMyUserInformation(server.url, user16AccessToken, 200)
await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200)
})
})