From bfbd912886eba17b4aa9a40dcef2fddc685d85bf Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 31 Jul 2019 15:57:32 +0200 Subject: Fix broken playlist api --- server/tests/api/check-params/video-playlists.ts | 34 +++++++++++++----------- server/tests/api/check-params/videos-filter.ts | 26 +++++------------- server/tests/api/check-params/videos.ts | 2 +- 3 files changed, 26 insertions(+), 36 deletions(-) (limited to 'server/tests/api/check-params') diff --git a/server/tests/api/check-params/video-playlists.ts b/server/tests/api/check-params/video-playlists.ts index 8c5e44bdd..ae5aa287f 100644 --- a/server/tests/api/check-params/video-playlists.ts +++ b/server/tests/api/check-params/video-playlists.ts @@ -37,6 +37,7 @@ describe('Test video playlists API validator', function () { let watchLaterPlaylistId: number let videoId: number let videoId2: number + let playlistElementId: number // --------------------------------------------------------------- @@ -132,18 +133,18 @@ describe('Test video playlists API validator', function () { }) describe('When listing videos of a playlist', function () { - const path = '/api/v1/video-playlists' + const path = '/api/v1/video-playlists/' it('Should fail with a bad start pagination', async function () { - await checkBadStartPagination(server.url, path, server.accessToken) + await checkBadStartPagination(server.url, path + playlistUUID + '/videos', server.accessToken) }) it('Should fail with a bad count pagination', async function () { - await checkBadCountPagination(server.url, path, server.accessToken) + await checkBadCountPagination(server.url, path + playlistUUID + '/videos', server.accessToken) }) - it('Should fail with a bad filter', async function () { - await checkBadSortPagination(server.url, path, server.accessToken) + it('Should success with the correct parameters', async function () { + await makeGetRequest({ url: server.url, path: path + playlistUUID + '/videos', statusCodeExpected: 200 }) }) }) @@ -296,7 +297,7 @@ describe('Test video playlists API validator', function () { token: server.accessToken, playlistId: playlistUUID, elementAttrs: Object.assign({ - videoId: videoId, + videoId, startTimestamp: 2, stopTimestamp: 3 }, elementAttrs) @@ -344,7 +345,8 @@ describe('Test video playlists API validator', function () { it('Succeed with the correct params', async function () { const params = getBase({}, { expectedStatus: 200 }) - await addVideoInPlaylist(params) + const res = await addVideoInPlaylist(params) + playlistElementId = res.body.videoPlaylistElement.id }) it('Should fail if the video was already added in the playlist', async function () { @@ -362,7 +364,7 @@ describe('Test video playlists API validator', function () { startTimestamp: 1, stopTimestamp: 2 }, elementAttrs), - videoId: videoId, + playlistElementId, playlistId: playlistUUID, expectedStatus: 400 }, wrapper) @@ -390,14 +392,14 @@ describe('Test video playlists API validator', function () { } }) - it('Should fail with an unknown or incorrect video id', async function () { + it('Should fail with an unknown or incorrect playlistElement id', async function () { { - const params = getBase({}, { videoId: 'toto' }) + const params = getBase({}, { playlistElementId: 'toto' }) await updateVideoPlaylistElement(params) } { - const params = getBase({}, { videoId: 42, expectedStatus: 404 }) + const params = getBase({}, { playlistElementId: 42, expectedStatus: 404 }) await updateVideoPlaylistElement(params) } }) @@ -415,7 +417,7 @@ describe('Test video playlists API validator', function () { }) it('Should fail with an unknown element', async function () { - const params = getBase({}, { videoId: videoId2, expectedStatus: 404 }) + const params = getBase({}, { playlistElementId: 888, expectedStatus: 404 }) await updateVideoPlaylistElement(params) }) @@ -587,7 +589,7 @@ describe('Test video playlists API validator', function () { return Object.assign({ url: server.url, token: server.accessToken, - videoId: videoId, + playlistElementId, playlistId: playlistUUID, expectedStatus: 400 }, wrapper) @@ -617,18 +619,18 @@ describe('Test video playlists API validator', function () { it('Should fail with an unknown or incorrect video id', async function () { { - const params = getBase({ videoId: 'toto' }) + const params = getBase({ playlistElementId: 'toto' }) await removeVideoFromPlaylist(params) } { - const params = getBase({ videoId: 42, expectedStatus: 404 }) + const params = getBase({ playlistElementId: 42, expectedStatus: 404 }) await removeVideoFromPlaylist(params) } }) it('Should fail with an unknown element', async function () { - const params = getBase({ videoId: videoId2, expectedStatus: 404 }) + const params = getBase({ playlistElementId: 888, expectedStatus: 404 }) await removeVideoFromPlaylist(params) }) diff --git a/server/tests/api/check-params/videos-filter.ts b/server/tests/api/check-params/videos-filter.ts index babef8223..5a5668665 100644 --- a/server/tests/api/check-params/videos-filter.ts +++ b/server/tests/api/check-params/videos-filter.ts @@ -15,13 +15,12 @@ import { import { UserRole } from '../../../../shared/models/users' import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model' -async function testEndpoints (server: ServerInfo, token: string, filter: string, playlistUUID: string, statusCodeExpected: number) { +async function testEndpoints (server: ServerInfo, token: string, filter: string, statusCodeExpected: number) { 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) { @@ -70,39 +69,28 @@ 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', 400) }) it('Should succeed with a good filter', async function () { - await testEndpoints(server, server.accessToken,'local', playlistUUID, 200) + await testEndpoints(server, server.accessToken,'local', 200) }) it('Should fail to list all-local with a simple user', async function () { - await testEndpoints(server, userAccessToken, 'all-local', playlistUUID, 401) + await testEndpoints(server, userAccessToken, 'all-local', 401) }) it('Should succeed to list all-local with a moderator', async function () { - await testEndpoints(server, moderatorAccessToken, 'all-local', playlistUUID, 200) + await testEndpoints(server, moderatorAccessToken, 'all-local', 200) }) it('Should succeed to list all-local with an admin', async function () { - await testEndpoints(server, server.accessToken, 'all-local', playlistUUID, 200) + await testEndpoints(server, server.accessToken, 'all-local', 200) }) // Because we cannot authenticate the user on the RSS endpoint diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts index 51e592a15..fa6d6f622 100644 --- a/server/tests/api/check-params/videos.ts +++ b/server/tests/api/check-params/videos.ts @@ -62,7 +62,7 @@ describe('Test videos API validator', function () { } }) - describe('When listing a video', function () { + describe('When listing videos', function () { it('Should fail with a bad start pagination', async function () { await checkBadStartPagination(server.url, path) }) -- cgit v1.2.3