]>
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' | |
d23dd9fb C |
5 | import { HttpStatusCode } from '@shared/core-utils' |
6 | import { Video } from '@shared/models' | |
c2bd7a6f | 7 | import { |
c2bd7a6f C |
8 | cleanupTests, |
9 | doubleFollow, | |
c2bd7a6f | 10 | flushAndRunMultipleServers, |
c2bd7a6f C |
11 | makeRawRequest, |
12 | ServerInfo, | |
13 | setAccessTokensToServers, | |
c2bd7a6f C |
14 | waitJobs |
15 | } from '../../../shared/extra-utils' | |
c2bd7a6f | 16 | |
a0eeb45f | 17 | async function testThumbnail (server: ServerInfo, videoId: number | string) { |
89d241a7 | 18 | const video = await server.videos.get({ id: videoId }) |
a0eeb45f | 19 | |
d23dd9fb C |
20 | const requests = [ |
21 | makeRawRequest(join(server.url, video.thumbnailPath), HttpStatusCode.OK_200), | |
22 | makeRawRequest(join(server.url, video.thumbnailPath), HttpStatusCode.OK_200) | |
23 | ] | |
a0eeb45f | 24 | |
d23dd9fb C |
25 | for (const req of requests) { |
26 | const res = await req | |
27 | expect(res.body).to.not.have.lengthOf(0) | |
28 | } | |
a0eeb45f C |
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 | { | |
89d241a7 C |
50 | const videoUUID1 = (await servers[0].videos.quickUpload({ name: 'video 1' })).uuid |
51 | video1 = await servers[0].videos.get({ id: videoUUID1 }) | |
c2bd7a6f | 52 | |
89d241a7 | 53 | thumbnail1Path = join(servers[0].servers.buildDirectory('thumbnails'), basename(video1.thumbnailPath)) |
c2bd7a6f | 54 | |
89d241a7 C |
55 | const videoUUID2 = (await servers[0].videos.quickUpload({ name: 'video 2' })).uuid |
56 | video2 = await servers[0].videos.get({ id: videoUUID2 }) | |
c2bd7a6f C |
57 | } |
58 | ||
59 | { | |
89d241a7 | 60 | const videoUUID = (await servers[1].videos.quickUpload({ name: 'video 3' })).uuid |
c2bd7a6f C |
61 | await waitJobs(servers) |
62 | ||
89d241a7 | 63 | remoteVideo = await servers[0].videos.get({ id: videoUUID }) |
c2bd7a6f | 64 | |
89d241a7 | 65 | thumbnailRemotePath = join(servers[0].servers.buildDirectory('thumbnails'), basename(remoteVideo.thumbnailPath)) |
c2bd7a6f C |
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 | ||
89d241a7 | 92 | await servers[0].cli.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 | }) |