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