X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fcheck-params%2Fvideos-filter.ts;h=4d54a4fd04e757a6355cff7b20fb04f52b0f97d3;hb=e3d15a6a9aed97a004d9dac1b7a6499d794e080a;hp=ec8654db27878f37d6b0198168c8b335638d9b0d;hpb=7024e9120b381b5b3201212f5a18f5cdc14e15ff;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/check-params/videos-filter.ts b/server/tests/api/check-params/videos-filter.ts index ec8654db2..4d54a4fd0 100644 --- a/server/tests/api/check-params/videos-filter.ts +++ b/server/tests/api/check-params/videos-filter.ts @@ -12,8 +12,9 @@ import { userLogin } from '../../../../shared/extra-utils' import { UserRole } from '../../../../shared/models/users' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' -async function testEndpoints (server: ServerInfo, token: string, filter: string, statusCodeExpected: number) { +async function testEndpoints (server: ServerInfo, token: string, filter: string, statusCodeExpected: HttpStatusCode) { const paths = [ '/api/v1/video-channels/root_channel/videos', '/api/v1/accounts/root/videos', @@ -34,7 +35,7 @@ async function testEndpoints (server: ServerInfo, token: string, filter: string, } } -describe('Test videos filters', function () { +describe('Test video filters validators', function () { let server: ServerInfo let userAccessToken: string let moderatorAccessToken: string @@ -71,42 +72,47 @@ describe('Test videos filters', function () { describe('When setting a video filter', function () { it('Should fail with a bad filter', async function () { - await testEndpoints(server, server.accessToken, 'bad-filter', 400) + await testEndpoints(server, server.accessToken, 'bad-filter', HttpStatusCode.BAD_REQUEST_400) }) it('Should succeed with a good filter', async function () { - await testEndpoints(server, server.accessToken, 'local', 200) + await testEndpoints(server, server.accessToken, 'local', HttpStatusCode.OK_200) }) - it('Should fail to list all-local with a simple user', async function () { - await testEndpoints(server, userAccessToken, 'all-local', 401) + it('Should fail to list all-local/all with a simple user', async function () { + await testEndpoints(server, userAccessToken, 'all-local', HttpStatusCode.UNAUTHORIZED_401) + await testEndpoints(server, userAccessToken, 'all', HttpStatusCode.UNAUTHORIZED_401) }) - it('Should succeed to list all-local with a moderator', async function () { - await testEndpoints(server, moderatorAccessToken, 'all-local', 200) + it('Should succeed to list all-local/all with a moderator', async function () { + await testEndpoints(server, moderatorAccessToken, 'all-local', HttpStatusCode.OK_200) + await testEndpoints(server, moderatorAccessToken, 'all', HttpStatusCode.OK_200) }) - it('Should succeed to list all-local with an admin', async function () { - await testEndpoints(server, server.accessToken, 'all-local', 200) + it('Should succeed to list all-local/all with an admin', async function () { + await testEndpoints(server, server.accessToken, 'all-local', HttpStatusCode.OK_200) + await testEndpoints(server, server.accessToken, 'all', HttpStatusCode.OK_200) }) // Because we cannot authenticate the user on the RSS endpoint - it('Should fail on the feeds endpoint with the all-local filter', async function () { - await makeGetRequest({ - url: server.url, - path: '/feeds/videos.json', - statusCodeExpected: 401, - query: { - filter: 'all-local' - } - }) + it('Should fail on the feeds endpoint with the all-local/all filter', async function () { + for (const filter of [ 'all', 'all-local' ]) { + await makeGetRequest({ + url: server.url, + path: '/feeds/videos.json', + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401, + query: { + filter + } + }) + } }) it('Should succeed on the feeds endpoint with the local filter', async function () { await makeGetRequest({ url: server.url, path: '/feeds/videos.json', - statusCodeExpected: 200, + statusCodeExpected: HttpStatusCode.OK_200, query: { filter: 'local' }