X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fcheck-params%2Fvideos-filter.ts;h=2391584a7ba78bf81509cfe1344f1ac163a23dfd;hb=f2eb23cd87cf32b8fe545178143b5f49e06a58da;hp=971867b27d30a58d104560dfcb873b31cca7e4d0;hpb=94565d52bb2883e09f16d1363170ac9c0dccb7a1;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 971867b27..2391584a7 100644 --- a/server/tests/api/check-params/videos-filter.ts +++ b/server/tests/api/check-params/videos-filter.ts @@ -1,27 +1,25 @@ -/* tslint:disable:no-unused-expression */ +/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' import { + cleanupTests, createUser, - createVideoPlaylist, - flushTests, - killallServers, + flushAndRunServer, makeGetRequest, - runServer, ServerInfo, - setAccessTokensToServers, setDefaultVideoChannel, + setAccessTokensToServers, + setDefaultVideoChannel, userLogin } from '../../../../shared/extra-utils' import { UserRole } from '../../../../shared/models/users' -import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' -async function testEndpoints (server: ServerInfo, token: string, filter: string, playlistUUID: 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', '/api/v1/videos', - '/api/v1/search/videos', - '/api/v1/video-playlists/' + playlistUUID + '/videos' + '/api/v1/search/videos' ] for (const path of paths) { @@ -41,16 +39,13 @@ describe('Test videos filters', function () { let server: ServerInfo let userAccessToken: string let moderatorAccessToken: string - let playlistUUID: string // --------------------------------------------------------------- before(async function () { this.timeout(30000) - await flushTests() - - server = await runServer(1) + server = await flushAndRunServer(1) await setAccessTokensToServers([ server ]) await setDefaultVideoChannel([ server ]) @@ -72,58 +67,52 @@ describe('Test videos filters', function () { } ) moderatorAccessToken = await userLogin(server, moderator) - - const res = await createVideoPlaylist({ - url: server.url, - token: server.accessToken, - playlistAttrs: { - displayName: 'super playlist', - privacy: VideoPlaylistPrivacy.PUBLIC, - videoChannelId: server.videoChannel.id - } - }) - playlistUUID = res.body.videoPlaylist.uuid }) describe('When setting a video filter', function () { it('Should fail with a bad filter', async function () { - await testEndpoints(server, server.accessToken, 'bad-filter', playlistUUID, 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', playlistUUID, 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', playlistUUID, 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', playlistUUID, 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', playlistUUID, 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' } @@ -132,11 +121,6 @@ describe('Test videos filters', function () { }) after(async function () { - killallServers([ server ]) - - // Keep the logs if the test failed - if (this['ok']) { - await flushTests() - } + await cleanupTests([ server ]) }) })