]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
5 | import { | |
6 | cleanupTests, | |
7 | createMultipleServers, | |
8 | doubleFollow, | |
9 | PeerTubeServer, | |
10 | setAccessTokensToServers, | |
11 | setDefaultVideoChannel, | |
12 | testImage, | |
13 | waitJobs | |
14 | } from '../../../../shared/extra-utils' | |
15 | import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model' | |
16 | ||
17 | const expect = chai.expect | |
18 | ||
19 | describe('Playlist thumbnail', function () { | |
20 | let servers: PeerTubeServer[] = [] | |
21 | ||
22 | let playlistWithoutThumbnailId: number | |
23 | let playlistWithThumbnailId: number | |
24 | ||
25 | let withThumbnailE1: number | |
26 | let withThumbnailE2: number | |
27 | let withoutThumbnailE1: number | |
28 | let withoutThumbnailE2: number | |
29 | ||
30 | let video1: number | |
31 | let video2: number | |
32 | ||
33 | async function getPlaylistWithoutThumbnail (server: PeerTubeServer) { | |
34 | const body = await server.playlists.list({ start: 0, count: 10 }) | |
35 | ||
36 | return body.data.find(p => p.displayName === 'playlist without thumbnail') | |
37 | } | |
38 | ||
39 | async function getPlaylistWithThumbnail (server: PeerTubeServer) { | |
40 | const body = await server.playlists.list({ start: 0, count: 10 }) | |
41 | ||
42 | return body.data.find(p => p.displayName === 'playlist with thumbnail') | |
43 | } | |
44 | ||
45 | before(async function () { | |
46 | this.timeout(120000) | |
47 | ||
48 | servers = await createMultipleServers(2, { transcoding: { enabled: false } }) | |
49 | ||
50 | // Get the access tokens | |
51 | await setAccessTokensToServers(servers) | |
52 | await setDefaultVideoChannel(servers) | |
53 | ||
54 | // Server 1 and server 2 follow each other | |
55 | await doubleFollow(servers[0], servers[1]) | |
56 | ||
57 | video1 = (await servers[0].videos.quickUpload({ name: 'video 1' })).id | |
58 | video2 = (await servers[0].videos.quickUpload({ name: 'video 2' })).id | |
59 | ||
60 | await waitJobs(servers) | |
61 | }) | |
62 | ||
63 | it('Should automatically update the thumbnail when adding an element', async function () { | |
64 | this.timeout(30000) | |
65 | ||
66 | const created = await servers[1].playlists.create({ | |
67 | attributes: { | |
68 | displayName: 'playlist without thumbnail', | |
69 | privacy: VideoPlaylistPrivacy.PUBLIC, | |
70 | videoChannelId: servers[1].store.channel.id | |
71 | } | |
72 | }) | |
73 | playlistWithoutThumbnailId = created.id | |
74 | ||
75 | const added = await servers[1].playlists.addElement({ | |
76 | playlistId: playlistWithoutThumbnailId, | |
77 | attributes: { videoId: video1 } | |
78 | }) | |
79 | withoutThumbnailE1 = added.id | |
80 | ||
81 | await waitJobs(servers) | |
82 | ||
83 | for (const server of servers) { | |
84 | const p = await getPlaylistWithoutThumbnail(server) | |
85 | await testImage(server.url, 'thumbnail-playlist', p.thumbnailPath) | |
86 | } | |
87 | }) | |
88 | ||
89 | it('Should not update the thumbnail if we explicitly uploaded a thumbnail', async function () { | |
90 | this.timeout(30000) | |
91 | ||
92 | const created = await servers[1].playlists.create({ | |
93 | attributes: { | |
94 | displayName: 'playlist with thumbnail', | |
95 | privacy: VideoPlaylistPrivacy.PUBLIC, | |
96 | videoChannelId: servers[1].store.channel.id, | |
97 | thumbnailfile: 'thumbnail.jpg' | |
98 | } | |
99 | }) | |
100 | playlistWithThumbnailId = created.id | |
101 | ||
102 | const added = await servers[1].playlists.addElement({ | |
103 | playlistId: playlistWithThumbnailId, | |
104 | attributes: { videoId: video1 } | |
105 | }) | |
106 | withThumbnailE1 = added.id | |
107 | ||
108 | await waitJobs(servers) | |
109 | ||
110 | for (const server of servers) { | |
111 | const p = await getPlaylistWithThumbnail(server) | |
112 | await testImage(server.url, 'thumbnail', p.thumbnailPath) | |
113 | } | |
114 | }) | |
115 | ||
116 | it('Should automatically update the thumbnail when moving the first element', async function () { | |
117 | this.timeout(30000) | |
118 | ||
119 | const added = await servers[1].playlists.addElement({ | |
120 | playlistId: playlistWithoutThumbnailId, | |
121 | attributes: { videoId: video2 } | |
122 | }) | |
123 | withoutThumbnailE2 = added.id | |
124 | ||
125 | await servers[1].playlists.reorderElements({ | |
126 | playlistId: playlistWithoutThumbnailId, | |
127 | attributes: { | |
128 | startPosition: 1, | |
129 | insertAfterPosition: 2 | |
130 | } | |
131 | }) | |
132 | ||
133 | await waitJobs(servers) | |
134 | ||
135 | for (const server of servers) { | |
136 | const p = await getPlaylistWithoutThumbnail(server) | |
137 | await testImage(server.url, 'thumbnail-playlist', p.thumbnailPath) | |
138 | } | |
139 | }) | |
140 | ||
141 | it('Should not update the thumbnail when moving the first element if we explicitly uploaded a thumbnail', async function () { | |
142 | this.timeout(30000) | |
143 | ||
144 | const added = await servers[1].playlists.addElement({ | |
145 | playlistId: playlistWithThumbnailId, | |
146 | attributes: { videoId: video2 } | |
147 | }) | |
148 | withThumbnailE2 = added.id | |
149 | ||
150 | await servers[1].playlists.reorderElements({ | |
151 | playlistId: playlistWithThumbnailId, | |
152 | attributes: { | |
153 | startPosition: 1, | |
154 | insertAfterPosition: 2 | |
155 | } | |
156 | }) | |
157 | ||
158 | await waitJobs(servers) | |
159 | ||
160 | for (const server of servers) { | |
161 | const p = await getPlaylistWithThumbnail(server) | |
162 | await testImage(server.url, 'thumbnail', p.thumbnailPath) | |
163 | } | |
164 | }) | |
165 | ||
166 | it('Should automatically update the thumbnail when deleting the first element', async function () { | |
167 | this.timeout(30000) | |
168 | ||
169 | await servers[1].playlists.removeElement({ | |
170 | playlistId: playlistWithoutThumbnailId, | |
171 | elementId: withoutThumbnailE1 | |
172 | }) | |
173 | ||
174 | await waitJobs(servers) | |
175 | ||
176 | for (const server of servers) { | |
177 | const p = await getPlaylistWithoutThumbnail(server) | |
178 | await testImage(server.url, 'thumbnail-playlist', p.thumbnailPath) | |
179 | } | |
180 | }) | |
181 | ||
182 | it('Should not update the thumbnail when deleting the first element if we explicitly uploaded a thumbnail', async function () { | |
183 | this.timeout(30000) | |
184 | ||
185 | await servers[1].playlists.removeElement({ | |
186 | playlistId: playlistWithThumbnailId, | |
187 | elementId: withThumbnailE1 | |
188 | }) | |
189 | ||
190 | await waitJobs(servers) | |
191 | ||
192 | for (const server of servers) { | |
193 | const p = await getPlaylistWithThumbnail(server) | |
194 | await testImage(server.url, 'thumbnail', p.thumbnailPath) | |
195 | } | |
196 | }) | |
197 | ||
198 | it('Should the thumbnail when we delete the last element', async function () { | |
199 | this.timeout(30000) | |
200 | ||
201 | await servers[1].playlists.removeElement({ | |
202 | playlistId: playlistWithoutThumbnailId, | |
203 | elementId: withoutThumbnailE2 | |
204 | }) | |
205 | ||
206 | await waitJobs(servers) | |
207 | ||
208 | for (const server of servers) { | |
209 | const p = await getPlaylistWithoutThumbnail(server) | |
210 | expect(p.thumbnailPath).to.be.null | |
211 | } | |
212 | }) | |
213 | ||
214 | it('Should not update the thumbnail when we delete the last element if we explicitly uploaded a thumbnail', async function () { | |
215 | this.timeout(30000) | |
216 | ||
217 | await servers[1].playlists.removeElement({ | |
218 | playlistId: playlistWithThumbnailId, | |
219 | elementId: withThumbnailE2 | |
220 | }) | |
221 | ||
222 | await waitJobs(servers) | |
223 | ||
224 | for (const server of servers) { | |
225 | const p = await getPlaylistWithThumbnail(server) | |
226 | await testImage(server.url, 'thumbnail', p.thumbnailPath) | |
227 | } | |
228 | }) | |
229 | ||
230 | after(async function () { | |
231 | await cleanupTests(servers) | |
232 | }) | |
233 | }) |