aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/cli/index.ts1
-rw-r--r--server/tests/cli/regenerate-thumbnails.ts110
2 files changed, 111 insertions, 0 deletions
diff --git a/server/tests/cli/index.ts b/server/tests/cli/index.ts
index 242589010..7e6eebd17 100644
--- a/server/tests/cli/index.ts
+++ b/server/tests/cli/index.ts
@@ -6,5 +6,6 @@ import './peertube'
6import './plugins' 6import './plugins'
7import './print-transcode-command' 7import './print-transcode-command'
8import './prune-storage' 8import './prune-storage'
9import './regenerate-thumbnails'
9import './reset-password' 10import './reset-password'
10import './update-host' 11import './update-host'
diff --git a/server/tests/cli/regenerate-thumbnails.ts b/server/tests/cli/regenerate-thumbnails.ts
new file mode 100644
index 000000000..56005518a
--- /dev/null
+++ b/server/tests/cli/regenerate-thumbnails.ts
@@ -0,0 +1,110 @@
1import 'mocha'
2import { expect } from 'chai'
3import { writeFile } from 'fs-extra'
4import { basename, join } from 'path'
5import { Video } from '@shared/models'
6import {
7 buildServerDirectory,
8 cleanupTests,
9 doubleFollow,
10 execCLI,
11 flushAndRunMultipleServers,
12 getEnvCli,
13 getVideo,
14 makeRawRequest,
15 ServerInfo,
16 setAccessTokensToServers,
17 uploadVideoAndGetId,
18 waitJobs
19} from '../../../shared/extra-utils'
20import { HttpStatusCode } from '@shared/core-utils'
21
22describe('Test regenerate thumbnails script', function () {
23 let servers: ServerInfo[]
24
25 let video1: Video
26 let video2: Video
27 let remoteVideo: Video
28
29 let thumbnail1Path: string
30 let thumbnailRemotePath: string
31
32 before(async function () {
33 this.timeout(60000)
34
35 servers = await flushAndRunMultipleServers(2)
36 await setAccessTokensToServers(servers)
37
38 await doubleFollow(servers[0], servers[1])
39
40 {
41 const videoUUID1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 1' })).uuid
42 video1 = await (getVideo(servers[0].url, videoUUID1).then(res => res.body))
43
44 thumbnail1Path = join(buildServerDirectory(servers[0], 'thumbnails'), basename(video1.thumbnailPath))
45
46 const videoUUID2 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 2' })).uuid
47 video2 = await (getVideo(servers[0].url, videoUUID2).then(res => res.body))
48 }
49
50 {
51 const videoUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 3' })).uuid
52 await waitJobs(servers)
53
54 remoteVideo = await (getVideo(servers[0].url, videoUUID).then(res => res.body))
55
56 thumbnailRemotePath = join(buildServerDirectory(servers[0], 'thumbnails'), basename(remoteVideo.thumbnailPath))
57 }
58
59 await writeFile(thumbnail1Path, '')
60 await writeFile(thumbnailRemotePath, '')
61 })
62
63 it('Should have empty thumbnails', async function () {
64 {
65 const res = await makeRawRequest(join(servers[0].url, video1.thumbnailPath), HttpStatusCode.OK_200)
66 expect(res.body).to.have.lengthOf(0)
67 }
68
69 {
70 const res = await makeRawRequest(join(servers[0].url, video2.thumbnailPath), HttpStatusCode.OK_200)
71 expect(res.body).to.not.have.lengthOf(0)
72 }
73
74 {
75 const res = await makeRawRequest(join(servers[0].url, remoteVideo.thumbnailPath), HttpStatusCode.OK_200)
76 expect(res.body).to.have.lengthOf(0)
77 }
78 })
79
80 it('Should regenerate thumbnails from the CLI', async function () {
81 this.timeout(15000)
82
83 const env = getEnvCli(servers[0])
84 await execCLI(`${env} npm run regenerate-thumbnails`)
85 })
86
87 it('Should have regenerated thumbbnails', async function () {
88 {
89 const res1 = await makeRawRequest(join(servers[0].url, video1.thumbnailPath), HttpStatusCode.OK_200)
90 expect(res1.body).to.not.have.lengthOf(0)
91
92 const res2 = await makeRawRequest(join(servers[0].url, video1.previewPath), HttpStatusCode.OK_200)
93 expect(res2.body).to.not.have.lengthOf(0)
94 }
95
96 {
97 const res = await makeRawRequest(join(servers[0].url, video2.thumbnailPath), HttpStatusCode.OK_200)
98 expect(res.body).to.not.have.lengthOf(0)
99 }
100
101 {
102 const res = await makeRawRequest(join(servers[0].url, remoteVideo.thumbnailPath), HttpStatusCode.OK_200)
103 expect(res.body).to.have.lengthOf(0)
104 }
105 })
106
107 after(async function () {
108 await cleanupTests(servers)
109 })
110})