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