From 5f04dd2f743961e0a06c29531cc3ccc9e4928d56 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 24 Oct 2017 19:41:30 +0200 Subject: Add video channel tests --- server/tests/api/check-params/remotes.ts | 2 + server/tests/api/check-params/video-channels.ts | 310 ++++++++++++++++++++++++ server/tests/api/check-params/videos.ts | 123 ++++++++-- 3 files changed, 416 insertions(+), 19 deletions(-) create mode 100644 server/tests/api/check-params/video-channels.ts (limited to 'server/tests/api/check-params') diff --git a/server/tests/api/check-params/remotes.ts b/server/tests/api/check-params/remotes.ts index 9456ae665..6d1747442 100644 --- a/server/tests/api/check-params/remotes.ts +++ b/server/tests/api/check-params/remotes.ts @@ -1,5 +1,7 @@ /* tslint:disable:no-unused-expression */ +import 'mocha' + import { ServerInfo, flushTests, diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts new file mode 100644 index 000000000..b99b5eda8 --- /dev/null +++ b/server/tests/api/check-params/video-channels.ts @@ -0,0 +1,310 @@ +/* tslint:disable:no-unused-expression */ + +import * as request from 'supertest' +import { join } from 'path' +import 'mocha' +import * as chai from 'chai' +const expect = chai.expect + +import { + ServerInfo, + flushTests, + runServer, + makePutBodyRequest, + setAccessTokensToServers, + killallServers, + getMyUserInformation, + makePostBodyRequest, + getVideoChannelsList, + createUser, + getUserAccessToken +} from '../../utils' + +describe('Test videos API validator', function () { + const path = '/api/v1/videos/channels' + let server: ServerInfo + let channelId: number + let accessTokenUser: string + + // --------------------------------------------------------------- + + before(async function () { + this.timeout(20000) + + await flushTests() + + server = await runServer(1) + + await setAccessTokensToServers([ server ]) + + const res = await getMyUserInformation(server.url, server.accessToken) + channelId = res.body.videoChannels[0].id + + const user = { + username: 'fake', + password: 'fake_password' + } + await createUser(server.url, server.accessToken, user.username, user.password) + + accessTokenUser = await getUserAccessToken(server, user) + }) + + describe('When listing a video channels', function () { + it('Should fail with a bad start pagination', async function () { + await request(server.url) + .get(path) + .query({ start: 'hello' }) + .set('Accept', 'application/json') + .expect(400) + }) + + it('Should fail with a bad count pagination', async function () { + await request(server.url) + .get(path) + .query({ count: 'hello' }) + .set('Accept', 'application/json') + .expect(400) + }) + + it('Should fail with an incorrect sort', async function () { + await request(server.url) + .get(path) + .query({ sort: 'hello' }) + .set('Accept', 'application/json') + .expect(400) + }) + }) + + describe('When listing author video channels', function () { + it('Should fail with bad author', async function () { + const path = '/api/v1/videos/authors/hello/channels' + + await request(server.url) + .get(path) + .set('Accept', 'application/json') + .expect(400) + }) + + it('Should fail with a unknown author', async function () { + const path = '/api/v1/videos/authors/156/channels' + + await request(server.url) + .get(path) + .set('Accept', 'application/json') + .expect(404) + }) + }) + + describe('When adding a video channel', function () { + + it('Should fail with a non authenticated user', async function () { + const fields = { + name: 'hello', + description: 'super description' + } + await makePostBodyRequest({ url: server.url, path, token: 'none', fields, statusCodeExpected: 401 }) + }) + + it('Should fail with nothing', async function () { + const fields = {} + await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) + }) + + it('Should fail without name', async function () { + const fields = { + description: 'super description' + } + await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) + }) + + it('Should fail with a long name', async function () { + const fields = { + name: 'hello tooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' + + 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long', + description: 'super description' + } + await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) + }) + + it('Should fail with a long description', async function () { + const fields = { + name: 'hello', + description: 'super toooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' + + 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo0' + + 'ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' + + 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long description' + } + await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) + }) + + it('Should succeed with the correct parameters', async function () { + const fields = { + name: 'hello', + description: 'super description' + } + await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 }) + }) + }) + + describe('When updating a video channel', function () { + let videoChannelId + + before(async function () { + const res = await getVideoChannelsList(server.url, 0, 1) + videoChannelId = res.body.data[0].id + }) + + it('Should fail with a non authenticated user', async function () { + const fields = { + name: 'hello', + description: 'super description' + } + await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: 'hi', fields, statusCodeExpected: 401 }) + }) + + it('Should fail with another authenticated user', async function () { + const fields = { + name: 'hello', + description: 'super description' + } + await makePutBodyRequest({ + url: server.url, + path: path + '/' + videoChannelId, + token: accessTokenUser, + fields, + statusCodeExpected: 403 + }) + }) + + it('Should fail with a long name', async function () { + const fields = { + name: 'hello tooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' + + 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long', + description: 'super description' + } + await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: server.accessToken, fields }) + }) + + it('Should fail with a long description', async function () { + const fields = { + name: 'hello', + description: 'super toooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' + + 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo0' + + 'ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' + + 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long description' + } + await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: server.accessToken, fields }) + }) + + it('Should succeed with the correct parameters', async function () { + const fields = { + name: 'hello 2', + description: 'super description 2' + } + await makePutBodyRequest({ + url: server.url, + path: path + '/' + videoChannelId, + token: server.accessToken, + fields, + statusCodeExpected: 204 + }) + }) + }) + + describe('When getting a video channel', function () { + let videoChannelId: number + + before(async function () { + const res = await getVideoChannelsList(server.url, 0, 1) + videoChannelId = res.body.data[0].id + }) + + it('Should return the list of the video channels with nothing', async function () { + const res = await request(server.url) + .get(path) + .set('Accept', 'application/json') + .expect(200) + .expect('Content-Type', /json/) + + expect(res.body.data).to.be.an('array') + }) + + it('Should fail without a correct uuid', async function () { + await request(server.url) + .get(path + '/coucou') + .set('Accept', 'application/json') + .expect(400) + }) + + it('Should return 404 with an incorrect video channel', async function () { + await request(server.url) + .get(path + '/4da6fde3-88f7-4d16-b119-108df5630b06') + .set('Accept', 'application/json') + .expect(404) + }) + + it('Should succeed with the correct parameters', async function () { + await request(server.url) + .get(path + '/' + videoChannelId) + .set('Accept', 'application/json') + .expect(200) + }) + }) + + describe('When deleting a video channel', function () { + let videoChannelId: number + + before(async function () { + const res = await getVideoChannelsList(server.url, 0, 1) + videoChannelId = res.body.data[0].id + }) + + it('Should fail with a non authenticated user', async function () { + await request(server.url) + .delete(path + '/' + videoChannelId) + .set('Authorization', 'Bearer coucou') + .expect(401) + }) + + it('Should fail with another authenticated user', async function () { + await request(server.url) + .delete(path + '/' + videoChannelId) + .set('Authorization', 'Bearer ' + accessTokenUser) + .expect(403) + }) + + it('Should fail with an unknown id', async function () { + await request(server.url) + .delete(path + '/454554') + .set('Authorization', 'Bearer ' + server.accessToken) + .expect(404) + }) + + it('Should succeed with the correct parameters', async function () { + await request(server.url) + .delete(path + '/' + videoChannelId) + .set('Authorization', 'Bearer ' + server.accessToken) + .expect(204) + }) + + it('Should fail to delete the last user video channel', async function () { + const res = await getVideoChannelsList(server.url, 0, 1) + videoChannelId = res.body.data[0].id + + await request(server.url) + .delete(path + '/' + videoChannelId) + .set('Authorization', 'Bearer ' + server.accessToken) + .expect(409 + ) + }) + }) + + after(async function () { + killallServers([ server ]) + + // Keep the logs if the test failed + if (this['ok']) { + await flushTests() + } + }) +}) diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts index af75d33c1..167b45b61 100644 --- a/server/tests/api/check-params/videos.ts +++ b/server/tests/api/check-params/videos.ts @@ -14,12 +14,16 @@ import { makePutBodyRequest, setAccessTokensToServers, killallServers, - makePostUploadRequest + makePostUploadRequest, + getMyUserInformation, + createUser, + getUserAccessToken } from '../../utils' describe('Test videos API validator', function () { const path = '/api/v1/videos/' let server: ServerInfo + let channelId: number // --------------------------------------------------------------- @@ -31,6 +35,9 @@ describe('Test videos API validator', function () { server = await runServer(1) await setAccessTokensToServers([ server ]) + + const res = await getMyUserInformation(server.url, server.accessToken) + channelId = res.body.videoChannels[0].id }) describe('When listing a video', function () { @@ -106,7 +113,8 @@ describe('Test videos API validator', function () { language: 6, nsfw: false, description: 'my super description', - tags: [ 'tag1', 'tag2' ] + tags: [ 'tag1', 'tag2' ], + channelId } const attaches = { 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') @@ -122,7 +130,8 @@ describe('Test videos API validator', function () { language: 6, nsfw: false, description: 'my super description', - tags: [ 'tag1', 'tag2' ] + tags: [ 'tag1', 'tag2' ], + channelId } const attaches = { 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') @@ -137,7 +146,8 @@ describe('Test videos API validator', function () { language: 6, nsfw: false, description: 'my super description', - tags: [ 'tag1', 'tag2' ] + tags: [ 'tag1', 'tag2' ], + channelId } const attaches = { 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') @@ -153,7 +163,8 @@ describe('Test videos API validator', function () { language: 6, nsfw: false, description: 'my super description', - tags: [ 'tag1', 'tag2' ] + tags: [ 'tag1', 'tag2' ], + channelId } const attaches = { 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') @@ -168,7 +179,8 @@ describe('Test videos API validator', function () { language: 6, nsfw: false, description: 'my super description', - tags: [ 'tag1', 'tag2' ] + tags: [ 'tag1', 'tag2' ], + channelId } const attaches = { 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') @@ -184,7 +196,8 @@ describe('Test videos API validator', function () { language: 6, nsfw: false, description: 'my super description', - tags: [ 'tag1', 'tag2' ] + tags: [ 'tag1', 'tag2' ], + channelId } const attaches = { 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') @@ -200,7 +213,8 @@ describe('Test videos API validator', function () { language: 563, nsfw: false, description: 'my super description', - tags: [ 'tag1', 'tag2' ] + tags: [ 'tag1', 'tag2' ], + channelId } const attaches = { 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') @@ -215,7 +229,8 @@ describe('Test videos API validator', function () { licence: 4, language: 6, description: 'my super description', - tags: [ 'tag1', 'tag2' ] + tags: [ 'tag1', 'tag2' ], + channelId } const attaches = { 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') @@ -223,7 +238,7 @@ describe('Test videos API validator', function () { await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) - it('Should fail with a bad nsfw attribue', async function () { + it('Should fail with a bad nsfw attribute', async function () { const fields = { name: 'my super name', category: 5, @@ -231,7 +246,8 @@ describe('Test videos API validator', function () { language: 6, nsfw: 2, description: 'my super description', - tags: [ 'tag1', 'tag2' ] + tags: [ 'tag1', 'tag2' ], + channelId } const attaches = { 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') @@ -246,7 +262,8 @@ describe('Test videos API validator', function () { licence: 1, language: 6, nsfw: false, - tags: [ 'tag1', 'tag2' ] + tags: [ 'tag1', 'tag2' ], + channelId } const attaches = { 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') @@ -264,6 +281,23 @@ describe('Test videos API validator', function () { description: 'my super description which is very very very very very very very very very very very very very very' + 'very very very very very very very very very very very very very very very very very very very very very' + 'very very very very very very very very very very very very very very very long', + tags: [ 'tag1', 'tag2' ], + channelId + } + const attaches = { + 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') + } + await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) + }) + + it('Should fail without a channel', async function () { + const fields = { + name: 'my super name', + category: 5, + licence: 1, + language: 6, + nsfw: false, + description: 'my super description', tags: [ 'tag1', 'tag2' ] } const attaches = { @@ -272,6 +306,50 @@ describe('Test videos API validator', function () { await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) + it('Should fail with a bad channel', async function () { + const fields = { + name: 'my super name', + category: 5, + licence: 1, + language: 6, + nsfw: false, + description: 'my super description', + tags: [ 'tag1', 'tag2' ], + channelId: 545454 + } + const attaches = { + 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') + } + await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) + }) + + it('Should fail with another user channel', async function () { + const user = { + username: 'fake', + password: 'fake_password' + } + await createUser(server.url, server.accessToken, user.username, user.password) + + const accessTokenUser = await getUserAccessToken(server, user) + const res = await getMyUserInformation(server.url, accessTokenUser) + const channelId = res.body.videoChannels[0].id + + const fields = { + name: 'my super name', + category: 5, + licence: 1, + language: 6, + nsfw: false, + description: 'my super description', + tags: [ 'tag1', 'tag2' ], + channelId + } + const attaches = { + 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') + } + await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) + }) + it('Should fail with too many tags', async function () { const fields = { name: 'my super name', @@ -280,7 +358,8 @@ describe('Test videos API validator', function () { language: 6, nsfw: false, description: 'my super description', - tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ] + tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ], + channelId } const attaches = { 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') @@ -296,7 +375,8 @@ describe('Test videos API validator', function () { language: 6, nsfw: false, description: 'my super description', - tags: [ 'tag1', 't' ] + tags: [ 'tag1', 't' ], + channelId } const attaches = { 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') @@ -312,7 +392,8 @@ describe('Test videos API validator', function () { language: 6, nsfw: false, description: 'my super description', - tags: [ 'my_super_tag_too_long', 'tag1' ] + tags: [ 'my_super_tag_too_long', 'tag1' ], + channelId } const attaches = { 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') @@ -328,7 +409,8 @@ describe('Test videos API validator', function () { language: 6, nsfw: false, description: 'my super description', - tags: [ 'tag1', 'tag2' ] + tags: [ 'tag1', 'tag2' ], + channelId } const attaches = {} await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) @@ -342,7 +424,8 @@ describe('Test videos API validator', function () { language: 6, nsfw: false, description: 'my super description', - tags: [ 'tag1', 'tag2' ] + tags: [ 'tag1', 'tag2' ], + channelId } const attaches = { 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm') @@ -358,7 +441,8 @@ describe('Test videos API validator', function () { language: 6, nsfw: false, description: 'my super description', - tags: [ 'tag1', 'tag2' ] + tags: [ 'tag1', 'tag2' ], + channelId } const attaches = { 'videofile': join(__dirname, '..', 'fixtures', 'video_too_long.webm') @@ -376,7 +460,8 @@ describe('Test videos API validator', function () { language: 6, nsfw: false, description: 'my super description', - tags: [ 'tag1', 'tag2' ] + tags: [ 'tag1', 'tag2' ], + channelId } const attaches = { 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') -- cgit v1.2.3