diff options
Diffstat (limited to 'server/tests/cli/regenerate-thumbnails.ts')
-rw-r--r-- | server/tests/cli/regenerate-thumbnails.ts | 52 |
1 files changed, 24 insertions, 28 deletions
diff --git a/server/tests/cli/regenerate-thumbnails.ts b/server/tests/cli/regenerate-thumbnails.ts index 8acb9f263..780c9b4bd 100644 --- a/server/tests/cli/regenerate-thumbnails.ts +++ b/server/tests/cli/regenerate-thumbnails.ts | |||
@@ -2,36 +2,33 @@ import 'mocha' | |||
2 | import { expect } from 'chai' | 2 | import { expect } from 'chai' |
3 | import { writeFile } from 'fs-extra' | 3 | import { writeFile } from 'fs-extra' |
4 | import { basename, join } from 'path' | 4 | import { basename, join } from 'path' |
5 | import { Video, VideoDetails } from '@shared/models' | 5 | import { HttpStatusCode, Video } from '@shared/models' |
6 | import { | 6 | import { |
7 | buildServerDirectory, | ||
8 | cleanupTests, | 7 | cleanupTests, |
8 | createMultipleServers, | ||
9 | doubleFollow, | 9 | doubleFollow, |
10 | execCLI, | ||
11 | flushAndRunMultipleServers, | ||
12 | getEnvCli, | ||
13 | getVideo, | ||
14 | makeRawRequest, | 10 | makeRawRequest, |
15 | ServerInfo, | 11 | PeerTubeServer, |
16 | setAccessTokensToServers, | 12 | setAccessTokensToServers, |
17 | uploadVideoAndGetId, | ||
18 | waitJobs | 13 | waitJobs |
19 | } from '../../../shared/extra-utils' | 14 | } from '../../../shared/extra-utils' |
20 | import { HttpStatusCode } from '@shared/core-utils' | ||
21 | 15 | ||
22 | async function testThumbnail (server: ServerInfo, videoId: number | string) { | 16 | async function testThumbnail (server: PeerTubeServer, videoId: number | string) { |
23 | const res = await getVideo(server.url, videoId) | 17 | const video = await server.videos.get({ id: videoId }) |
24 | const video: VideoDetails = res.body | ||
25 | 18 | ||
26 | const res1 = await makeRawRequest(join(server.url, video.thumbnailPath), HttpStatusCode.OK_200) | 19 | const requests = [ |
27 | expect(res1.body).to.not.have.lengthOf(0) | 20 | makeRawRequest(join(server.url, video.thumbnailPath), HttpStatusCode.OK_200), |
21 | makeRawRequest(join(server.url, video.thumbnailPath), HttpStatusCode.OK_200) | ||
22 | ] | ||
28 | 23 | ||
29 | const res2 = await makeRawRequest(join(server.url, video.thumbnailPath), HttpStatusCode.OK_200) | 24 | for (const req of requests) { |
30 | expect(res2.body).to.not.have.lengthOf(0) | 25 | const res = await req |
26 | expect(res.body).to.not.have.lengthOf(0) | ||
27 | } | ||
31 | } | 28 | } |
32 | 29 | ||
33 | describe('Test regenerate thumbnails script', function () { | 30 | describe('Test regenerate thumbnails script', function () { |
34 | let servers: ServerInfo[] | 31 | let servers: PeerTubeServer[] |
35 | 32 | ||
36 | let video1: Video | 33 | let video1: Video |
37 | let video2: Video | 34 | let video2: Video |
@@ -43,28 +40,28 @@ describe('Test regenerate thumbnails script', function () { | |||
43 | before(async function () { | 40 | before(async function () { |
44 | this.timeout(60000) | 41 | this.timeout(60000) |
45 | 42 | ||
46 | servers = await flushAndRunMultipleServers(2) | 43 | servers = await createMultipleServers(2) |
47 | await setAccessTokensToServers(servers) | 44 | await setAccessTokensToServers(servers) |
48 | 45 | ||
49 | await doubleFollow(servers[0], servers[1]) | 46 | await doubleFollow(servers[0], servers[1]) |
50 | 47 | ||
51 | { | 48 | { |
52 | const videoUUID1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 1' })).uuid | 49 | const videoUUID1 = (await servers[0].videos.quickUpload({ name: 'video 1' })).uuid |
53 | video1 = await (getVideo(servers[0].url, videoUUID1).then(res => res.body)) | 50 | video1 = await servers[0].videos.get({ id: videoUUID1 }) |
54 | 51 | ||
55 | thumbnail1Path = join(buildServerDirectory(servers[0], 'thumbnails'), basename(video1.thumbnailPath)) | 52 | thumbnail1Path = join(servers[0].servers.buildDirectory('thumbnails'), basename(video1.thumbnailPath)) |
56 | 53 | ||
57 | const videoUUID2 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 2' })).uuid | 54 | const videoUUID2 = (await servers[0].videos.quickUpload({ name: 'video 2' })).uuid |
58 | video2 = await (getVideo(servers[0].url, videoUUID2).then(res => res.body)) | 55 | video2 = await servers[0].videos.get({ id: videoUUID2 }) |
59 | } | 56 | } |
60 | 57 | ||
61 | { | 58 | { |
62 | const videoUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 3' })).uuid | 59 | const videoUUID = (await servers[1].videos.quickUpload({ name: 'video 3' })).uuid |
63 | await waitJobs(servers) | 60 | await waitJobs(servers) |
64 | 61 | ||
65 | remoteVideo = await (getVideo(servers[0].url, videoUUID).then(res => res.body)) | 62 | remoteVideo = await servers[0].videos.get({ id: videoUUID }) |
66 | 63 | ||
67 | thumbnailRemotePath = join(buildServerDirectory(servers[0], 'thumbnails'), basename(remoteVideo.thumbnailPath)) | 64 | thumbnailRemotePath = join(servers[0].servers.buildDirectory('thumbnails'), basename(remoteVideo.thumbnailPath)) |
68 | } | 65 | } |
69 | 66 | ||
70 | await writeFile(thumbnail1Path, '') | 67 | await writeFile(thumbnail1Path, '') |
@@ -91,8 +88,7 @@ describe('Test regenerate thumbnails script', function () { | |||
91 | it('Should regenerate local thumbnails from the CLI', async function () { | 88 | it('Should regenerate local thumbnails from the CLI', async function () { |
92 | this.timeout(15000) | 89 | this.timeout(15000) |
93 | 90 | ||
94 | const env = getEnvCli(servers[0]) | 91 | await servers[0].cli.execWithEnv(`npm run regenerate-thumbnails`) |
95 | await execCLI(`${env} npm run regenerate-thumbnails`) | ||
96 | }) | 92 | }) |
97 | 93 | ||
98 | it('Should have generated new thumbnail files', async function () { | 94 | it('Should have generated new thumbnail files', async function () { |