From 213e30ef90806369529684ac9c247d73b8dc7928 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Apr 2021 10:36:13 +0200 Subject: Add banner tests --- server/tests/api/check-params/video-channels.ts | 70 ++++++++++--------- server/tests/api/videos/video-channels.ts | 86 +++++++++++++++++++----- server/tests/fixtures/banner-resized.jpg | Bin 0 -> 88780 bytes server/tests/fixtures/banner.jpg | Bin 0 -> 31648 bytes 4 files changed, 110 insertions(+), 46 deletions(-) create mode 100644 server/tests/fixtures/banner-resized.jpg create mode 100644 server/tests/fixtures/banner.jpg (limited to 'server/tests') diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts index 0dd436426..bc2e6192e 100644 --- a/server/tests/api/check-params/video-channels.ts +++ b/server/tests/api/check-params/video-channels.ts @@ -234,7 +234,8 @@ describe('Test video channels API validator', function () { }) }) - describe('When updating video channel avatar', function () { + describe('When updating video channel avatar/banner', function () { + const types = [ 'avatar', 'banner' ] let path: string before(async function () { @@ -242,48 +243,57 @@ describe('Test video channels API validator', function () { }) it('Should fail with an incorrect input file', async function () { - const fields = {} - const attaches = { - avatarfile: join(__dirname, '..', '..', 'fixtures', 'video_short.mp4') + for (const type of types) { + const fields = {} + const attaches = { + [type + 'file']: join(__dirname, '..', '..', 'fixtures', 'video_short.mp4') + } + + await makeUploadRequest({ url: server.url, path: `${path}/${type}/pick`, token: server.accessToken, fields, attaches }) } - await makeUploadRequest({ url: server.url, path: path + '/avatar/pick', token: server.accessToken, fields, attaches }) }) it('Should fail with a big file', async function () { - const fields = {} - const attaches = { - avatarfile: join(__dirname, '..', '..', 'fixtures', 'avatar-big.png') + for (const type of types) { + const fields = {} + const attaches = { + [type + 'file']: join(__dirname, '..', '..', 'fixtures', 'avatar-big.png') + } + await makeUploadRequest({ url: server.url, path: `${path}/${type}/pick`, token: server.accessToken, fields, attaches }) } - await makeUploadRequest({ url: server.url, path: path + '/avatar/pick', token: server.accessToken, fields, attaches }) }) it('Should fail with an unauthenticated user', async function () { - const fields = {} - const attaches = { - avatarfile: join(__dirname, '..', '..', 'fixtures', 'avatar.png') + for (const type of types) { + const fields = {} + const attaches = { + [type + 'file']: join(__dirname, '..', '..', 'fixtures', 'avatar.png') + } + await makeUploadRequest({ + url: server.url, + path: `${path}/${type}/pick`, + fields, + attaches, + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + }) } - await makeUploadRequest({ - url: server.url, - path: path + '/avatar/pick', - fields, - attaches, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 - }) }) it('Should succeed with the correct params', async function () { - const fields = {} - const attaches = { - avatarfile: join(__dirname, '..', '..', 'fixtures', 'avatar.png') + for (const type of types) { + const fields = {} + const attaches = { + [type + 'file']: join(__dirname, '..', '..', 'fixtures', 'avatar.png') + } + await makeUploadRequest({ + url: server.url, + path: `${path}/${type}/pick`, + token: server.accessToken, + fields, + attaches, + statusCodeExpected: HttpStatusCode.OK_200 + }) } - await makeUploadRequest({ - url: server.url, - path: path + '/avatar/pick', - token: server.accessToken, - fields, - attaches, - statusCodeExpected: HttpStatusCode.OK_200 - }) }) }) diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts index 367f99fdd..8033b9ba5 100644 --- a/server/tests/api/videos/video-channels.ts +++ b/server/tests/api/videos/video-channels.ts @@ -5,13 +5,14 @@ import * as chai from 'chai' import { cleanupTests, createUser, + deleteVideoChannelImage, doubleFollow, flushAndRunMultipleServers, getVideo, getVideoChannelVideos, testImage, updateVideo, - updateVideoChannelAvatar, + updateVideoChannelImage, uploadVideo, userLogin, wait @@ -21,7 +22,6 @@ import { deleteVideoChannel, getAccountVideoChannelsList, getMyUserInformation, - getVideoChannel, getVideoChannelsList, ServerInfo, setAccessTokensToServers, @@ -33,6 +33,13 @@ import { User, Video, VideoChannel, VideoDetails } from '../../../../shared/inde const expect = chai.expect +async function findChannel (server: ServerInfo, channelId: number) { + const res = await getVideoChannelsList(server.url, 0, 5, '-name') + const videoChannel = res.body.data.find(c => c.id === channelId) + + return videoChannel as VideoChannel +} + describe('Test video channels', function () { let servers: ServerInfo[] let userInfo: User @@ -262,38 +269,85 @@ describe('Test video channels', function () { }) it('Should update video channel avatar', async function () { - this.timeout(5000) + this.timeout(15000) const fixture = 'avatar.png' - await updateVideoChannelAvatar({ + await updateVideoChannelImage({ url: servers[0].url, accessToken: servers[0].accessToken, videoChannelName: 'second_video_channel', - fixture + fixture, + type: 'avatar' }) await waitJobs(servers) + + for (const server of servers) { + const videoChannel = await findChannel(server, secondVideoChannelId) + + await testImage(server.url, 'avatar-resized', videoChannel.avatar.path, '.png') + } }) - it('Should have video channel avatar updated', async function () { + it('Should update video channel banner', async function () { + this.timeout(15000) + + const fixture = 'banner.jpg' + + await updateVideoChannelImage({ + url: servers[0].url, + accessToken: servers[0].accessToken, + videoChannelName: 'second_video_channel', + fixture, + type: 'banner' + }) + + await waitJobs(servers) + for (const server of servers) { - const res = await getVideoChannelsList(server.url, 0, 1, '-name') + const videoChannel = await findChannel(server, secondVideoChannelId) - const videoChannel = res.body.data.find(c => c.id === secondVideoChannelId) + await testImage(server.url, 'banner-resized', videoChannel.banner.path) + } + }) - await testImage(server.url, 'avatar-resized', videoChannel.avatar.path, '.png') + it('Should delete the video channel avatar', async function () { + this.timeout(15000) + + await deleteVideoChannelImage({ + url: servers[0].url, + accessToken: servers[0].accessToken, + videoChannelName: 'second_video_channel', + type: 'avatar' + }) + + await waitJobs(servers) + + for (const server of servers) { + const videoChannel = await findChannel(server, secondVideoChannelId) + + expect(videoChannel.avatar).to.be.null } }) - it('Should get video channel', async function () { - const res = await getVideoChannel(servers[0].url, 'second_video_channel') + it('Should delete the video channel banner', async function () { + this.timeout(15000) + + await deleteVideoChannelImage({ + url: servers[0].url, + accessToken: servers[0].accessToken, + videoChannelName: 'second_video_channel', + type: 'banner' + }) - const videoChannel = res.body - expect(videoChannel.name).to.equal('second_video_channel') - expect(videoChannel.displayName).to.equal('video channel updated') - expect(videoChannel.description).to.equal('video channel description updated') - expect(videoChannel.support).to.equal('video channel support text updated') + await waitJobs(servers) + + for (const server of servers) { + const videoChannel = await findChannel(server, secondVideoChannelId) + + expect(videoChannel.banner).to.be.null + } }) it('Should list the second video channel videos', async function () { diff --git a/server/tests/fixtures/banner-resized.jpg b/server/tests/fixtures/banner-resized.jpg new file mode 100644 index 000000000..13ea422cb Binary files /dev/null and b/server/tests/fixtures/banner-resized.jpg differ diff --git a/server/tests/fixtures/banner.jpg b/server/tests/fixtures/banner.jpg new file mode 100644 index 000000000..e5f284f59 Binary files /dev/null and b/server/tests/fixtures/banner.jpg differ -- cgit v1.2.3