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