]>
Commit | Line | Data |
---|---|---|
c2bd7a6f C |
1 | import 'mocha' |
2 | import { expect } from 'chai' | |
3 | import { writeFile } from 'fs-extra' | |
4 | import { basename, join } from 'path' | |
a0eeb45f | 5 | import { Video, VideoDetails } from '@shared/models' |
c2bd7a6f C |
6 | import { |
7 | buildServerDirectory, | |
8 | cleanupTests, | |
9 | doubleFollow, | |
c2bd7a6f | 10 | flushAndRunMultipleServers, |
c2bd7a6f C |
11 | getVideo, |
12 | makeRawRequest, | |
13 | ServerInfo, | |
14 | setAccessTokensToServers, | |
15 | uploadVideoAndGetId, | |
16 | waitJobs | |
17 | } from '../../../shared/extra-utils' | |
18 | import { HttpStatusCode } from '@shared/core-utils' | |
19 | ||
a0eeb45f C |
20 | async function testThumbnail (server: ServerInfo, videoId: number | string) { |
21 | const res = await getVideo(server.url, videoId) | |
22 | const video: VideoDetails = res.body | |
23 | ||
24 | const res1 = await makeRawRequest(join(server.url, video.thumbnailPath), HttpStatusCode.OK_200) | |
25 | expect(res1.body).to.not.have.lengthOf(0) | |
26 | ||
27 | const res2 = await makeRawRequest(join(server.url, video.thumbnailPath), HttpStatusCode.OK_200) | |
28 | expect(res2.body).to.not.have.lengthOf(0) | |
29 | } | |
30 | ||
c2bd7a6f C |
31 | describe('Test regenerate thumbnails script', function () { |
32 | let servers: ServerInfo[] | |
33 | ||
34 | let video1: Video | |
35 | let video2: Video | |
36 | let remoteVideo: Video | |
37 | ||
38 | let thumbnail1Path: string | |
39 | let thumbnailRemotePath: string | |
40 | ||
41 | before(async function () { | |
42 | this.timeout(60000) | |
43 | ||
44 | servers = await flushAndRunMultipleServers(2) | |
45 | await setAccessTokensToServers(servers) | |
46 | ||
47 | await doubleFollow(servers[0], servers[1]) | |
48 | ||
49 | { | |
50 | const videoUUID1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 1' })).uuid | |
51 | video1 = await (getVideo(servers[0].url, videoUUID1).then(res => res.body)) | |
52 | ||
53 | thumbnail1Path = join(buildServerDirectory(servers[0], 'thumbnails'), basename(video1.thumbnailPath)) | |
54 | ||
55 | const videoUUID2 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 2' })).uuid | |
56 | video2 = await (getVideo(servers[0].url, videoUUID2).then(res => res.body)) | |
57 | } | |
58 | ||
59 | { | |
60 | const videoUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 3' })).uuid | |
61 | await waitJobs(servers) | |
62 | ||
63 | remoteVideo = await (getVideo(servers[0].url, videoUUID).then(res => res.body)) | |
64 | ||
65 | thumbnailRemotePath = join(buildServerDirectory(servers[0], 'thumbnails'), basename(remoteVideo.thumbnailPath)) | |
66 | } | |
67 | ||
68 | await writeFile(thumbnail1Path, '') | |
69 | await writeFile(thumbnailRemotePath, '') | |
70 | }) | |
71 | ||
72 | it('Should have empty thumbnails', async function () { | |
73 | { | |
74 | const res = await makeRawRequest(join(servers[0].url, video1.thumbnailPath), HttpStatusCode.OK_200) | |
75 | expect(res.body).to.have.lengthOf(0) | |
76 | } | |
77 | ||
78 | { | |
79 | const res = await makeRawRequest(join(servers[0].url, video2.thumbnailPath), HttpStatusCode.OK_200) | |
80 | expect(res.body).to.not.have.lengthOf(0) | |
81 | } | |
82 | ||
83 | { | |
84 | const res = await makeRawRequest(join(servers[0].url, remoteVideo.thumbnailPath), HttpStatusCode.OK_200) | |
85 | expect(res.body).to.have.lengthOf(0) | |
86 | } | |
87 | }) | |
88 | ||
20373985 | 89 | it('Should regenerate local thumbnails from the CLI', async function () { |
c2bd7a6f C |
90 | this.timeout(15000) |
91 | ||
329619b3 | 92 | await servers[0].cliCommand.execWithEnv(`npm run regenerate-thumbnails`) |
c2bd7a6f C |
93 | }) |
94 | ||
a0eeb45f C |
95 | it('Should have generated new thumbnail files', async function () { |
96 | await testThumbnail(servers[0], video1.uuid) | |
97 | await testThumbnail(servers[0], video2.uuid) | |
c2bd7a6f | 98 | |
a0eeb45f C |
99 | const res = await makeRawRequest(join(servers[0].url, remoteVideo.thumbnailPath), HttpStatusCode.OK_200) |
100 | expect(res.body).to.have.lengthOf(0) | |
101 | }) | |
102 | ||
103 | it('Should have deleted old thumbnail files', async function () { | |
104 | { | |
105 | await makeRawRequest(join(servers[0].url, video1.thumbnailPath), HttpStatusCode.NOT_FOUND_404) | |
c2bd7a6f C |
106 | } |
107 | ||
108 | { | |
a0eeb45f | 109 | await makeRawRequest(join(servers[0].url, video2.thumbnailPath), HttpStatusCode.NOT_FOUND_404) |
c2bd7a6f C |
110 | } |
111 | ||
112 | { | |
113 | const res = await makeRawRequest(join(servers[0].url, remoteVideo.thumbnailPath), HttpStatusCode.OK_200) | |
114 | expect(res.body).to.have.lengthOf(0) | |
115 | } | |
116 | }) | |
117 | ||
118 | after(async function () { | |
119 | await cleanupTests(servers) | |
120 | }) | |
121 | }) |