From 9567011bf01f36c7f796ac1e0f1fb12c71635e53 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 30 Oct 2017 10:16:27 +0100 Subject: Add lazy description on server --- server/tests/api/index.ts | 1 + server/tests/api/video-description.ts | 86 +++++++++++++++++++++++++++++++++++ server/tests/utils/videos.ts | 9 ++++ 3 files changed, 96 insertions(+) create mode 100644 server/tests/api/video-description.ts (limited to 'server/tests') diff --git a/server/tests/api/index.ts b/server/tests/api/index.ts index e50e65049..2ff0ecf24 100644 --- a/server/tests/api/index.ts +++ b/server/tests/api/index.ts @@ -7,6 +7,7 @@ import './single-pod' import './video-abuse' import './video-blacklist' import './video-blacklist-management' +import './video-description' import './multiple-pods' import './services' import './request-schedulers' diff --git a/server/tests/api/video-description.ts b/server/tests/api/video-description.ts new file mode 100644 index 000000000..f04c5f1f6 --- /dev/null +++ b/server/tests/api/video-description.ts @@ -0,0 +1,86 @@ +/* tslint:disable:no-unused-expression */ + +import 'mocha' +import * as chai from 'chai' + +import { + flushAndRunMultipleServers, + flushTests, + getVideo, + getVideosList, + killallServers, + makeFriends, + ServerInfo, + setAccessTokensToServers, + uploadVideo, + wait, + getVideoDescription +} from '../utils' + +const expect = chai.expect + +describe('Test video description', function () { + let servers: ServerInfo[] = [] + let videoUUID = '' + let longDescription = 'my super description for pod 1'.repeat(50) + + before(async function () { + this.timeout(10000) + + // Run servers + servers = await flushAndRunMultipleServers(2) + + // Get the access tokens + await setAccessTokensToServers(servers) + + // Pod 1 makes friend with pod 2 + await makeFriends(servers[0].url, servers[0].accessToken) + }) + + it('Should upload video with long description', async function () { + this.timeout(15000) + + const attributes = { + description: longDescription + } + await uploadVideo(servers[0].url, servers[0].accessToken, attributes) + + await wait(11000) + + const res = await getVideosList(servers[0].url) + + videoUUID = res.body.data[0].uuid + }) + + it('Should have a truncated description on each pod', async function () { + for (const server of servers) { + const res = await getVideo(server.url, videoUUID) + const video = res.body + + // 30 characters * 6 -> 240 characters + const truncatedDescription = 'my super description for pod 1'.repeat(8) + + 'my supe...' + + expect(video.description).to.equal(truncatedDescription) + } + }) + + it('Should fetch long description on each pod', async function () { + for (const server of servers) { + const res = await getVideo(server.url, videoUUID) + const video = res.body + + const res2 = await getVideoDescription(server.url, video.descriptionPath) + expect(res2.body.description).to.equal(longDescription) + } + }) + + after(async function () { + killallServers(servers) + + // Keep the logs if the test failed + if (this['ok']) { + await flushTests() + } + }) +}) diff --git a/server/tests/utils/videos.ts b/server/tests/utils/videos.ts index 08fa48da6..2a5d00255 100644 --- a/server/tests/utils/videos.ts +++ b/server/tests/utils/videos.ts @@ -61,6 +61,14 @@ function getVideo (url: string, id: number | string) { .expect('Content-Type', /json/) } +function getVideoDescription (url: string, descriptionPath: string) { + return request(url) + .get(descriptionPath) + .set('Accept', 'application/json') + .expect(200) + .expect('Content-Type', /json/) +} + function getVideosList (url: string) { const path = '/api/v1/videos' @@ -263,6 +271,7 @@ function parseTorrentVideo (server: ServerInfo, videoUUID: string, resolution: n // --------------------------------------------------------------------------- export { + getVideoDescription, getVideoCategories, getVideoLicences, getVideoLanguages, -- cgit v1.2.3