diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-21 15:51:30 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-21 15:51:30 +0200 |
commit | a24bd1ed41b43790bab6ba789580bb4e85f07d85 (patch) | |
tree | a54b0f6c921ba83a6e909cd0ced325b2d4b8863c /server/tests/api/videos/video-playlists.ts | |
parent | 5f26f13b3c16ac5ae0a3b0a7142d84a9528cf565 (diff) | |
parent | c63830f15403ac4e750829f27d8bbbdc9a59282c (diff) | |
download | PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.gz PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.zst PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.zip |
Merge branch 'next' into develop
Diffstat (limited to 'server/tests/api/videos/video-playlists.ts')
-rw-r--r-- | server/tests/api/videos/video-playlists.ts | 727 |
1 files changed, 303 insertions, 424 deletions
diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts index da8de054b..f42aee2ff 100644 --- a/server/tests/api/videos/video-playlists.ts +++ b/server/tests/api/videos/video-playlists.ts | |||
@@ -2,71 +2,33 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
6 | import { | 5 | import { |
7 | addVideoChannel, | ||
8 | addVideoInPlaylist, | ||
9 | addVideoToBlacklist, | ||
10 | checkPlaylistFilesWereRemoved, | 6 | checkPlaylistFilesWereRemoved, |
11 | cleanupTests, | 7 | cleanupTests, |
12 | createUser, | 8 | createMultipleServers, |
13 | createVideoPlaylist, | ||
14 | deleteVideoChannel, | ||
15 | deleteVideoPlaylist, | ||
16 | doubleFollow, | 9 | doubleFollow, |
17 | doVideosExistInMyPlaylist, | 10 | PeerTubeServer, |
18 | flushAndRunMultipleServers, | 11 | PlaylistsCommand, |
19 | generateUserAccessToken, | ||
20 | getAccessToken, | ||
21 | getAccountPlaylistsList, | ||
22 | getAccountPlaylistsListWithToken, | ||
23 | getMyUserInformation, | ||
24 | getPlaylistVideos, | ||
25 | getVideoChannelPlaylistsList, | ||
26 | getVideoPlaylist, | ||
27 | getVideoPlaylistPrivacies, | ||
28 | getVideoPlaylistsList, | ||
29 | getVideoPlaylistWithToken, | ||
30 | removeUser, | ||
31 | removeVideoFromBlacklist, | ||
32 | removeVideoFromPlaylist, | ||
33 | reorderVideosPlaylist, | ||
34 | ServerInfo, | ||
35 | setAccessTokensToServers, | 12 | setAccessTokensToServers, |
36 | setDefaultVideoChannel, | 13 | setDefaultVideoChannel, |
37 | testImage, | 14 | testImage, |
38 | unfollow, | ||
39 | updateVideo, | ||
40 | updateVideoPlaylist, | ||
41 | updateVideoPlaylistElement, | ||
42 | uploadVideo, | ||
43 | uploadVideoAndGetId, | ||
44 | userLogin, | ||
45 | wait, | 15 | wait, |
46 | waitJobs | 16 | waitJobs |
47 | } from '../../../../shared/extra-utils' | 17 | } from '@shared/extra-utils' |
48 | import { | 18 | import { |
49 | addAccountToAccountBlocklist, | 19 | HttpStatusCode, |
50 | addAccountToServerBlocklist, | 20 | VideoPlaylist, |
51 | addServerToAccountBlocklist, | 21 | VideoPlaylistCreateResult, |
52 | addServerToServerBlocklist, | 22 | VideoPlaylistElementType, |
53 | removeAccountFromAccountBlocklist, | 23 | VideoPlaylistPrivacy, |
54 | removeAccountFromServerBlocklist, | 24 | VideoPlaylistType, |
55 | removeServerFromAccountBlocklist, | 25 | VideoPrivacy |
56 | removeServerFromServerBlocklist | 26 | } from '@shared/models' |
57 | } from '../../../../shared/extra-utils/users/blocklist' | ||
58 | import { User } from '../../../../shared/models/users' | ||
59 | import { VideoPlaylistCreateResult, VideoPrivacy } from '../../../../shared/models/videos' | ||
60 | import { VideoExistInPlaylist } from '../../../../shared/models/videos/playlist/video-exist-in-playlist.model' | ||
61 | import { VideoPlaylistElement, VideoPlaylistElementType } from '../../../../shared/models/videos/playlist/video-playlist-element.model' | ||
62 | import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model' | ||
63 | import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/video-playlist-type.model' | ||
64 | import { VideoPlaylist } from '../../../../shared/models/videos/playlist/video-playlist.model' | ||
65 | 27 | ||
66 | const expect = chai.expect | 28 | const expect = chai.expect |
67 | 29 | ||
68 | async function checkPlaylistElementType ( | 30 | async function checkPlaylistElementType ( |
69 | servers: ServerInfo[], | 31 | servers: PeerTubeServer[], |
70 | playlistId: string, | 32 | playlistId: string, |
71 | type: VideoPlaylistElementType, | 33 | type: VideoPlaylistElementType, |
72 | position: number, | 34 | position: number, |
@@ -74,10 +36,10 @@ async function checkPlaylistElementType ( | |||
74 | total: number | 36 | total: number |
75 | ) { | 37 | ) { |
76 | for (const server of servers) { | 38 | for (const server of servers) { |
77 | const res = await getPlaylistVideos(server.url, server.accessToken, playlistId, 0, 10) | 39 | const body = await server.playlists.listVideos({ token: server.accessToken, playlistId, start: 0, count: 10 }) |
78 | expect(res.body.total).to.equal(total) | 40 | expect(body.total).to.equal(total) |
79 | 41 | ||
80 | const videoElement: VideoPlaylistElement = res.body.data.find((e: VideoPlaylistElement) => e.position === position) | 42 | const videoElement = body.data.find(e => e.position === position) |
81 | expect(videoElement.type).to.equal(type, 'On server ' + server.url) | 43 | expect(videoElement.type).to.equal(type, 'On server ' + server.url) |
82 | 44 | ||
83 | if (type === VideoPlaylistElementType.REGULAR) { | 45 | if (type === VideoPlaylistElementType.REGULAR) { |
@@ -90,11 +52,11 @@ async function checkPlaylistElementType ( | |||
90 | } | 52 | } |
91 | 53 | ||
92 | describe('Test video playlists', function () { | 54 | describe('Test video playlists', function () { |
93 | let servers: ServerInfo[] = [] | 55 | let servers: PeerTubeServer[] = [] |
94 | 56 | ||
95 | let playlistServer2Id1: number | 57 | let playlistServer2Id1: number |
96 | let playlistServer2Id2: number | 58 | let playlistServer2Id2: number |
97 | let playlistServer2UUID2: number | 59 | let playlistServer2UUID2: string |
98 | 60 | ||
99 | let playlistServer1Id: number | 61 | let playlistServer1Id: number |
100 | let playlistServer1UUID: string | 62 | let playlistServer1UUID: string |
@@ -106,12 +68,14 @@ describe('Test video playlists', function () { | |||
106 | 68 | ||
107 | let nsfwVideoServer1: number | 69 | let nsfwVideoServer1: number |
108 | 70 | ||
109 | let userAccessTokenServer1: string | 71 | let userTokenServer1: string |
72 | |||
73 | let commands: PlaylistsCommand[] | ||
110 | 74 | ||
111 | before(async function () { | 75 | before(async function () { |
112 | this.timeout(120000) | 76 | this.timeout(120000) |
113 | 77 | ||
114 | servers = await flushAndRunMultipleServers(3, { transcoding: { enabled: false } }) | 78 | servers = await createMultipleServers(3, { transcoding: { enabled: false } }) |
115 | 79 | ||
116 | // Get the access tokens | 80 | // Get the access tokens |
117 | await setAccessTokensToServers(servers) | 81 | await setAccessTokensToServers(servers) |
@@ -122,86 +86,78 @@ describe('Test video playlists', function () { | |||
122 | // Server 1 and server 3 follow each other | 86 | // Server 1 and server 3 follow each other |
123 | await doubleFollow(servers[0], servers[2]) | 87 | await doubleFollow(servers[0], servers[2]) |
124 | 88 | ||
89 | commands = servers.map(s => s.playlists) | ||
90 | |||
125 | { | 91 | { |
126 | servers[0].videos = [] | 92 | servers[0].store.videos = [] |
127 | servers[1].videos = [] | 93 | servers[1].store.videos = [] |
128 | servers[2].videos = [] | 94 | servers[2].store.videos = [] |
129 | 95 | ||
130 | for (const server of servers) { | 96 | for (const server of servers) { |
131 | for (let i = 0; i < 7; i++) { | 97 | for (let i = 0; i < 7; i++) { |
132 | const name = `video ${i} server ${server.serverNumber}` | 98 | const name = `video ${i} server ${server.serverNumber}` |
133 | const resVideo = await uploadVideo(server.url, server.accessToken, { name, nsfw: false }) | 99 | const video = await server.videos.upload({ attributes: { name, nsfw: false } }) |
134 | 100 | ||
135 | server.videos.push(resVideo.body.video) | 101 | server.store.videos.push(video) |
136 | } | 102 | } |
137 | } | 103 | } |
138 | } | 104 | } |
139 | 105 | ||
140 | nsfwVideoServer1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'NSFW video', nsfw: true })).id | 106 | nsfwVideoServer1 = (await servers[0].videos.quickUpload({ name: 'NSFW video', nsfw: true })).id |
141 | 107 | ||
142 | { | 108 | userTokenServer1 = await servers[0].users.generateUserAndToken('user1') |
143 | await createUser({ | ||
144 | url: servers[0].url, | ||
145 | accessToken: servers[0].accessToken, | ||
146 | username: 'user1', | ||
147 | password: 'password' | ||
148 | }) | ||
149 | userAccessTokenServer1 = await getAccessToken(servers[0].url, 'user1', 'password') | ||
150 | } | ||
151 | 109 | ||
152 | await waitJobs(servers) | 110 | await waitJobs(servers) |
153 | }) | 111 | }) |
154 | 112 | ||
155 | describe('Get default playlists', function () { | 113 | describe('Get default playlists', function () { |
114 | |||
156 | it('Should list video playlist privacies', async function () { | 115 | it('Should list video playlist privacies', async function () { |
157 | const res = await getVideoPlaylistPrivacies(servers[0].url) | 116 | const privacies = await commands[0].getPrivacies() |
158 | 117 | ||
159 | const privacies = res.body | ||
160 | expect(Object.keys(privacies)).to.have.length.at.least(3) | 118 | expect(Object.keys(privacies)).to.have.length.at.least(3) |
161 | |||
162 | expect(privacies[3]).to.equal('Private') | 119 | expect(privacies[3]).to.equal('Private') |
163 | }) | 120 | }) |
164 | 121 | ||
165 | it('Should list watch later playlist', async function () { | 122 | it('Should list watch later playlist', async function () { |
166 | const url = servers[0].url | 123 | const token = servers[0].accessToken |
167 | const accessToken = servers[0].accessToken | ||
168 | 124 | ||
169 | { | 125 | { |
170 | const res = await getAccountPlaylistsListWithToken(url, accessToken, 'root', 0, 5, VideoPlaylistType.WATCH_LATER) | 126 | const body = await commands[0].listByAccount({ token, handle: 'root', playlistType: VideoPlaylistType.WATCH_LATER }) |
171 | 127 | ||
172 | expect(res.body.total).to.equal(1) | 128 | expect(body.total).to.equal(1) |
173 | expect(res.body.data).to.have.lengthOf(1) | 129 | expect(body.data).to.have.lengthOf(1) |
174 | 130 | ||
175 | const playlist: VideoPlaylist = res.body.data[0] | 131 | const playlist = body.data[0] |
176 | expect(playlist.displayName).to.equal('Watch later') | 132 | expect(playlist.displayName).to.equal('Watch later') |
177 | expect(playlist.type.id).to.equal(VideoPlaylistType.WATCH_LATER) | 133 | expect(playlist.type.id).to.equal(VideoPlaylistType.WATCH_LATER) |
178 | expect(playlist.type.label).to.equal('Watch later') | 134 | expect(playlist.type.label).to.equal('Watch later') |
179 | } | 135 | } |
180 | 136 | ||
181 | { | 137 | { |
182 | const res = await getAccountPlaylistsListWithToken(url, accessToken, 'root', 0, 5, VideoPlaylistType.REGULAR) | 138 | const body = await commands[0].listByAccount({ token, handle: 'root', playlistType: VideoPlaylistType.REGULAR }) |
183 | 139 | ||
184 | expect(res.body.total).to.equal(0) | 140 | expect(body.total).to.equal(0) |
185 | expect(res.body.data).to.have.lengthOf(0) | 141 | expect(body.data).to.have.lengthOf(0) |
186 | } | 142 | } |
187 | 143 | ||
188 | { | 144 | { |
189 | const res = await getAccountPlaylistsList(url, 'root', 0, 5) | 145 | const body = await commands[0].listByAccount({ handle: 'root' }) |
190 | expect(res.body.total).to.equal(0) | 146 | expect(body.total).to.equal(0) |
191 | expect(res.body.data).to.have.lengthOf(0) | 147 | expect(body.data).to.have.lengthOf(0) |
192 | } | 148 | } |
193 | }) | 149 | }) |
194 | 150 | ||
195 | it('Should get private playlist for a classic user', async function () { | 151 | it('Should get private playlist for a classic user', async function () { |
196 | const token = await generateUserAccessToken(servers[0], 'toto') | 152 | const token = await servers[0].users.generateUserAndToken('toto') |
197 | 153 | ||
198 | const res = await getAccountPlaylistsListWithToken(servers[0].url, token, 'toto', 0, 5) | 154 | const body = await commands[0].listByAccount({ token, handle: 'toto' }) |
199 | 155 | ||
200 | expect(res.body.total).to.equal(1) | 156 | expect(body.total).to.equal(1) |
201 | expect(res.body.data).to.have.lengthOf(1) | 157 | expect(body.data).to.have.lengthOf(1) |
202 | 158 | ||
203 | const playlistId = res.body.data[0].id | 159 | const playlistId = body.data[0].id |
204 | await getPlaylistVideos(servers[0].url, token, playlistId, 0, 5) | 160 | await commands[0].listVideos({ token, playlistId }) |
205 | }) | 161 | }) |
206 | }) | 162 | }) |
207 | 163 | ||
@@ -210,15 +166,13 @@ describe('Test video playlists', function () { | |||
210 | it('Should create a playlist on server 1 and have the playlist on server 2 and 3', async function () { | 166 | it('Should create a playlist on server 1 and have the playlist on server 2 and 3', async function () { |
211 | this.timeout(30000) | 167 | this.timeout(30000) |
212 | 168 | ||
213 | await createVideoPlaylist({ | 169 | await commands[0].create({ |
214 | url: servers[0].url, | 170 | attributes: { |
215 | token: servers[0].accessToken, | ||
216 | playlistAttrs: { | ||
217 | displayName: 'my super playlist', | 171 | displayName: 'my super playlist', |
218 | privacy: VideoPlaylistPrivacy.PUBLIC, | 172 | privacy: VideoPlaylistPrivacy.PUBLIC, |
219 | description: 'my super description', | 173 | description: 'my super description', |
220 | thumbnailfile: 'thumbnail.jpg', | 174 | thumbnailfile: 'thumbnail.jpg', |
221 | videoChannelId: servers[0].videoChannel.id | 175 | videoChannelId: servers[0].store.channel.id |
222 | } | 176 | } |
223 | }) | 177 | }) |
224 | 178 | ||
@@ -227,14 +181,13 @@ describe('Test video playlists', function () { | |||
227 | await wait(3000) | 181 | await wait(3000) |
228 | 182 | ||
229 | for (const server of servers) { | 183 | for (const server of servers) { |
230 | const res = await getVideoPlaylistsList(server.url, 0, 5) | 184 | const body = await server.playlists.list({ start: 0, count: 5 }) |
231 | expect(res.body.total).to.equal(1) | 185 | expect(body.total).to.equal(1) |
232 | expect(res.body.data).to.have.lengthOf(1) | 186 | expect(body.data).to.have.lengthOf(1) |
233 | 187 | ||
234 | const playlistFromList = res.body.data[0] as VideoPlaylist | 188 | const playlistFromList = body.data[0] |
235 | 189 | ||
236 | const res2 = await getVideoPlaylist(server.url, playlistFromList.uuid) | 190 | const playlistFromGet = await server.playlists.get({ playlistId: playlistFromList.uuid }) |
237 | const playlistFromGet = res2.body as VideoPlaylist | ||
238 | 191 | ||
239 | for (const playlist of [ playlistFromGet, playlistFromList ]) { | 192 | for (const playlist of [ playlistFromGet, playlistFromList ]) { |
240 | expect(playlist.id).to.be.a('number') | 193 | expect(playlist.id).to.be.a('number') |
@@ -264,46 +217,38 @@ describe('Test video playlists', function () { | |||
264 | this.timeout(30000) | 217 | this.timeout(30000) |
265 | 218 | ||
266 | { | 219 | { |
267 | const res = await createVideoPlaylist({ | 220 | const playlist = await servers[1].playlists.create({ |
268 | url: servers[1].url, | 221 | attributes: { |
269 | token: servers[1].accessToken, | ||
270 | playlistAttrs: { | ||
271 | displayName: 'playlist 2', | 222 | displayName: 'playlist 2', |
272 | privacy: VideoPlaylistPrivacy.PUBLIC, | 223 | privacy: VideoPlaylistPrivacy.PUBLIC, |
273 | videoChannelId: servers[1].videoChannel.id | 224 | videoChannelId: servers[1].store.channel.id |
274 | } | 225 | } |
275 | }) | 226 | }) |
276 | playlistServer2Id1 = res.body.videoPlaylist.id | 227 | playlistServer2Id1 = playlist.id |
277 | } | 228 | } |
278 | 229 | ||
279 | { | 230 | { |
280 | const res = await createVideoPlaylist({ | 231 | const playlist = await servers[1].playlists.create({ |
281 | url: servers[1].url, | 232 | attributes: { |
282 | token: servers[1].accessToken, | ||
283 | playlistAttrs: { | ||
284 | displayName: 'playlist 3', | 233 | displayName: 'playlist 3', |
285 | privacy: VideoPlaylistPrivacy.PUBLIC, | 234 | privacy: VideoPlaylistPrivacy.PUBLIC, |
286 | thumbnailfile: 'thumbnail.jpg', | 235 | thumbnailfile: 'thumbnail.jpg', |
287 | videoChannelId: servers[1].videoChannel.id | 236 | videoChannelId: servers[1].store.channel.id |
288 | } | 237 | } |
289 | }) | 238 | }) |
290 | 239 | ||
291 | playlistServer2Id2 = res.body.videoPlaylist.id | 240 | playlistServer2Id2 = playlist.id |
292 | playlistServer2UUID2 = res.body.videoPlaylist.uuid | 241 | playlistServer2UUID2 = playlist.uuid |
293 | } | 242 | } |
294 | 243 | ||
295 | for (const id of [ playlistServer2Id1, playlistServer2Id2 ]) { | 244 | for (const id of [ playlistServer2Id1, playlistServer2Id2 ]) { |
296 | await addVideoInPlaylist({ | 245 | await servers[1].playlists.addElement({ |
297 | url: servers[1].url, | ||
298 | token: servers[1].accessToken, | ||
299 | playlistId: id, | 246 | playlistId: id, |
300 | elementAttrs: { videoId: servers[1].videos[0].id, startTimestamp: 1, stopTimestamp: 2 } | 247 | attributes: { videoId: servers[1].store.videos[0].id, startTimestamp: 1, stopTimestamp: 2 } |
301 | }) | 248 | }) |
302 | await addVideoInPlaylist({ | 249 | await servers[1].playlists.addElement({ |
303 | url: servers[1].url, | ||
304 | token: servers[1].accessToken, | ||
305 | playlistId: id, | 250 | playlistId: id, |
306 | elementAttrs: { videoId: servers[1].videos[1].id } | 251 | attributes: { videoId: servers[1].store.videos[1].id } |
307 | }) | 252 | }) |
308 | } | 253 | } |
309 | 254 | ||
@@ -311,20 +256,20 @@ describe('Test video playlists', function () { | |||
311 | await wait(3000) | 256 | await wait(3000) |
312 | 257 | ||
313 | for (const server of [ servers[0], servers[1] ]) { | 258 | for (const server of [ servers[0], servers[1] ]) { |
314 | const res = await getVideoPlaylistsList(server.url, 0, 5) | 259 | const body = await server.playlists.list({ start: 0, count: 5 }) |
315 | 260 | ||
316 | const playlist2 = res.body.data.find(p => p.displayName === 'playlist 2') | 261 | const playlist2 = body.data.find(p => p.displayName === 'playlist 2') |
317 | expect(playlist2).to.not.be.undefined | 262 | expect(playlist2).to.not.be.undefined |
318 | await testImage(server.url, 'thumbnail-playlist', playlist2.thumbnailPath) | 263 | await testImage(server.url, 'thumbnail-playlist', playlist2.thumbnailPath) |
319 | 264 | ||
320 | const playlist3 = res.body.data.find(p => p.displayName === 'playlist 3') | 265 | const playlist3 = body.data.find(p => p.displayName === 'playlist 3') |
321 | expect(playlist3).to.not.be.undefined | 266 | expect(playlist3).to.not.be.undefined |
322 | await testImage(server.url, 'thumbnail', playlist3.thumbnailPath) | 267 | await testImage(server.url, 'thumbnail', playlist3.thumbnailPath) |
323 | } | 268 | } |
324 | 269 | ||
325 | const res = await getVideoPlaylistsList(servers[2].url, 0, 5) | 270 | const body = await servers[2].playlists.list({ start: 0, count: 5 }) |
326 | expect(res.body.data.find(p => p.displayName === 'playlist 2')).to.be.undefined | 271 | expect(body.data.find(p => p.displayName === 'playlist 2')).to.be.undefined |
327 | expect(res.body.data.find(p => p.displayName === 'playlist 3')).to.be.undefined | 272 | expect(body.data.find(p => p.displayName === 'playlist 3')).to.be.undefined |
328 | }) | 273 | }) |
329 | 274 | ||
330 | it('Should have the playlist on server 3 after a new follow', async function () { | 275 | it('Should have the playlist on server 3 after a new follow', async function () { |
@@ -333,13 +278,13 @@ describe('Test video playlists', function () { | |||
333 | // Server 2 and server 3 follow each other | 278 | // Server 2 and server 3 follow each other |
334 | await doubleFollow(servers[1], servers[2]) | 279 | await doubleFollow(servers[1], servers[2]) |
335 | 280 | ||
336 | const res = await getVideoPlaylistsList(servers[2].url, 0, 5) | 281 | const body = await servers[2].playlists.list({ start: 0, count: 5 }) |
337 | 282 | ||
338 | const playlist2 = res.body.data.find(p => p.displayName === 'playlist 2') | 283 | const playlist2 = body.data.find(p => p.displayName === 'playlist 2') |
339 | expect(playlist2).to.not.be.undefined | 284 | expect(playlist2).to.not.be.undefined |
340 | await testImage(servers[2].url, 'thumbnail-playlist', playlist2.thumbnailPath) | 285 | await testImage(servers[2].url, 'thumbnail-playlist', playlist2.thumbnailPath) |
341 | 286 | ||
342 | expect(res.body.data.find(p => p.displayName === 'playlist 3')).to.not.be.undefined | 287 | expect(body.data.find(p => p.displayName === 'playlist 3')).to.not.be.undefined |
343 | }) | 288 | }) |
344 | }) | 289 | }) |
345 | 290 | ||
@@ -349,22 +294,20 @@ describe('Test video playlists', function () { | |||
349 | this.timeout(30000) | 294 | this.timeout(30000) |
350 | 295 | ||
351 | { | 296 | { |
352 | const res = await getVideoPlaylistsList(servers[2].url, 1, 2, 'createdAt') | 297 | const body = await servers[2].playlists.list({ start: 1, count: 2, sort: 'createdAt' }) |
353 | 298 | expect(body.total).to.equal(3) | |
354 | expect(res.body.total).to.equal(3) | ||
355 | 299 | ||
356 | const data: VideoPlaylist[] = res.body.data | 300 | const data = body.data |
357 | expect(data).to.have.lengthOf(2) | 301 | expect(data).to.have.lengthOf(2) |
358 | expect(data[0].displayName).to.equal('playlist 2') | 302 | expect(data[0].displayName).to.equal('playlist 2') |
359 | expect(data[1].displayName).to.equal('playlist 3') | 303 | expect(data[1].displayName).to.equal('playlist 3') |
360 | } | 304 | } |
361 | 305 | ||
362 | { | 306 | { |
363 | const res = await getVideoPlaylistsList(servers[2].url, 1, 2, '-createdAt') | 307 | const body = await servers[2].playlists.list({ start: 1, count: 2, sort: '-createdAt' }) |
308 | expect(body.total).to.equal(3) | ||
364 | 309 | ||
365 | expect(res.body.total).to.equal(3) | 310 | const data = body.data |
366 | |||
367 | const data: VideoPlaylist[] = res.body.data | ||
368 | expect(data).to.have.lengthOf(2) | 311 | expect(data).to.have.lengthOf(2) |
369 | expect(data[0].displayName).to.equal('playlist 2') | 312 | expect(data[0].displayName).to.equal('playlist 2') |
370 | expect(data[1].displayName).to.equal('my super playlist') | 313 | expect(data[1].displayName).to.equal('my super playlist') |
@@ -375,11 +318,10 @@ describe('Test video playlists', function () { | |||
375 | this.timeout(30000) | 318 | this.timeout(30000) |
376 | 319 | ||
377 | { | 320 | { |
378 | const res = await getVideoChannelPlaylistsList(servers[0].url, 'root_channel', 0, 2, '-createdAt') | 321 | const body = await commands[0].listByChannel({ handle: 'root_channel', start: 0, count: 2, sort: '-createdAt' }) |
379 | 322 | expect(body.total).to.equal(1) | |
380 | expect(res.body.total).to.equal(1) | ||
381 | 323 | ||
382 | const data: VideoPlaylist[] = res.body.data | 324 | const data = body.data |
383 | expect(data).to.have.lengthOf(1) | 325 | expect(data).to.have.lengthOf(1) |
384 | expect(data[0].displayName).to.equal('my super playlist') | 326 | expect(data[0].displayName).to.equal('my super playlist') |
385 | } | 327 | } |
@@ -389,41 +331,37 @@ describe('Test video playlists', function () { | |||
389 | this.timeout(30000) | 331 | this.timeout(30000) |
390 | 332 | ||
391 | { | 333 | { |
392 | const res = await getAccountPlaylistsList(servers[1].url, 'root', 1, 2, '-createdAt') | 334 | const body = await servers[1].playlists.listByAccount({ handle: 'root', start: 1, count: 2, sort: '-createdAt' }) |
335 | expect(body.total).to.equal(2) | ||
393 | 336 | ||
394 | expect(res.body.total).to.equal(2) | 337 | const data = body.data |
395 | |||
396 | const data: VideoPlaylist[] = res.body.data | ||
397 | expect(data).to.have.lengthOf(1) | 338 | expect(data).to.have.lengthOf(1) |
398 | expect(data[0].displayName).to.equal('playlist 2') | 339 | expect(data[0].displayName).to.equal('playlist 2') |
399 | } | 340 | } |
400 | 341 | ||
401 | { | 342 | { |
402 | const res = await getAccountPlaylistsList(servers[1].url, 'root', 1, 2, 'createdAt') | 343 | const body = await servers[1].playlists.listByAccount({ handle: 'root', start: 1, count: 2, sort: 'createdAt' }) |
403 | 344 | expect(body.total).to.equal(2) | |
404 | expect(res.body.total).to.equal(2) | ||
405 | 345 | ||
406 | const data: VideoPlaylist[] = res.body.data | 346 | const data = body.data |
407 | expect(data).to.have.lengthOf(1) | 347 | expect(data).to.have.lengthOf(1) |
408 | expect(data[0].displayName).to.equal('playlist 3') | 348 | expect(data[0].displayName).to.equal('playlist 3') |
409 | } | 349 | } |
410 | 350 | ||
411 | { | 351 | { |
412 | const res = await getAccountPlaylistsList(servers[1].url, 'root', 0, 10, 'createdAt', '3') | 352 | const body = await servers[1].playlists.listByAccount({ handle: 'root', sort: 'createdAt', search: '3' }) |
353 | expect(body.total).to.equal(1) | ||
413 | 354 | ||
414 | expect(res.body.total).to.equal(1) | 355 | const data = body.data |
415 | |||
416 | const data: VideoPlaylist[] = res.body.data | ||
417 | expect(data).to.have.lengthOf(1) | 356 | expect(data).to.have.lengthOf(1) |
418 | expect(data[0].displayName).to.equal('playlist 3') | 357 | expect(data[0].displayName).to.equal('playlist 3') |
419 | } | 358 | } |
420 | 359 | ||
421 | { | 360 | { |
422 | const res = await getAccountPlaylistsList(servers[1].url, 'root', 0, 10, 'createdAt', '4') | 361 | const body = await servers[1].playlists.listByAccount({ handle: 'root', sort: 'createdAt', search: '4' }) |
423 | 362 | expect(body.total).to.equal(0) | |
424 | expect(res.body.total).to.equal(0) | ||
425 | 363 | ||
426 | const data: VideoPlaylist[] = res.body.data | 364 | const data = body.data |
427 | expect(data).to.have.lengthOf(0) | 365 | expect(data).to.have.lengthOf(0) |
428 | } | 366 | } |
429 | }) | 367 | }) |
@@ -437,28 +375,22 @@ describe('Test video playlists', function () { | |||
437 | this.timeout(30000) | 375 | this.timeout(30000) |
438 | 376 | ||
439 | { | 377 | { |
440 | const res = await createVideoPlaylist({ | 378 | unlistedPlaylist = await servers[1].playlists.create({ |
441 | url: servers[1].url, | 379 | attributes: { |
442 | token: servers[1].accessToken, | ||
443 | playlistAttrs: { | ||
444 | displayName: 'playlist unlisted', | 380 | displayName: 'playlist unlisted', |
445 | privacy: VideoPlaylistPrivacy.UNLISTED, | 381 | privacy: VideoPlaylistPrivacy.UNLISTED, |
446 | videoChannelId: servers[1].videoChannel.id | 382 | videoChannelId: servers[1].store.channel.id |
447 | } | 383 | } |
448 | }) | 384 | }) |
449 | unlistedPlaylist = res.body.videoPlaylist | ||
450 | } | 385 | } |
451 | 386 | ||
452 | { | 387 | { |
453 | const res = await createVideoPlaylist({ | 388 | privatePlaylist = await servers[1].playlists.create({ |
454 | url: servers[1].url, | 389 | attributes: { |
455 | token: servers[1].accessToken, | ||
456 | playlistAttrs: { | ||
457 | displayName: 'playlist private', | 390 | displayName: 'playlist private', |
458 | privacy: VideoPlaylistPrivacy.PRIVATE | 391 | privacy: VideoPlaylistPrivacy.PRIVATE |
459 | } | 392 | } |
460 | }) | 393 | }) |
461 | privatePlaylist = res.body.videoPlaylist | ||
462 | } | 394 | } |
463 | 395 | ||
464 | await waitJobs(servers) | 396 | await waitJobs(servers) |
@@ -468,15 +400,15 @@ describe('Test video playlists', function () { | |||
468 | it('Should not list unlisted or private playlists', async function () { | 400 | it('Should not list unlisted or private playlists', async function () { |
469 | for (const server of servers) { | 401 | for (const server of servers) { |
470 | const results = [ | 402 | const results = [ |
471 | await getAccountPlaylistsList(server.url, 'root@localhost:' + servers[1].port, 0, 5, '-createdAt'), | 403 | await server.playlists.listByAccount({ handle: 'root@localhost:' + servers[1].port, sort: '-createdAt' }), |
472 | await getVideoPlaylistsList(server.url, 0, 2, '-createdAt') | 404 | await server.playlists.list({ start: 0, count: 2, sort: '-createdAt' }) |
473 | ] | 405 | ] |
474 | 406 | ||
475 | expect(results[0].body.total).to.equal(2) | 407 | expect(results[0].total).to.equal(2) |
476 | expect(results[1].body.total).to.equal(3) | 408 | expect(results[1].total).to.equal(3) |
477 | 409 | ||
478 | for (const res of results) { | 410 | for (const body of results) { |
479 | const data: VideoPlaylist[] = res.body.data | 411 | const data = body.data |
480 | expect(data).to.have.lengthOf(2) | 412 | expect(data).to.have.lengthOf(2) |
481 | expect(data[0].displayName).to.equal('playlist 3') | 413 | expect(data[0].displayName).to.equal('playlist 3') |
482 | expect(data[1].displayName).to.equal('playlist 2') | 414 | expect(data[1].displayName).to.equal('playlist 2') |
@@ -485,23 +417,23 @@ describe('Test video playlists', function () { | |||
485 | }) | 417 | }) |
486 | 418 | ||
487 | it('Should not get unlisted playlist using only the id', async function () { | 419 | it('Should not get unlisted playlist using only the id', async function () { |
488 | await getVideoPlaylist(servers[1].url, unlistedPlaylist.id, 404) | 420 | await servers[1].playlists.get({ playlistId: unlistedPlaylist.id, expectedStatus: 404 }) |
489 | }) | 421 | }) |
490 | 422 | ||
491 | it('Should get unlisted plyaylist using uuid or shortUUID', async function () { | 423 | it('Should get unlisted plyaylist using uuid or shortUUID', async function () { |
492 | await getVideoPlaylist(servers[1].url, unlistedPlaylist.uuid) | 424 | await servers[1].playlists.get({ playlistId: unlistedPlaylist.uuid }) |
493 | await getVideoPlaylist(servers[1].url, unlistedPlaylist.shortUUID) | 425 | await servers[1].playlists.get({ playlistId: unlistedPlaylist.shortUUID }) |
494 | }) | 426 | }) |
495 | 427 | ||
496 | it('Should not get private playlist without token', async function () { | 428 | it('Should not get private playlist without token', async function () { |
497 | for (const id of [ privatePlaylist.id, privatePlaylist.uuid, privatePlaylist.shortUUID ]) { | 429 | for (const id of [ privatePlaylist.id, privatePlaylist.uuid, privatePlaylist.shortUUID ]) { |
498 | await getVideoPlaylist(servers[1].url, id, 401) | 430 | await servers[1].playlists.get({ playlistId: id, expectedStatus: 401 }) |
499 | } | 431 | } |
500 | }) | 432 | }) |
501 | 433 | ||
502 | it('Should get private playlist with a token', async function () { | 434 | it('Should get private playlist with a token', async function () { |
503 | for (const id of [ privatePlaylist.id, privatePlaylist.uuid, privatePlaylist.shortUUID ]) { | 435 | for (const id of [ privatePlaylist.id, privatePlaylist.uuid, privatePlaylist.shortUUID ]) { |
504 | await getVideoPlaylistWithToken(servers[1].url, servers[1].accessToken, id) | 436 | await servers[1].playlists.get({ token: servers[1].accessToken, playlistId: id }) |
505 | } | 437 | } |
506 | }) | 438 | }) |
507 | }) | 439 | }) |
@@ -511,15 +443,13 @@ describe('Test video playlists', function () { | |||
511 | it('Should update a playlist', async function () { | 443 | it('Should update a playlist', async function () { |
512 | this.timeout(30000) | 444 | this.timeout(30000) |
513 | 445 | ||
514 | await updateVideoPlaylist({ | 446 | await servers[1].playlists.update({ |
515 | url: servers[1].url, | 447 | attributes: { |
516 | token: servers[1].accessToken, | ||
517 | playlistAttrs: { | ||
518 | displayName: 'playlist 3 updated', | 448 | displayName: 'playlist 3 updated', |
519 | description: 'description updated', | 449 | description: 'description updated', |
520 | privacy: VideoPlaylistPrivacy.UNLISTED, | 450 | privacy: VideoPlaylistPrivacy.UNLISTED, |
521 | thumbnailfile: 'thumbnail.jpg', | 451 | thumbnailfile: 'thumbnail.jpg', |
522 | videoChannelId: servers[1].videoChannel.id | 452 | videoChannelId: servers[1].store.channel.id |
523 | }, | 453 | }, |
524 | playlistId: playlistServer2Id2 | 454 | playlistId: playlistServer2Id2 |
525 | }) | 455 | }) |
@@ -527,8 +457,7 @@ describe('Test video playlists', function () { | |||
527 | await waitJobs(servers) | 457 | await waitJobs(servers) |
528 | 458 | ||
529 | for (const server of servers) { | 459 | for (const server of servers) { |
530 | const res = await getVideoPlaylist(server.url, playlistServer2UUID2) | 460 | const playlist = await server.playlists.get({ playlistId: playlistServer2UUID2 }) |
531 | const playlist: VideoPlaylist = res.body | ||
532 | 461 | ||
533 | expect(playlist.displayName).to.equal('playlist 3 updated') | 462 | expect(playlist.displayName).to.equal('playlist 3 updated') |
534 | expect(playlist.description).to.equal('description updated') | 463 | expect(playlist.description).to.equal('description updated') |
@@ -554,39 +483,37 @@ describe('Test video playlists', function () { | |||
554 | it('Should create a playlist containing different startTimestamp/endTimestamp videos', async function () { | 483 | it('Should create a playlist containing different startTimestamp/endTimestamp videos', async function () { |
555 | this.timeout(30000) | 484 | this.timeout(30000) |
556 | 485 | ||
557 | const addVideo = (elementAttrs: any) => { | 486 | const addVideo = (attributes: any) => { |
558 | return addVideoInPlaylist({ url: servers[0].url, token: servers[0].accessToken, playlistId: playlistServer1Id, elementAttrs }) | 487 | return commands[0].addElement({ playlistId: playlistServer1Id, attributes }) |
559 | } | 488 | } |
560 | 489 | ||
561 | const res = await createVideoPlaylist({ | 490 | const playlist = await commands[0].create({ |
562 | url: servers[0].url, | 491 | attributes: { |
563 | token: servers[0].accessToken, | ||
564 | playlistAttrs: { | ||
565 | displayName: 'playlist 4', | 492 | displayName: 'playlist 4', |
566 | privacy: VideoPlaylistPrivacy.PUBLIC, | 493 | privacy: VideoPlaylistPrivacy.PUBLIC, |
567 | videoChannelId: servers[0].videoChannel.id | 494 | videoChannelId: servers[0].store.channel.id |
568 | } | 495 | } |
569 | }) | 496 | }) |
570 | 497 | ||
571 | playlistServer1Id = res.body.videoPlaylist.id | 498 | playlistServer1Id = playlist.id |
572 | playlistServer1UUID = res.body.videoPlaylist.uuid | 499 | playlistServer1UUID = playlist.uuid |
573 | 500 | ||
574 | await addVideo({ videoId: servers[0].videos[0].uuid, startTimestamp: 15, stopTimestamp: 28 }) | 501 | await addVideo({ videoId: servers[0].store.videos[0].uuid, startTimestamp: 15, stopTimestamp: 28 }) |
575 | await addVideo({ videoId: servers[2].videos[1].uuid, startTimestamp: 35 }) | 502 | await addVideo({ videoId: servers[2].store.videos[1].uuid, startTimestamp: 35 }) |
576 | await addVideo({ videoId: servers[2].videos[2].uuid }) | 503 | await addVideo({ videoId: servers[2].store.videos[2].uuid }) |
577 | { | 504 | { |
578 | const res = await addVideo({ videoId: servers[0].videos[3].uuid, stopTimestamp: 35 }) | 505 | const element = await addVideo({ videoId: servers[0].store.videos[3].uuid, stopTimestamp: 35 }) |
579 | playlistElementServer1Video4 = res.body.videoPlaylistElement.id | 506 | playlistElementServer1Video4 = element.id |
580 | } | 507 | } |
581 | 508 | ||
582 | { | 509 | { |
583 | const res = await addVideo({ videoId: servers[0].videos[4].uuid, startTimestamp: 45, stopTimestamp: 60 }) | 510 | const element = await addVideo({ videoId: servers[0].store.videos[4].uuid, startTimestamp: 45, stopTimestamp: 60 }) |
584 | playlistElementServer1Video5 = res.body.videoPlaylistElement.id | 511 | playlistElementServer1Video5 = element.id |
585 | } | 512 | } |
586 | 513 | ||
587 | { | 514 | { |
588 | const res = await addVideo({ videoId: nsfwVideoServer1, startTimestamp: 5 }) | 515 | const element = await addVideo({ videoId: nsfwVideoServer1, startTimestamp: 5 }) |
589 | playlistElementNSFW = res.body.videoPlaylistElement.id | 516 | playlistElementNSFW = element.id |
590 | 517 | ||
591 | await addVideo({ videoId: nsfwVideoServer1, startTimestamp: 4 }) | 518 | await addVideo({ videoId: nsfwVideoServer1, startTimestamp: 4 }) |
592 | await addVideo({ videoId: nsfwVideoServer1 }) | 519 | await addVideo({ videoId: nsfwVideoServer1 }) |
@@ -599,64 +526,68 @@ describe('Test video playlists', function () { | |||
599 | this.timeout(30000) | 526 | this.timeout(30000) |
600 | 527 | ||
601 | for (const server of servers) { | 528 | for (const server of servers) { |
602 | const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10) | 529 | { |
603 | 530 | const body = await server.playlists.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) | |
604 | expect(res.body.total).to.equal(8) | 531 | |
605 | 532 | expect(body.total).to.equal(8) | |
606 | const videoElements: VideoPlaylistElement[] = res.body.data | 533 | |
607 | expect(videoElements).to.have.lengthOf(8) | 534 | const videoElements = body.data |
608 | 535 | expect(videoElements).to.have.lengthOf(8) | |
609 | expect(videoElements[0].video.name).to.equal('video 0 server 1') | 536 | |
610 | expect(videoElements[0].position).to.equal(1) | 537 | expect(videoElements[0].video.name).to.equal('video 0 server 1') |
611 | expect(videoElements[0].startTimestamp).to.equal(15) | 538 | expect(videoElements[0].position).to.equal(1) |
612 | expect(videoElements[0].stopTimestamp).to.equal(28) | 539 | expect(videoElements[0].startTimestamp).to.equal(15) |
613 | 540 | expect(videoElements[0].stopTimestamp).to.equal(28) | |
614 | expect(videoElements[1].video.name).to.equal('video 1 server 3') | 541 | |
615 | expect(videoElements[1].position).to.equal(2) | 542 | expect(videoElements[1].video.name).to.equal('video 1 server 3') |
616 | expect(videoElements[1].startTimestamp).to.equal(35) | 543 | expect(videoElements[1].position).to.equal(2) |
617 | expect(videoElements[1].stopTimestamp).to.be.null | 544 | expect(videoElements[1].startTimestamp).to.equal(35) |
618 | 545 | expect(videoElements[1].stopTimestamp).to.be.null | |
619 | expect(videoElements[2].video.name).to.equal('video 2 server 3') | 546 | |
620 | expect(videoElements[2].position).to.equal(3) | 547 | expect(videoElements[2].video.name).to.equal('video 2 server 3') |
621 | expect(videoElements[2].startTimestamp).to.be.null | 548 | expect(videoElements[2].position).to.equal(3) |
622 | expect(videoElements[2].stopTimestamp).to.be.null | 549 | expect(videoElements[2].startTimestamp).to.be.null |
623 | 550 | expect(videoElements[2].stopTimestamp).to.be.null | |
624 | expect(videoElements[3].video.name).to.equal('video 3 server 1') | 551 | |
625 | expect(videoElements[3].position).to.equal(4) | 552 | expect(videoElements[3].video.name).to.equal('video 3 server 1') |
626 | expect(videoElements[3].startTimestamp).to.be.null | 553 | expect(videoElements[3].position).to.equal(4) |
627 | expect(videoElements[3].stopTimestamp).to.equal(35) | 554 | expect(videoElements[3].startTimestamp).to.be.null |
628 | 555 | expect(videoElements[3].stopTimestamp).to.equal(35) | |
629 | expect(videoElements[4].video.name).to.equal('video 4 server 1') | 556 | |
630 | expect(videoElements[4].position).to.equal(5) | 557 | expect(videoElements[4].video.name).to.equal('video 4 server 1') |
631 | expect(videoElements[4].startTimestamp).to.equal(45) | 558 | expect(videoElements[4].position).to.equal(5) |
632 | expect(videoElements[4].stopTimestamp).to.equal(60) | 559 | expect(videoElements[4].startTimestamp).to.equal(45) |
633 | 560 | expect(videoElements[4].stopTimestamp).to.equal(60) | |
634 | expect(videoElements[5].video.name).to.equal('NSFW video') | 561 | |
635 | expect(videoElements[5].position).to.equal(6) | 562 | expect(videoElements[5].video.name).to.equal('NSFW video') |
636 | expect(videoElements[5].startTimestamp).to.equal(5) | 563 | expect(videoElements[5].position).to.equal(6) |
637 | expect(videoElements[5].stopTimestamp).to.be.null | 564 | expect(videoElements[5].startTimestamp).to.equal(5) |
638 | 565 | expect(videoElements[5].stopTimestamp).to.be.null | |
639 | expect(videoElements[6].video.name).to.equal('NSFW video') | 566 | |
640 | expect(videoElements[6].position).to.equal(7) | 567 | expect(videoElements[6].video.name).to.equal('NSFW video') |
641 | expect(videoElements[6].startTimestamp).to.equal(4) | 568 | expect(videoElements[6].position).to.equal(7) |
642 | expect(videoElements[6].stopTimestamp).to.be.null | 569 | expect(videoElements[6].startTimestamp).to.equal(4) |
643 | 570 | expect(videoElements[6].stopTimestamp).to.be.null | |
644 | expect(videoElements[7].video.name).to.equal('NSFW video') | 571 | |
645 | expect(videoElements[7].position).to.equal(8) | 572 | expect(videoElements[7].video.name).to.equal('NSFW video') |
646 | expect(videoElements[7].startTimestamp).to.be.null | 573 | expect(videoElements[7].position).to.equal(8) |
647 | expect(videoElements[7].stopTimestamp).to.be.null | 574 | expect(videoElements[7].startTimestamp).to.be.null |
648 | 575 | expect(videoElements[7].stopTimestamp).to.be.null | |
649 | const res3 = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 2) | 576 | } |
650 | expect(res3.body.data).to.have.lengthOf(2) | 577 | |
578 | { | ||
579 | const body = await server.playlists.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 2 }) | ||
580 | expect(body.data).to.have.lengthOf(2) | ||
581 | } | ||
651 | } | 582 | } |
652 | }) | 583 | }) |
653 | }) | 584 | }) |
654 | 585 | ||
655 | describe('Element type', function () { | 586 | describe('Element type', function () { |
656 | let groupUser1: ServerInfo[] | 587 | let groupUser1: PeerTubeServer[] |
657 | let groupWithoutToken1: ServerInfo[] | 588 | let groupWithoutToken1: PeerTubeServer[] |
658 | let group1: ServerInfo[] | 589 | let group1: PeerTubeServer[] |
659 | let group2: ServerInfo[] | 590 | let group2: PeerTubeServer[] |
660 | 591 | ||
661 | let video1: string | 592 | let video1: string |
662 | let video2: string | 593 | let video2: string |
@@ -665,31 +596,30 @@ describe('Test video playlists', function () { | |||
665 | before(async function () { | 596 | before(async function () { |
666 | this.timeout(60000) | 597 | this.timeout(60000) |
667 | 598 | ||
668 | groupUser1 = [ Object.assign({}, servers[0], { accessToken: userAccessTokenServer1 }) ] | 599 | groupUser1 = [ Object.assign({}, servers[0], { accessToken: userTokenServer1 }) ] |
669 | groupWithoutToken1 = [ Object.assign({}, servers[0], { accessToken: undefined }) ] | 600 | groupWithoutToken1 = [ Object.assign({}, servers[0], { accessToken: undefined }) ] |
670 | group1 = [ servers[0] ] | 601 | group1 = [ servers[0] ] |
671 | group2 = [ servers[1], servers[2] ] | 602 | group2 = [ servers[1], servers[2] ] |
672 | 603 | ||
673 | const res = await createVideoPlaylist({ | 604 | const playlist = await commands[0].create({ |
674 | url: servers[0].url, | 605 | token: userTokenServer1, |
675 | token: userAccessTokenServer1, | 606 | attributes: { |
676 | playlistAttrs: { | ||
677 | displayName: 'playlist 56', | 607 | displayName: 'playlist 56', |
678 | privacy: VideoPlaylistPrivacy.PUBLIC, | 608 | privacy: VideoPlaylistPrivacy.PUBLIC, |
679 | videoChannelId: servers[0].videoChannel.id | 609 | videoChannelId: servers[0].store.channel.id |
680 | } | 610 | } |
681 | }) | 611 | }) |
682 | 612 | ||
683 | const playlistServer1Id2 = res.body.videoPlaylist.id | 613 | const playlistServer1Id2 = playlist.id |
684 | playlistServer1UUID2 = res.body.videoPlaylist.uuid | 614 | playlistServer1UUID2 = playlist.uuid |
685 | 615 | ||
686 | const addVideo = (elementAttrs: any) => { | 616 | const addVideo = (attributes: any) => { |
687 | return addVideoInPlaylist({ url: servers[0].url, token: userAccessTokenServer1, playlistId: playlistServer1Id2, elementAttrs }) | 617 | return commands[0].addElement({ token: userTokenServer1, playlistId: playlistServer1Id2, attributes }) |
688 | } | 618 | } |
689 | 619 | ||
690 | video1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 89', token: userAccessTokenServer1 })).uuid | 620 | video1 = (await servers[0].videos.quickUpload({ name: 'video 89', token: userTokenServer1 })).uuid |
691 | video2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 90' })).uuid | 621 | video2 = (await servers[1].videos.quickUpload({ name: 'video 90' })).uuid |
692 | video3 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 91', nsfw: true })).uuid | 622 | video3 = (await servers[0].videos.quickUpload({ name: 'video 91', nsfw: true })).uuid |
693 | 623 | ||
694 | await waitJobs(servers) | 624 | await waitJobs(servers) |
695 | 625 | ||
@@ -707,7 +637,7 @@ describe('Test video playlists', function () { | |||
707 | const position = 1 | 637 | const position = 1 |
708 | 638 | ||
709 | { | 639 | { |
710 | await updateVideo(servers[0].url, servers[0].accessToken, video1, { privacy: VideoPrivacy.PRIVATE }) | 640 | await servers[0].videos.update({ id: video1, attributes: { privacy: VideoPrivacy.PRIVATE } }) |
711 | await waitJobs(servers) | 641 | await waitJobs(servers) |
712 | 642 | ||
713 | await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) | 643 | await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) |
@@ -717,7 +647,7 @@ describe('Test video playlists', function () { | |||
717 | } | 647 | } |
718 | 648 | ||
719 | { | 649 | { |
720 | await updateVideo(servers[0].url, servers[0].accessToken, video1, { privacy: VideoPrivacy.PUBLIC }) | 650 | await servers[0].videos.update({ id: video1, attributes: { privacy: VideoPrivacy.PUBLIC } }) |
721 | await waitJobs(servers) | 651 | await waitJobs(servers) |
722 | 652 | ||
723 | await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) | 653 | await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) |
@@ -735,7 +665,7 @@ describe('Test video playlists', function () { | |||
735 | const position = 1 | 665 | const position = 1 |
736 | 666 | ||
737 | { | 667 | { |
738 | await addVideoToBlacklist(servers[0].url, servers[0].accessToken, video1, 'reason', true) | 668 | await servers[0].blacklist.add({ videoId: video1, reason: 'reason', unfederate: true }) |
739 | await waitJobs(servers) | 669 | await waitJobs(servers) |
740 | 670 | ||
741 | await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) | 671 | await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) |
@@ -745,7 +675,7 @@ describe('Test video playlists', function () { | |||
745 | } | 675 | } |
746 | 676 | ||
747 | { | 677 | { |
748 | await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, video1) | 678 | await servers[0].blacklist.remove({ videoId: video1 }) |
749 | await waitJobs(servers) | 679 | await waitJobs(servers) |
750 | 680 | ||
751 | await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) | 681 | await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) |
@@ -759,56 +689,58 @@ describe('Test video playlists', function () { | |||
759 | it('Should update the element type if the account or server of the video is blocked', async function () { | 689 | it('Should update the element type if the account or server of the video is blocked', async function () { |
760 | this.timeout(90000) | 690 | this.timeout(90000) |
761 | 691 | ||
692 | const command = servers[0].blocklist | ||
693 | |||
762 | const name = 'video 90' | 694 | const name = 'video 90' |
763 | const position = 2 | 695 | const position = 2 |
764 | 696 | ||
765 | { | 697 | { |
766 | await addAccountToAccountBlocklist(servers[0].url, userAccessTokenServer1, 'root@localhost:' + servers[1].port) | 698 | await command.addToMyBlocklist({ token: userTokenServer1, account: 'root@localhost:' + servers[1].port }) |
767 | await waitJobs(servers) | 699 | await waitJobs(servers) |
768 | 700 | ||
769 | await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3) | 701 | await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3) |
770 | await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) | 702 | await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) |
771 | 703 | ||
772 | await removeAccountFromAccountBlocklist(servers[0].url, userAccessTokenServer1, 'root@localhost:' + servers[1].port) | 704 | await command.removeFromMyBlocklist({ token: userTokenServer1, account: 'root@localhost:' + servers[1].port }) |
773 | await waitJobs(servers) | 705 | await waitJobs(servers) |
774 | 706 | ||
775 | await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) | 707 | await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) |
776 | } | 708 | } |
777 | 709 | ||
778 | { | 710 | { |
779 | await addServerToAccountBlocklist(servers[0].url, userAccessTokenServer1, 'localhost:' + servers[1].port) | 711 | await command.addToMyBlocklist({ token: userTokenServer1, server: 'localhost:' + servers[1].port }) |
780 | await waitJobs(servers) | 712 | await waitJobs(servers) |
781 | 713 | ||
782 | await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3) | 714 | await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3) |
783 | await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) | 715 | await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) |
784 | 716 | ||
785 | await removeServerFromAccountBlocklist(servers[0].url, userAccessTokenServer1, 'localhost:' + servers[1].port) | 717 | await command.removeFromMyBlocklist({ token: userTokenServer1, server: 'localhost:' + servers[1].port }) |
786 | await waitJobs(servers) | 718 | await waitJobs(servers) |
787 | 719 | ||
788 | await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) | 720 | await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) |
789 | } | 721 | } |
790 | 722 | ||
791 | { | 723 | { |
792 | await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'root@localhost:' + servers[1].port) | 724 | await command.addToServerBlocklist({ account: 'root@localhost:' + servers[1].port }) |
793 | await waitJobs(servers) | 725 | await waitJobs(servers) |
794 | 726 | ||
795 | await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3) | 727 | await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3) |
796 | await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) | 728 | await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) |
797 | 729 | ||
798 | await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'root@localhost:' + servers[1].port) | 730 | await command.removeFromServerBlocklist({ account: 'root@localhost:' + servers[1].port }) |
799 | await waitJobs(servers) | 731 | await waitJobs(servers) |
800 | 732 | ||
801 | await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) | 733 | await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) |
802 | } | 734 | } |
803 | 735 | ||
804 | { | 736 | { |
805 | await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port) | 737 | await command.addToServerBlocklist({ server: 'localhost:' + servers[1].port }) |
806 | await waitJobs(servers) | 738 | await waitJobs(servers) |
807 | 739 | ||
808 | await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3) | 740 | await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3) |
809 | await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) | 741 | await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) |
810 | 742 | ||
811 | await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port) | 743 | await command.removeFromServerBlocklist({ server: 'localhost:' + servers[1].port }) |
812 | await waitJobs(servers) | 744 | await waitJobs(servers) |
813 | 745 | ||
814 | await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) | 746 | await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) |
@@ -816,10 +748,10 @@ describe('Test video playlists', function () { | |||
816 | }) | 748 | }) |
817 | 749 | ||
818 | it('Should hide the video if it is NSFW', async function () { | 750 | it('Should hide the video if it is NSFW', async function () { |
819 | const res = await getPlaylistVideos(servers[0].url, userAccessTokenServer1, playlistServer1UUID2, 0, 10, { nsfw: false }) | 751 | const body = await commands[0].listVideos({ token: userTokenServer1, playlistId: playlistServer1UUID2, query: { nsfw: 'false' } }) |
820 | expect(res.body.total).to.equal(3) | 752 | expect(body.total).to.equal(3) |
821 | 753 | ||
822 | const elements: VideoPlaylistElement[] = res.body.data | 754 | const elements = body.data |
823 | const element = elements.find(e => e.position === 3) | 755 | const element = elements.find(e => e.position === 3) |
824 | 756 | ||
825 | expect(element).to.exist | 757 | expect(element).to.exist |
@@ -835,11 +767,9 @@ describe('Test video playlists', function () { | |||
835 | this.timeout(30000) | 767 | this.timeout(30000) |
836 | 768 | ||
837 | { | 769 | { |
838 | await reorderVideosPlaylist({ | 770 | await commands[0].reorderElements({ |
839 | url: servers[0].url, | ||
840 | token: servers[0].accessToken, | ||
841 | playlistId: playlistServer1Id, | 771 | playlistId: playlistServer1Id, |
842 | elementAttrs: { | 772 | attributes: { |
843 | startPosition: 2, | 773 | startPosition: 2, |
844 | insertAfterPosition: 3 | 774 | insertAfterPosition: 3 |
845 | } | 775 | } |
@@ -848,8 +778,8 @@ describe('Test video playlists', function () { | |||
848 | await waitJobs(servers) | 778 | await waitJobs(servers) |
849 | 779 | ||
850 | for (const server of servers) { | 780 | for (const server of servers) { |
851 | const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10) | 781 | const body = await server.playlists.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) |
852 | const names = (res.body.data as VideoPlaylistElement[]).map(v => v.video.name) | 782 | const names = body.data.map(v => v.video.name) |
853 | 783 | ||
854 | expect(names).to.deep.equal([ | 784 | expect(names).to.deep.equal([ |
855 | 'video 0 server 1', | 785 | 'video 0 server 1', |
@@ -865,11 +795,9 @@ describe('Test video playlists', function () { | |||
865 | } | 795 | } |
866 | 796 | ||
867 | { | 797 | { |
868 | await reorderVideosPlaylist({ | 798 | await commands[0].reorderElements({ |
869 | url: servers[0].url, | ||
870 | token: servers[0].accessToken, | ||
871 | playlistId: playlistServer1Id, | 799 | playlistId: playlistServer1Id, |
872 | elementAttrs: { | 800 | attributes: { |
873 | startPosition: 1, | 801 | startPosition: 1, |
874 | reorderLength: 3, | 802 | reorderLength: 3, |
875 | insertAfterPosition: 4 | 803 | insertAfterPosition: 4 |
@@ -879,8 +807,8 @@ describe('Test video playlists', function () { | |||
879 | await waitJobs(servers) | 807 | await waitJobs(servers) |
880 | 808 | ||
881 | for (const server of servers) { | 809 | for (const server of servers) { |
882 | const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10) | 810 | const body = await server.playlists.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) |
883 | const names = (res.body.data as VideoPlaylistElement[]).map(v => v.video.name) | 811 | const names = body.data.map(v => v.video.name) |
884 | 812 | ||
885 | expect(names).to.deep.equal([ | 813 | expect(names).to.deep.equal([ |
886 | 'video 3 server 1', | 814 | 'video 3 server 1', |
@@ -896,11 +824,9 @@ describe('Test video playlists', function () { | |||
896 | } | 824 | } |
897 | 825 | ||
898 | { | 826 | { |
899 | await reorderVideosPlaylist({ | 827 | await commands[0].reorderElements({ |
900 | url: servers[0].url, | ||
901 | token: servers[0].accessToken, | ||
902 | playlistId: playlistServer1Id, | 828 | playlistId: playlistServer1Id, |
903 | elementAttrs: { | 829 | attributes: { |
904 | startPosition: 6, | 830 | startPosition: 6, |
905 | insertAfterPosition: 3 | 831 | insertAfterPosition: 3 |
906 | } | 832 | } |
@@ -909,8 +835,7 @@ describe('Test video playlists', function () { | |||
909 | await waitJobs(servers) | 835 | await waitJobs(servers) |
910 | 836 | ||
911 | for (const server of servers) { | 837 | for (const server of servers) { |
912 | const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10) | 838 | const { data: elements } = await server.playlists.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) |
913 | const elements: VideoPlaylistElement[] = res.body.data | ||
914 | const names = elements.map(v => v.video.name) | 839 | const names = elements.map(v => v.video.name) |
915 | 840 | ||
916 | expect(names).to.deep.equal([ | 841 | expect(names).to.deep.equal([ |
@@ -934,22 +859,18 @@ describe('Test video playlists', function () { | |||
934 | it('Should update startTimestamp/endTimestamp of some elements', async function () { | 859 | it('Should update startTimestamp/endTimestamp of some elements', async function () { |
935 | this.timeout(30000) | 860 | this.timeout(30000) |
936 | 861 | ||
937 | await updateVideoPlaylistElement({ | 862 | await commands[0].updateElement({ |
938 | url: servers[0].url, | ||
939 | token: servers[0].accessToken, | ||
940 | playlistId: playlistServer1Id, | 863 | playlistId: playlistServer1Id, |
941 | playlistElementId: playlistElementServer1Video4, | 864 | elementId: playlistElementServer1Video4, |
942 | elementAttrs: { | 865 | attributes: { |
943 | startTimestamp: 1 | 866 | startTimestamp: 1 |
944 | } | 867 | } |
945 | }) | 868 | }) |
946 | 869 | ||
947 | await updateVideoPlaylistElement({ | 870 | await commands[0].updateElement({ |
948 | url: servers[0].url, | ||
949 | token: servers[0].accessToken, | ||
950 | playlistId: playlistServer1Id, | 871 | playlistId: playlistServer1Id, |
951 | playlistElementId: playlistElementServer1Video5, | 872 | elementId: playlistElementServer1Video5, |
952 | elementAttrs: { | 873 | attributes: { |
953 | stopTimestamp: null | 874 | stopTimestamp: null |
954 | } | 875 | } |
955 | }) | 876 | }) |
@@ -957,8 +878,7 @@ describe('Test video playlists', function () { | |||
957 | await waitJobs(servers) | 878 | await waitJobs(servers) |
958 | 879 | ||
959 | for (const server of servers) { | 880 | for (const server of servers) { |
960 | const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10) | 881 | const { data: elements } = await server.playlists.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) |
961 | const elements: VideoPlaylistElement[] = res.body.data | ||
962 | 882 | ||
963 | expect(elements[0].video.name).to.equal('video 3 server 1') | 883 | expect(elements[0].video.name).to.equal('video 3 server 1') |
964 | expect(elements[0].position).to.equal(1) | 884 | expect(elements[0].position).to.equal(1) |
@@ -974,17 +894,16 @@ describe('Test video playlists', function () { | |||
974 | 894 | ||
975 | it('Should check videos existence in my playlist', async function () { | 895 | it('Should check videos existence in my playlist', async function () { |
976 | const videoIds = [ | 896 | const videoIds = [ |
977 | servers[0].videos[0].id, | 897 | servers[0].store.videos[0].id, |
978 | 42000, | 898 | 42000, |
979 | servers[0].videos[3].id, | 899 | servers[0].store.videos[3].id, |
980 | 43000, | 900 | 43000, |
981 | servers[0].videos[4].id | 901 | servers[0].store.videos[4].id |
982 | ] | 902 | ] |
983 | const res = await doVideosExistInMyPlaylist(servers[0].url, servers[0].accessToken, videoIds) | 903 | const obj = await commands[0].videosExist({ videoIds }) |
984 | const obj = res.body as VideoExistInPlaylist | ||
985 | 904 | ||
986 | { | 905 | { |
987 | const elem = obj[servers[0].videos[0].id] | 906 | const elem = obj[servers[0].store.videos[0].id] |
988 | expect(elem).to.have.lengthOf(1) | 907 | expect(elem).to.have.lengthOf(1) |
989 | expect(elem[0].playlistElementId).to.exist | 908 | expect(elem[0].playlistElementId).to.exist |
990 | expect(elem[0].playlistId).to.equal(playlistServer1Id) | 909 | expect(elem[0].playlistId).to.equal(playlistServer1Id) |
@@ -993,7 +912,7 @@ describe('Test video playlists', function () { | |||
993 | } | 912 | } |
994 | 913 | ||
995 | { | 914 | { |
996 | const elem = obj[servers[0].videos[3].id] | 915 | const elem = obj[servers[0].store.videos[3].id] |
997 | expect(elem).to.have.lengthOf(1) | 916 | expect(elem).to.have.lengthOf(1) |
998 | expect(elem[0].playlistElementId).to.equal(playlistElementServer1Video4) | 917 | expect(elem[0].playlistElementId).to.equal(playlistElementServer1Video4) |
999 | expect(elem[0].playlistId).to.equal(playlistServer1Id) | 918 | expect(elem[0].playlistId).to.equal(playlistServer1Id) |
@@ -1002,7 +921,7 @@ describe('Test video playlists', function () { | |||
1002 | } | 921 | } |
1003 | 922 | ||
1004 | { | 923 | { |
1005 | const elem = obj[servers[0].videos[4].id] | 924 | const elem = obj[servers[0].store.videos[4].id] |
1006 | expect(elem).to.have.lengthOf(1) | 925 | expect(elem).to.have.lengthOf(1) |
1007 | expect(elem[0].playlistId).to.equal(playlistServer1Id) | 926 | expect(elem[0].playlistId).to.equal(playlistServer1Id) |
1008 | expect(elem[0].startTimestamp).to.equal(45) | 927 | expect(elem[0].startTimestamp).to.equal(45) |
@@ -1015,42 +934,29 @@ describe('Test video playlists', function () { | |||
1015 | 934 | ||
1016 | it('Should automatically update updatedAt field of playlists', async function () { | 935 | it('Should automatically update updatedAt field of playlists', async function () { |
1017 | const server = servers[1] | 936 | const server = servers[1] |
1018 | const videoId = servers[1].videos[5].id | 937 | const videoId = servers[1].store.videos[5].id |
1019 | 938 | ||
1020 | async function getPlaylistNames () { | 939 | async function getPlaylistNames () { |
1021 | const res = await getAccountPlaylistsListWithToken(server.url, server.accessToken, 'root', 0, 5, undefined, '-updatedAt') | 940 | const { data } = await server.playlists.listByAccount({ token: server.accessToken, handle: 'root', sort: '-updatedAt' }) |
1022 | 941 | ||
1023 | return (res.body.data as VideoPlaylist[]).map(p => p.displayName) | 942 | return data.map(p => p.displayName) |
1024 | } | 943 | } |
1025 | 944 | ||
1026 | const elementAttrs = { videoId } | 945 | const attributes = { videoId } |
1027 | const res1 = await addVideoInPlaylist({ url: server.url, token: server.accessToken, playlistId: playlistServer2Id1, elementAttrs }) | 946 | const element1 = await server.playlists.addElement({ playlistId: playlistServer2Id1, attributes }) |
1028 | const res2 = await addVideoInPlaylist({ url: server.url, token: server.accessToken, playlistId: playlistServer2Id2, elementAttrs }) | 947 | const element2 = await server.playlists.addElement({ playlistId: playlistServer2Id2, attributes }) |
1029 | |||
1030 | const element1 = res1.body.videoPlaylistElement.id | ||
1031 | const element2 = res2.body.videoPlaylistElement.id | ||
1032 | 948 | ||
1033 | const names1 = await getPlaylistNames() | 949 | const names1 = await getPlaylistNames() |
1034 | expect(names1[0]).to.equal('playlist 3 updated') | 950 | expect(names1[0]).to.equal('playlist 3 updated') |
1035 | expect(names1[1]).to.equal('playlist 2') | 951 | expect(names1[1]).to.equal('playlist 2') |
1036 | 952 | ||
1037 | await removeVideoFromPlaylist({ | 953 | await server.playlists.removeElement({ playlistId: playlistServer2Id1, elementId: element1.id }) |
1038 | url: server.url, | ||
1039 | token: server.accessToken, | ||
1040 | playlistId: playlistServer2Id1, | ||
1041 | playlistElementId: element1 | ||
1042 | }) | ||
1043 | 954 | ||
1044 | const names2 = await getPlaylistNames() | 955 | const names2 = await getPlaylistNames() |
1045 | expect(names2[0]).to.equal('playlist 2') | 956 | expect(names2[0]).to.equal('playlist 2') |
1046 | expect(names2[1]).to.equal('playlist 3 updated') | 957 | expect(names2[1]).to.equal('playlist 3 updated') |
1047 | 958 | ||
1048 | await removeVideoFromPlaylist({ | 959 | await server.playlists.removeElement({ playlistId: playlistServer2Id2, elementId: element2.id }) |
1049 | url: server.url, | ||
1050 | token: server.accessToken, | ||
1051 | playlistId: playlistServer2Id2, | ||
1052 | playlistElementId: element2 | ||
1053 | }) | ||
1054 | 960 | ||
1055 | const names3 = await getPlaylistNames() | 961 | const names3 = await getPlaylistNames() |
1056 | expect(names3[0]).to.equal('playlist 3 updated') | 962 | expect(names3[0]).to.equal('playlist 3 updated') |
@@ -1060,28 +966,16 @@ describe('Test video playlists', function () { | |||
1060 | it('Should delete some elements', async function () { | 966 | it('Should delete some elements', async function () { |
1061 | this.timeout(30000) | 967 | this.timeout(30000) |
1062 | 968 | ||
1063 | await removeVideoFromPlaylist({ | 969 | await commands[0].removeElement({ playlistId: playlistServer1Id, elementId: playlistElementServer1Video4 }) |
1064 | url: servers[0].url, | 970 | await commands[0].removeElement({ playlistId: playlistServer1Id, elementId: playlistElementNSFW }) |
1065 | token: servers[0].accessToken, | ||
1066 | playlistId: playlistServer1Id, | ||
1067 | playlistElementId: playlistElementServer1Video4 | ||
1068 | }) | ||
1069 | |||
1070 | await removeVideoFromPlaylist({ | ||
1071 | url: servers[0].url, | ||
1072 | token: servers[0].accessToken, | ||
1073 | playlistId: playlistServer1Id, | ||
1074 | playlistElementId: playlistElementNSFW | ||
1075 | }) | ||
1076 | 971 | ||
1077 | await waitJobs(servers) | 972 | await waitJobs(servers) |
1078 | 973 | ||
1079 | for (const server of servers) { | 974 | for (const server of servers) { |
1080 | const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10) | 975 | const body = await server.playlists.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) |
976 | expect(body.total).to.equal(6) | ||
1081 | 977 | ||
1082 | expect(res.body.total).to.equal(6) | 978 | const elements = body.data |
1083 | |||
1084 | const elements: VideoPlaylistElement[] = res.body.data | ||
1085 | expect(elements).to.have.lengthOf(6) | 979 | expect(elements).to.have.lengthOf(6) |
1086 | 980 | ||
1087 | expect(elements[0].video.name).to.equal('video 0 server 1') | 981 | expect(elements[0].video.name).to.equal('video 0 server 1') |
@@ -1107,34 +1001,31 @@ describe('Test video playlists', function () { | |||
1107 | it('Should be able to create a public playlist, and set it to private', async function () { | 1001 | it('Should be able to create a public playlist, and set it to private', async function () { |
1108 | this.timeout(30000) | 1002 | this.timeout(30000) |
1109 | 1003 | ||
1110 | const res = await createVideoPlaylist({ | 1004 | const videoPlaylistIds = await commands[0].create({ |
1111 | url: servers[0].url, | 1005 | attributes: { |
1112 | token: servers[0].accessToken, | ||
1113 | playlistAttrs: { | ||
1114 | displayName: 'my super public playlist', | 1006 | displayName: 'my super public playlist', |
1115 | privacy: VideoPlaylistPrivacy.PUBLIC, | 1007 | privacy: VideoPlaylistPrivacy.PUBLIC, |
1116 | videoChannelId: servers[0].videoChannel.id | 1008 | videoChannelId: servers[0].store.channel.id |
1117 | } | 1009 | } |
1118 | }) | 1010 | }) |
1119 | const videoPlaylistIds = res.body.videoPlaylist | ||
1120 | 1011 | ||
1121 | await waitJobs(servers) | 1012 | await waitJobs(servers) |
1122 | 1013 | ||
1123 | for (const server of servers) { | 1014 | for (const server of servers) { |
1124 | await getVideoPlaylist(server.url, videoPlaylistIds.uuid, HttpStatusCode.OK_200) | 1015 | await server.playlists.get({ playlistId: videoPlaylistIds.uuid, expectedStatus: HttpStatusCode.OK_200 }) |
1125 | } | 1016 | } |
1126 | 1017 | ||
1127 | const playlistAttrs = { privacy: VideoPlaylistPrivacy.PRIVATE } | 1018 | const attributes = { privacy: VideoPlaylistPrivacy.PRIVATE } |
1128 | await updateVideoPlaylist({ url: servers[0].url, token: servers[0].accessToken, playlistId: videoPlaylistIds.id, playlistAttrs }) | 1019 | await commands[0].update({ playlistId: videoPlaylistIds.id, attributes }) |
1129 | 1020 | ||
1130 | await waitJobs(servers) | 1021 | await waitJobs(servers) |
1131 | 1022 | ||
1132 | for (const server of [ servers[1], servers[2] ]) { | 1023 | for (const server of [ servers[1], servers[2] ]) { |
1133 | await getVideoPlaylist(server.url, videoPlaylistIds.uuid, HttpStatusCode.NOT_FOUND_404) | 1024 | await server.playlists.get({ playlistId: videoPlaylistIds.uuid, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) |
1134 | } | 1025 | } |
1135 | await getVideoPlaylist(servers[0].url, videoPlaylistIds.uuid, HttpStatusCode.UNAUTHORIZED_401) | ||
1136 | 1026 | ||
1137 | await getVideoPlaylistWithToken(servers[0].url, servers[0].accessToken, videoPlaylistIds.uuid, HttpStatusCode.OK_200) | 1027 | await commands[0].get({ playlistId: videoPlaylistIds.uuid, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
1028 | await commands[0].get({ token: servers[0].accessToken, playlistId: videoPlaylistIds.uuid, expectedStatus: HttpStatusCode.OK_200 }) | ||
1138 | }) | 1029 | }) |
1139 | }) | 1030 | }) |
1140 | 1031 | ||
@@ -1143,12 +1034,12 @@ describe('Test video playlists', function () { | |||
1143 | it('Should delete the playlist on server 1 and delete on server 2 and 3', async function () { | 1034 | it('Should delete the playlist on server 1 and delete on server 2 and 3', async function () { |
1144 | this.timeout(30000) | 1035 | this.timeout(30000) |
1145 | 1036 | ||
1146 | await deleteVideoPlaylist(servers[0].url, servers[0].accessToken, playlistServer1Id) | 1037 | await commands[0].delete({ playlistId: playlistServer1Id }) |
1147 | 1038 | ||
1148 | await waitJobs(servers) | 1039 | await waitJobs(servers) |
1149 | 1040 | ||
1150 | for (const server of servers) { | 1041 | for (const server of servers) { |
1151 | await getVideoPlaylist(server.url, playlistServer1UUID, HttpStatusCode.NOT_FOUND_404) | 1042 | await server.playlists.get({ playlistId: playlistServer1UUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) |
1152 | } | 1043 | } |
1153 | }) | 1044 | }) |
1154 | 1045 | ||
@@ -1163,75 +1054,61 @@ describe('Test video playlists', function () { | |||
1163 | it('Should unfollow servers 1 and 2 and hide their playlists', async function () { | 1054 | it('Should unfollow servers 1 and 2 and hide their playlists', async function () { |
1164 | this.timeout(30000) | 1055 | this.timeout(30000) |
1165 | 1056 | ||
1166 | const finder = data => data.find(p => p.displayName === 'my super playlist') | 1057 | const finder = (data: VideoPlaylist[]) => data.find(p => p.displayName === 'my super playlist') |
1167 | 1058 | ||
1168 | { | 1059 | { |
1169 | const res = await getVideoPlaylistsList(servers[2].url, 0, 5) | 1060 | const body = await servers[2].playlists.list({ start: 0, count: 5 }) |
1170 | expect(res.body.total).to.equal(3) | 1061 | expect(body.total).to.equal(3) |
1171 | expect(finder(res.body.data)).to.not.be.undefined | 1062 | |
1063 | expect(finder(body.data)).to.not.be.undefined | ||
1172 | } | 1064 | } |
1173 | 1065 | ||
1174 | await unfollow(servers[2].url, servers[2].accessToken, servers[0]) | 1066 | await servers[2].follows.unfollow({ target: servers[0] }) |
1175 | 1067 | ||
1176 | { | 1068 | { |
1177 | const res = await getVideoPlaylistsList(servers[2].url, 0, 5) | 1069 | const body = await servers[2].playlists.list({ start: 0, count: 5 }) |
1178 | expect(res.body.total).to.equal(1) | 1070 | expect(body.total).to.equal(1) |
1179 | 1071 | ||
1180 | expect(finder(res.body.data)).to.be.undefined | 1072 | expect(finder(body.data)).to.be.undefined |
1181 | } | 1073 | } |
1182 | }) | 1074 | }) |
1183 | 1075 | ||
1184 | it('Should delete a channel and put the associated playlist in private mode', async function () { | 1076 | it('Should delete a channel and put the associated playlist in private mode', async function () { |
1185 | this.timeout(30000) | 1077 | this.timeout(30000) |
1186 | 1078 | ||
1187 | const res = await addVideoChannel(servers[0].url, servers[0].accessToken, { name: 'super_channel', displayName: 'super channel' }) | 1079 | const channel = await servers[0].channels.create({ attributes: { name: 'super_channel', displayName: 'super channel' } }) |
1188 | const videoChannelId = res.body.videoChannel.id | ||
1189 | 1080 | ||
1190 | const res2 = await createVideoPlaylist({ | 1081 | const playlistCreated = await commands[0].create({ |
1191 | url: servers[0].url, | 1082 | attributes: { |
1192 | token: servers[0].accessToken, | ||
1193 | playlistAttrs: { | ||
1194 | displayName: 'channel playlist', | 1083 | displayName: 'channel playlist', |
1195 | privacy: VideoPlaylistPrivacy.PUBLIC, | 1084 | privacy: VideoPlaylistPrivacy.PUBLIC, |
1196 | videoChannelId | 1085 | videoChannelId: channel.id |
1197 | } | 1086 | } |
1198 | }) | 1087 | }) |
1199 | const videoPlaylistUUID = res2.body.videoPlaylist.uuid | ||
1200 | 1088 | ||
1201 | await waitJobs(servers) | 1089 | await waitJobs(servers) |
1202 | 1090 | ||
1203 | await deleteVideoChannel(servers[0].url, servers[0].accessToken, 'super_channel') | 1091 | await servers[0].channels.delete({ channelName: 'super_channel' }) |
1204 | 1092 | ||
1205 | await waitJobs(servers) | 1093 | await waitJobs(servers) |
1206 | 1094 | ||
1207 | const res3 = await getVideoPlaylistWithToken(servers[0].url, servers[0].accessToken, videoPlaylistUUID) | 1095 | const body = await commands[0].get({ token: servers[0].accessToken, playlistId: playlistCreated.uuid }) |
1208 | expect(res3.body.displayName).to.equal('channel playlist') | 1096 | expect(body.displayName).to.equal('channel playlist') |
1209 | expect(res3.body.privacy.id).to.equal(VideoPlaylistPrivacy.PRIVATE) | 1097 | expect(body.privacy.id).to.equal(VideoPlaylistPrivacy.PRIVATE) |
1210 | 1098 | ||
1211 | await getVideoPlaylist(servers[1].url, videoPlaylistUUID, HttpStatusCode.NOT_FOUND_404) | 1099 | await servers[1].playlists.get({ playlistId: playlistCreated.uuid, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) |
1212 | }) | 1100 | }) |
1213 | 1101 | ||
1214 | it('Should delete an account and delete its playlists', async function () { | 1102 | it('Should delete an account and delete its playlists', async function () { |
1215 | this.timeout(30000) | 1103 | this.timeout(30000) |
1216 | 1104 | ||
1217 | const user = { username: 'user_1', password: 'password' } | 1105 | const { userId, token } = await servers[0].users.generate('user_1') |
1218 | const res = await createUser({ | ||
1219 | url: servers[0].url, | ||
1220 | accessToken: servers[0].accessToken, | ||
1221 | username: user.username, | ||
1222 | password: user.password | ||
1223 | }) | ||
1224 | |||
1225 | const userId = res.body.user.id | ||
1226 | const userAccessToken = await userLogin(servers[0], user) | ||
1227 | 1106 | ||
1228 | const resChannel = await getMyUserInformation(servers[0].url, userAccessToken) | 1107 | const { videoChannels } = await servers[0].users.getMyInfo({ token }) |
1229 | const userChannel = (resChannel.body as User).videoChannels[0] | 1108 | const userChannel = videoChannels[0] |
1230 | 1109 | ||
1231 | await createVideoPlaylist({ | 1110 | await commands[0].create({ |
1232 | url: servers[0].url, | 1111 | attributes: { |
1233 | token: userAccessToken, | ||
1234 | playlistAttrs: { | ||
1235 | displayName: 'playlist to be deleted', | 1112 | displayName: 'playlist to be deleted', |
1236 | privacy: VideoPlaylistPrivacy.PUBLIC, | 1113 | privacy: VideoPlaylistPrivacy.PUBLIC, |
1237 | videoChannelId: userChannel.id | 1114 | videoChannelId: userChannel.id |
@@ -1240,22 +1117,24 @@ describe('Test video playlists', function () { | |||
1240 | 1117 | ||
1241 | await waitJobs(servers) | 1118 | await waitJobs(servers) |
1242 | 1119 | ||
1243 | const finder = data => data.find(p => p.displayName === 'playlist to be deleted') | 1120 | const finder = (data: VideoPlaylist[]) => data.find(p => p.displayName === 'playlist to be deleted') |
1244 | 1121 | ||
1245 | { | 1122 | { |
1246 | for (const server of [ servers[0], servers[1] ]) { | 1123 | for (const server of [ servers[0], servers[1] ]) { |
1247 | const res = await getVideoPlaylistsList(server.url, 0, 15) | 1124 | const body = await server.playlists.list({ start: 0, count: 15 }) |
1248 | expect(finder(res.body.data)).to.not.be.undefined | 1125 | |
1126 | expect(finder(body.data)).to.not.be.undefined | ||
1249 | } | 1127 | } |
1250 | } | 1128 | } |
1251 | 1129 | ||
1252 | await removeUser(servers[0].url, userId, servers[0].accessToken) | 1130 | await servers[0].users.remove({ userId }) |
1253 | await waitJobs(servers) | 1131 | await waitJobs(servers) |
1254 | 1132 | ||
1255 | { | 1133 | { |
1256 | for (const server of [ servers[0], servers[1] ]) { | 1134 | for (const server of [ servers[0], servers[1] ]) { |
1257 | const res = await getVideoPlaylistsList(server.url, 0, 15) | 1135 | const body = await server.playlists.list({ start: 0, count: 15 }) |
1258 | expect(finder(res.body.data)).to.be.undefined | 1136 | |
1137 | expect(finder(body.data)).to.be.undefined | ||
1259 | } | 1138 | } |
1260 | } | 1139 | } |
1261 | }) | 1140 | }) |