X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fcheck-params%2Fvideos.ts;h=16ef1c50521761dc71fca2d86a4c73dc087201a1;hb=a22046d166805222ca76060e471b6cb3d419a32d;hp=abbea6ba34b5a49bbb4c6a76e96a1664040efc3f;hpb=bbe0f0645ca958d33a3f409b15166609733b663f;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts index abbea6ba3..16ef1c505 100644 --- a/server/tests/api/check-params/videos.ts +++ b/server/tests/api/check-params/videos.ts @@ -6,11 +6,28 @@ import 'mocha' import { join } from 'path' import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' import { - createUser, flushTests, getMyUserInformation, getVideo, getVideosList, immutableAssign, killallServers, makeDeleteRequest, - makeGetRequest, makeUploadRequest, makePutBodyRequest, removeVideo, runServer, ServerInfo, setAccessTokensToServers, userLogin -} from '../../utils' -import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' -import { getAccountsList } from '../../utils/users/accounts' + cleanupTests, + createUser, + flushAndRunServer, + getMyUserInformation, + getVideo, + getVideosList, + immutableAssign, + makeDeleteRequest, + makeGetRequest, + makePutBodyRequest, + makeUploadRequest, + removeVideo, + ServerInfo, + setAccessTokensToServers, + userLogin, + root +} from '../../../../shared/extra-utils' +import { + checkBadCountPagination, + checkBadSortPagination, + checkBadStartPagination +} from '../../../../shared/extra-utils/requests/check-api-params' const expect = chai.expect @@ -20,7 +37,7 @@ describe('Test videos API validator', function () { let userAccessToken = '' let accountName: string let channelId: number - let channelUUID: string + let channelName: string let videoId // --------------------------------------------------------------- @@ -28,26 +45,24 @@ describe('Test videos API validator', function () { before(async function () { this.timeout(30000) - await flushTests() - - server = await runServer(1) + server = await flushAndRunServer(1) await setAccessTokensToServers([ server ]) const username = 'user1' const password = 'my super password' - await createUser(server.url, server.accessToken, username, password) + await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) userAccessToken = await userLogin(server, { username, password }) { const res = await getMyUserInformation(server.url, server.accessToken) channelId = res.body.videoChannels[ 0 ].id - channelUUID = res.body.videoChannels[ 0 ].uuid + channelName = res.body.videoChannels[ 0 ].name accountName = res.body.account.name + '@' + res.body.account.host } }) - 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) }) @@ -60,8 +75,12 @@ describe('Test videos API validator', function () { await checkBadSortPagination(server.url, path) }) + it('Should fail with a bad skipVideos query', async function () { + await makeGetRequest({ url: server.url, path, statusCodeExpected: 200, query: { skipCount: 'toto' } }) + }) + it('Should success with the correct parameters', async function () { - await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 }) + await makeGetRequest({ url: server.url, path, statusCodeExpected: 200, query: { skipCount: false } }) }) }) @@ -140,7 +159,7 @@ describe('Test videos API validator', function () { let path: string before(async function () { - path = '/api/v1/video-channels/' + channelUUID + '/videos' + path = '/api/v1/video-channels/' + channelName + '/videos' }) it('Should fail with a bad start pagination', async function () { @@ -163,7 +182,7 @@ describe('Test videos API validator', function () { describe('When adding a video', function () { let baseCorrectParams const baseCorrectAttaches = { - 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.webm') + 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.webm') } before(function () { @@ -175,12 +194,14 @@ describe('Test videos API validator', function () { language: 'pt', nsfw: false, commentsEnabled: true, + downloadEnabled: true, waitTranscoding: true, description: 'my super description', support: 'my super support text', tags: [ 'tag1', 'tag2' ], privacy: VideoPrivacy.PUBLIC, - channelId: channelId + channelId: channelId, + originallyPublishedAt: new Date().toISOString() } }) @@ -233,7 +254,7 @@ describe('Test videos API validator', function () { }) it('Should fail with a long support text', async function () { - const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(150) }) + const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) }) const attaches = baseCorrectAttaches await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) @@ -258,7 +279,7 @@ describe('Test videos API validator', function () { username: 'fake', password: 'fake_password' } - await createUser(server.url, server.accessToken, user.username, user.password) + await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) const accessTokenUser = await userLogin(server, user) const res = await getMyUserInformation(server.url, accessTokenUser) @@ -308,16 +329,28 @@ describe('Test videos API validator', function () { await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) + it('Should fail with a bad originally published at attribute', async function () { + const fields = immutableAssign(baseCorrectParams, { 'originallyPublishedAt': 'toto' }) + const attaches = baseCorrectAttaches + + await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) + }) + it('Should fail without an input file', async function () { const fields = baseCorrectParams const attaches = {} await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) - it('Should fail without an incorrect input file', async function () { + it('Should fail with an incorrect input file', async function () { const fields = baseCorrectParams - const attaches = { - 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short_fake.webm') + let attaches = { + 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short_fake.webm') + } + await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) + + attaches = { + 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.mkv') } await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) @@ -325,8 +358,8 @@ describe('Test videos API validator', function () { it('Should fail with an incorrect thumbnail file', async function () { const fields = baseCorrectParams const attaches = { - 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png'), - 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short_fake.webm') + 'thumbnailfile': join(root(), 'server', 'tests', 'fixtures', 'avatar.png'), + 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') } await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) @@ -335,8 +368,8 @@ describe('Test videos API validator', function () { it('Should fail with a big thumbnail file', async function () { const fields = baseCorrectParams const attaches = { - 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png'), - 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short_fake.webm') + 'thumbnailfile': join(root(), 'server', 'tests', 'fixtures', 'avatar-big.png'), + 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') } await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) @@ -345,8 +378,8 @@ describe('Test videos API validator', function () { it('Should fail with an incorrect preview file', async function () { const fields = baseCorrectParams const attaches = { - 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png'), - 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short_fake.webm') + 'previewfile': join(root(), 'server', 'tests', 'fixtures', 'avatar.png'), + 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') } await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) @@ -355,8 +388,8 @@ describe('Test videos API validator', function () { it('Should fail with a big preview file', async function () { const fields = baseCorrectParams const attaches = { - 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png'), - 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short_fake.webm') + 'previewfile': join(root(), 'server', 'tests', 'fixtures', 'avatar-big.png'), + 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') } await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) @@ -381,7 +414,7 @@ describe('Test videos API validator', function () { { const attaches = immutableAssign(baseCorrectAttaches, { - videofile: join(__dirname, '..', '..', 'fixtures', 'video_short.mp4') + videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') }) await makeUploadRequest({ @@ -396,7 +429,7 @@ describe('Test videos API validator', function () { { const attaches = immutableAssign(baseCorrectAttaches, { - videofile: join(__dirname, '..', '..', 'fixtures', 'video_short.ogv') + videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.ogv') }) await makeUploadRequest({ @@ -419,6 +452,7 @@ describe('Test videos API validator', function () { language: 'pt', nsfw: false, commentsEnabled: false, + downloadEnabled: false, description: 'my super description', privacy: VideoPrivacy.PUBLIC, tags: [ 'tag1', 'tag2' ] @@ -482,7 +516,7 @@ describe('Test videos API validator', function () { }) it('Should fail with a long support text', async function () { - const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(150) }) + const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) }) await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) }) @@ -523,10 +557,16 @@ describe('Test videos API validator', function () { await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) }) + it('Should fail with a bad originally published at param', async function () { + const fields = immutableAssign(baseCorrectParams, { originallyPublishedAt: 'toto' }) + + await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) + }) + it('Should fail with an incorrect thumbnail file', async function () { const fields = baseCorrectParams const attaches = { - 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png') + 'thumbnailfile': join(root(), 'server', 'tests', 'fixtures', 'avatar.png') } await makeUploadRequest({ @@ -542,7 +582,7 @@ describe('Test videos API validator', function () { it('Should fail with a big thumbnail file', async function () { const fields = baseCorrectParams const attaches = { - 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png') + 'thumbnailfile': join(root(), 'server', 'tests', 'fixtures', 'avatar-big.png') } await makeUploadRequest({ @@ -558,7 +598,7 @@ describe('Test videos API validator', function () { it('Should fail with an incorrect preview file', async function () { const fields = baseCorrectParams const attaches = { - 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png') + 'previewfile': join(root(), 'server', 'tests', 'fixtures', 'avatar.png') } await makeUploadRequest({ @@ -574,7 +614,7 @@ describe('Test videos API validator', function () { it('Should fail with a big preview file', async function () { const fields = baseCorrectParams const attaches = { - 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png') + 'previewfile': join(root(), 'server', 'tests', 'fixtures', 'avatar-big.png') } await makeUploadRequest({ @@ -705,11 +745,6 @@ describe('Test videos API validator', function () { }) after(async function () { - killallServers([ server ]) - - // Keep the logs if the test failed - if (this['ok']) { - await flushTests() - } + await cleanupTests([ server ]) }) })