video-playlists.ts 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867
  1. /* tslint:disable:no-unused-expression */
  2. import * as chai from 'chai'
  3. import 'mocha'
  4. import {
  5. addVideoChannel,
  6. addVideoInPlaylist,
  7. checkPlaylistFilesWereRemoved,
  8. cleanupTests,
  9. createUser,
  10. createVideoPlaylist,
  11. deleteVideoChannel,
  12. deleteVideoPlaylist,
  13. doubleFollow,
  14. doVideosExistInMyPlaylist,
  15. flushAndRunMultipleServers,
  16. getAccountPlaylistsList,
  17. getAccountPlaylistsListWithToken,
  18. getMyUserInformation,
  19. getPlaylistVideos,
  20. getVideoChannelPlaylistsList,
  21. getVideoPlaylist,
  22. getVideoPlaylistPrivacies,
  23. getVideoPlaylistsList,
  24. getVideoPlaylistWithToken,
  25. removeUser,
  26. removeVideoFromPlaylist,
  27. reorderVideosPlaylist,
  28. ServerInfo,
  29. setAccessTokensToServers,
  30. setDefaultVideoChannel,
  31. testImage,
  32. unfollow,
  33. updateVideoPlaylist,
  34. updateVideoPlaylistElement,
  35. uploadVideo,
  36. uploadVideoAndGetId,
  37. userLogin,
  38. waitJobs
  39. } from '../../../../shared/extra-utils'
  40. import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model'
  41. import { VideoPlaylist } from '../../../../shared/models/videos/playlist/video-playlist.model'
  42. import { Video } from '../../../../shared/models/videos'
  43. import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/video-playlist-type.model'
  44. import { VideoExistInPlaylist } from '../../../../shared/models/videos/playlist/video-exist-in-playlist.model'
  45. import { User } from '../../../../shared/models/users'
  46. const expect = chai.expect
  47. describe('Test video playlists', function () {
  48. let servers: ServerInfo[] = []
  49. let playlistServer2Id1: number
  50. let playlistServer2Id2: number
  51. let playlistServer2UUID2: number
  52. let playlistServer1Id: number
  53. let playlistServer1UUID: string
  54. let nsfwVideoServer1: number
  55. before(async function () {
  56. this.timeout(120000)
  57. servers = await flushAndRunMultipleServers(3, { transcoding: { enabled: false } })
  58. // Get the access tokens
  59. await setAccessTokensToServers(servers)
  60. await setDefaultVideoChannel(servers)
  61. // Server 1 and server 2 follow each other
  62. await doubleFollow(servers[0], servers[1])
  63. // Server 1 and server 3 follow each other
  64. await doubleFollow(servers[0], servers[2])
  65. {
  66. const serverPromises: Promise<any>[][] = []
  67. for (const server of servers) {
  68. const videoPromises: Promise<any>[] = []
  69. for (let i = 0; i < 7; i++) {
  70. videoPromises.push(
  71. uploadVideo(server.url, server.accessToken, { name: `video ${i} server ${server.serverNumber}`, nsfw: false })
  72. .then(res => res.body.video)
  73. )
  74. }
  75. serverPromises.push(videoPromises)
  76. }
  77. servers[0].videos = await Promise.all(serverPromises[0])
  78. servers[1].videos = await Promise.all(serverPromises[1])
  79. servers[2].videos = await Promise.all(serverPromises[2])
  80. }
  81. nsfwVideoServer1 = (await uploadVideoAndGetId({ server: servers[ 0 ], videoName: 'NSFW video', nsfw: true })).id
  82. await waitJobs(servers)
  83. })
  84. it('Should list video playlist privacies', async function () {
  85. const res = await getVideoPlaylistPrivacies(servers[0].url)
  86. const privacies = res.body
  87. expect(Object.keys(privacies)).to.have.length.at.least(3)
  88. expect(privacies[3]).to.equal('Private')
  89. })
  90. it('Should list watch later playlist', async function () {
  91. const url = servers[ 0 ].url
  92. const accessToken = servers[ 0 ].accessToken
  93. {
  94. const res = await getAccountPlaylistsListWithToken(url, accessToken, 'root', 0, 5, VideoPlaylistType.WATCH_LATER)
  95. expect(res.body.total).to.equal(1)
  96. expect(res.body.data).to.have.lengthOf(1)
  97. const playlist: VideoPlaylist = res.body.data[ 0 ]
  98. expect(playlist.displayName).to.equal('Watch later')
  99. expect(playlist.type.id).to.equal(VideoPlaylistType.WATCH_LATER)
  100. expect(playlist.type.label).to.equal('Watch later')
  101. }
  102. {
  103. const res = await getAccountPlaylistsListWithToken(url, accessToken, 'root', 0, 5, VideoPlaylistType.REGULAR)
  104. expect(res.body.total).to.equal(0)
  105. expect(res.body.data).to.have.lengthOf(0)
  106. }
  107. {
  108. const res = await getAccountPlaylistsList(url, 'root', 0, 5)
  109. expect(res.body.total).to.equal(0)
  110. expect(res.body.data).to.have.lengthOf(0)
  111. }
  112. })
  113. it('Should create a playlist on server 1 and have the playlist on server 2 and 3', async function () {
  114. this.timeout(30000)
  115. await createVideoPlaylist({
  116. url: servers[0].url,
  117. token: servers[0].accessToken,
  118. playlistAttrs: {
  119. displayName: 'my super playlist',
  120. privacy: VideoPlaylistPrivacy.PUBLIC,
  121. description: 'my super description',
  122. thumbnailfile: 'thumbnail.jpg',
  123. videoChannelId: servers[0].videoChannel.id
  124. }
  125. })
  126. await waitJobs(servers)
  127. for (const server of servers) {
  128. const res = await getVideoPlaylistsList(server.url, 0, 5)
  129. expect(res.body.total).to.equal(1)
  130. expect(res.body.data).to.have.lengthOf(1)
  131. const playlistFromList = res.body.data[0] as VideoPlaylist
  132. const res2 = await getVideoPlaylist(server.url, playlistFromList.uuid)
  133. const playlistFromGet = res2.body
  134. for (const playlist of [ playlistFromGet, playlistFromList ]) {
  135. expect(playlist.id).to.be.a('number')
  136. expect(playlist.uuid).to.be.a('string')
  137. expect(playlist.isLocal).to.equal(server.serverNumber === 1)
  138. expect(playlist.displayName).to.equal('my super playlist')
  139. expect(playlist.description).to.equal('my super description')
  140. expect(playlist.privacy.id).to.equal(VideoPlaylistPrivacy.PUBLIC)
  141. expect(playlist.privacy.label).to.equal('Public')
  142. expect(playlist.type.id).to.equal(VideoPlaylistType.REGULAR)
  143. expect(playlist.type.label).to.equal('Regular')
  144. expect(playlist.videosLength).to.equal(0)
  145. expect(playlist.ownerAccount.name).to.equal('root')
  146. expect(playlist.ownerAccount.displayName).to.equal('root')
  147. expect(playlist.videoChannel.name).to.equal('root_channel')
  148. expect(playlist.videoChannel.displayName).to.equal('Main root channel')
  149. }
  150. }
  151. })
  152. it('Should create a playlist on server 2 and have the playlist on server 1 but not on server 3', async function () {
  153. this.timeout(30000)
  154. {
  155. const res = await createVideoPlaylist({
  156. url: servers[1].url,
  157. token: servers[1].accessToken,
  158. playlistAttrs: {
  159. displayName: 'playlist 2',
  160. privacy: VideoPlaylistPrivacy.PUBLIC,
  161. videoChannelId: servers[1].videoChannel.id
  162. }
  163. })
  164. playlistServer2Id1 = res.body.videoPlaylist.id
  165. }
  166. {
  167. const res = await createVideoPlaylist({
  168. url: servers[ 1 ].url,
  169. token: servers[ 1 ].accessToken,
  170. playlistAttrs: {
  171. displayName: 'playlist 3',
  172. privacy: VideoPlaylistPrivacy.PUBLIC,
  173. thumbnailfile: 'thumbnail.jpg',
  174. videoChannelId: servers[1].videoChannel.id
  175. }
  176. })
  177. playlistServer2Id2 = res.body.videoPlaylist.id
  178. playlistServer2UUID2 = res.body.videoPlaylist.uuid
  179. }
  180. for (let id of [ playlistServer2Id1, playlistServer2Id2 ]) {
  181. await addVideoInPlaylist({
  182. url: servers[ 1 ].url,
  183. token: servers[ 1 ].accessToken,
  184. playlistId: id,
  185. elementAttrs: { videoId: servers[ 1 ].videos[ 0 ].id, startTimestamp: 1, stopTimestamp: 2 }
  186. })
  187. await addVideoInPlaylist({
  188. url: servers[ 1 ].url,
  189. token: servers[ 1 ].accessToken,
  190. playlistId: id,
  191. elementAttrs: { videoId: servers[ 1 ].videos[ 1 ].id }
  192. })
  193. }
  194. await waitJobs(servers)
  195. for (const server of [ servers[0], servers[1] ]) {
  196. const res = await getVideoPlaylistsList(server.url, 0, 5)
  197. const playlist2 = res.body.data.find(p => p.displayName === 'playlist 2')
  198. expect(playlist2).to.not.be.undefined
  199. await testImage(server.url, 'thumbnail-playlist', playlist2.thumbnailPath)
  200. const playlist3 = res.body.data.find(p => p.displayName === 'playlist 3')
  201. expect(playlist3).to.not.be.undefined
  202. await testImage(server.url, 'thumbnail', playlist3.thumbnailPath)
  203. }
  204. const res = await getVideoPlaylistsList(servers[2].url, 0, 5)
  205. expect(res.body.data.find(p => p.displayName === 'playlist 2')).to.be.undefined
  206. expect(res.body.data.find(p => p.displayName === 'playlist 3')).to.be.undefined
  207. })
  208. it('Should have the playlist on server 3 after a new follow', async function () {
  209. this.timeout(30000)
  210. // Server 2 and server 3 follow each other
  211. await doubleFollow(servers[1], servers[2])
  212. const res = await getVideoPlaylistsList(servers[2].url, 0, 5)
  213. const playlist2 = res.body.data.find(p => p.displayName === 'playlist 2')
  214. expect(playlist2).to.not.be.undefined
  215. await testImage(servers[2].url, 'thumbnail-playlist', playlist2.thumbnailPath)
  216. expect(res.body.data.find(p => p.displayName === 'playlist 3')).to.not.be.undefined
  217. })
  218. it('Should correctly list the playlists', async function () {
  219. this.timeout(30000)
  220. {
  221. const res = await getVideoPlaylistsList(servers[ 2 ].url, 1, 2, 'createdAt')
  222. expect(res.body.total).to.equal(3)
  223. const data: VideoPlaylist[] = res.body.data
  224. expect(data).to.have.lengthOf(2)
  225. expect(data[ 0 ].displayName).to.equal('playlist 2')
  226. expect(data[ 1 ].displayName).to.equal('playlist 3')
  227. }
  228. {
  229. const res = await getVideoPlaylistsList(servers[ 2 ].url, 1, 2, '-createdAt')
  230. expect(res.body.total).to.equal(3)
  231. const data: VideoPlaylist[] = res.body.data
  232. expect(data).to.have.lengthOf(2)
  233. expect(data[ 0 ].displayName).to.equal('playlist 2')
  234. expect(data[ 1 ].displayName).to.equal('my super playlist')
  235. }
  236. })
  237. it('Should list video channel playlists', async function () {
  238. this.timeout(30000)
  239. {
  240. const res = await getVideoChannelPlaylistsList(servers[ 0 ].url, 'root_channel', 0, 2, '-createdAt')
  241. expect(res.body.total).to.equal(1)
  242. const data: VideoPlaylist[] = res.body.data
  243. expect(data).to.have.lengthOf(1)
  244. expect(data[ 0 ].displayName).to.equal('my super playlist')
  245. }
  246. })
  247. it('Should list account playlists', async function () {
  248. this.timeout(30000)
  249. {
  250. const res = await getAccountPlaylistsList(servers[ 1 ].url, 'root', 1, 2, '-createdAt')
  251. expect(res.body.total).to.equal(2)
  252. const data: VideoPlaylist[] = res.body.data
  253. expect(data).to.have.lengthOf(1)
  254. expect(data[ 0 ].displayName).to.equal('playlist 2')
  255. }
  256. {
  257. const res = await getAccountPlaylistsList(servers[ 1 ].url, 'root', 1, 2, 'createdAt')
  258. expect(res.body.total).to.equal(2)
  259. const data: VideoPlaylist[] = res.body.data
  260. expect(data).to.have.lengthOf(1)
  261. expect(data[ 0 ].displayName).to.equal('playlist 3')
  262. }
  263. })
  264. it('Should not list unlisted or private playlists', async function () {
  265. this.timeout(30000)
  266. await createVideoPlaylist({
  267. url: servers[ 1 ].url,
  268. token: servers[ 1 ].accessToken,
  269. playlistAttrs: {
  270. displayName: 'playlist unlisted',
  271. privacy: VideoPlaylistPrivacy.UNLISTED
  272. }
  273. })
  274. await createVideoPlaylist({
  275. url: servers[ 1 ].url,
  276. token: servers[ 1 ].accessToken,
  277. playlistAttrs: {
  278. displayName: 'playlist private',
  279. privacy: VideoPlaylistPrivacy.PRIVATE
  280. }
  281. })
  282. await waitJobs(servers)
  283. for (const server of servers) {
  284. const results = [
  285. await getAccountPlaylistsList(server.url, 'root@localhost:9002', 0, 5, '-createdAt'),
  286. await getVideoPlaylistsList(server.url, 0, 2, '-createdAt')
  287. ]
  288. expect(results[0].body.total).to.equal(2)
  289. expect(results[1].body.total).to.equal(3)
  290. for (const res of results) {
  291. const data: VideoPlaylist[] = res.body.data
  292. expect(data).to.have.lengthOf(2)
  293. expect(data[ 0 ].displayName).to.equal('playlist 3')
  294. expect(data[ 1 ].displayName).to.equal('playlist 2')
  295. }
  296. }
  297. })
  298. it('Should update a playlist', async function () {
  299. this.timeout(30000)
  300. await updateVideoPlaylist({
  301. url: servers[1].url,
  302. token: servers[1].accessToken,
  303. playlistAttrs: {
  304. displayName: 'playlist 3 updated',
  305. description: 'description updated',
  306. privacy: VideoPlaylistPrivacy.UNLISTED,
  307. thumbnailfile: 'thumbnail.jpg',
  308. videoChannelId: servers[1].videoChannel.id
  309. },
  310. playlistId: playlistServer2Id2
  311. })
  312. await waitJobs(servers)
  313. for (const server of servers) {
  314. const res = await getVideoPlaylist(server.url, playlistServer2UUID2)
  315. const playlist: VideoPlaylist = res.body
  316. expect(playlist.displayName).to.equal('playlist 3 updated')
  317. expect(playlist.description).to.equal('description updated')
  318. expect(playlist.privacy.id).to.equal(VideoPlaylistPrivacy.UNLISTED)
  319. expect(playlist.privacy.label).to.equal('Unlisted')
  320. expect(playlist.type.id).to.equal(VideoPlaylistType.REGULAR)
  321. expect(playlist.type.label).to.equal('Regular')
  322. expect(playlist.videosLength).to.equal(2)
  323. expect(playlist.ownerAccount.name).to.equal('root')
  324. expect(playlist.ownerAccount.displayName).to.equal('root')
  325. expect(playlist.videoChannel.name).to.equal('root_channel')
  326. expect(playlist.videoChannel.displayName).to.equal('Main root channel')
  327. }
  328. })
  329. it('Should create a playlist containing different startTimestamp/endTimestamp videos', async function () {
  330. this.timeout(30000)
  331. const addVideo = (elementAttrs: any) => {
  332. return addVideoInPlaylist({ url: servers[0].url, token: servers[0].accessToken, playlistId: playlistServer1Id, elementAttrs })
  333. }
  334. const res = await createVideoPlaylist({
  335. url: servers[ 0 ].url,
  336. token: servers[ 0 ].accessToken,
  337. playlistAttrs: {
  338. displayName: 'playlist 4',
  339. privacy: VideoPlaylistPrivacy.PUBLIC,
  340. videoChannelId: servers[0].videoChannel.id
  341. }
  342. })
  343. playlistServer1Id = res.body.videoPlaylist.id
  344. playlistServer1UUID = res.body.videoPlaylist.uuid
  345. await addVideo({ videoId: servers[0].videos[0].uuid, startTimestamp: 15, stopTimestamp: 28 })
  346. await addVideo({ videoId: servers[2].videos[1].uuid, startTimestamp: 35 })
  347. await addVideo({ videoId: servers[2].videos[2].uuid })
  348. await addVideo({ videoId: servers[0].videos[3].uuid, stopTimestamp: 35 })
  349. await addVideo({ videoId: servers[0].videos[4].uuid, startTimestamp: 45, stopTimestamp: 60 })
  350. await addVideo({ videoId: nsfwVideoServer1, startTimestamp: 5 })
  351. await waitJobs(servers)
  352. })
  353. it('Should correctly list playlist videos', async function () {
  354. this.timeout(30000)
  355. for (const server of servers) {
  356. const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10)
  357. expect(res.body.total).to.equal(6)
  358. const videos: Video[] = res.body.data
  359. expect(videos).to.have.lengthOf(6)
  360. expect(videos[0].name).to.equal('video 0 server 1')
  361. expect(videos[0].playlistElement.position).to.equal(1)
  362. expect(videos[0].playlistElement.startTimestamp).to.equal(15)
  363. expect(videos[0].playlistElement.stopTimestamp).to.equal(28)
  364. expect(videos[1].name).to.equal('video 1 server 3')
  365. expect(videos[1].playlistElement.position).to.equal(2)
  366. expect(videos[1].playlistElement.startTimestamp).to.equal(35)
  367. expect(videos[1].playlistElement.stopTimestamp).to.be.null
  368. expect(videos[2].name).to.equal('video 2 server 3')
  369. expect(videos[2].playlistElement.position).to.equal(3)
  370. expect(videos[2].playlistElement.startTimestamp).to.be.null
  371. expect(videos[2].playlistElement.stopTimestamp).to.be.null
  372. expect(videos[3].name).to.equal('video 3 server 1')
  373. expect(videos[3].playlistElement.position).to.equal(4)
  374. expect(videos[3].playlistElement.startTimestamp).to.be.null
  375. expect(videos[3].playlistElement.stopTimestamp).to.equal(35)
  376. expect(videos[4].name).to.equal('video 4 server 1')
  377. expect(videos[4].playlistElement.position).to.equal(5)
  378. expect(videos[4].playlistElement.startTimestamp).to.equal(45)
  379. expect(videos[4].playlistElement.stopTimestamp).to.equal(60)
  380. expect(videos[5].name).to.equal('NSFW video')
  381. expect(videos[5].playlistElement.position).to.equal(6)
  382. expect(videos[5].playlistElement.startTimestamp).to.equal(5)
  383. expect(videos[5].playlistElement.stopTimestamp).to.be.null
  384. const res2 = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10, { nsfw: false })
  385. expect(res2.body.total).to.equal(5)
  386. expect(res2.body.data.find(v => v.name === 'NSFW video')).to.be.undefined
  387. const res3 = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 2)
  388. expect(res3.body.data).to.have.lengthOf(2)
  389. }
  390. })
  391. it('Should reorder the playlist', async function () {
  392. this.timeout(30000)
  393. {
  394. await reorderVideosPlaylist({
  395. url: servers[ 0 ].url,
  396. token: servers[ 0 ].accessToken,
  397. playlistId: playlistServer1Id,
  398. elementAttrs: {
  399. startPosition: 2,
  400. insertAfterPosition: 3
  401. }
  402. })
  403. await waitJobs(servers)
  404. for (const server of servers) {
  405. const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10)
  406. const names = res.body.data.map(v => v.name)
  407. expect(names).to.deep.equal([
  408. 'video 0 server 1',
  409. 'video 2 server 3',
  410. 'video 1 server 3',
  411. 'video 3 server 1',
  412. 'video 4 server 1',
  413. 'NSFW video'
  414. ])
  415. }
  416. }
  417. {
  418. await reorderVideosPlaylist({
  419. url: servers[0].url,
  420. token: servers[0].accessToken,
  421. playlistId: playlistServer1Id,
  422. elementAttrs: {
  423. startPosition: 1,
  424. reorderLength: 3,
  425. insertAfterPosition: 4
  426. }
  427. })
  428. await waitJobs(servers)
  429. for (const server of servers) {
  430. const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10)
  431. const names = res.body.data.map(v => v.name)
  432. expect(names).to.deep.equal([
  433. 'video 3 server 1',
  434. 'video 0 server 1',
  435. 'video 2 server 3',
  436. 'video 1 server 3',
  437. 'video 4 server 1',
  438. 'NSFW video'
  439. ])
  440. }
  441. }
  442. {
  443. await reorderVideosPlaylist({
  444. url: servers[0].url,
  445. token: servers[0].accessToken,
  446. playlistId: playlistServer1Id,
  447. elementAttrs: {
  448. startPosition: 6,
  449. insertAfterPosition: 3
  450. }
  451. })
  452. await waitJobs(servers)
  453. for (const server of servers) {
  454. const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10)
  455. const videos: Video[] = res.body.data
  456. const names = videos.map(v => v.name)
  457. expect(names).to.deep.equal([
  458. 'video 3 server 1',
  459. 'video 0 server 1',
  460. 'video 2 server 3',
  461. 'NSFW video',
  462. 'video 1 server 3',
  463. 'video 4 server 1'
  464. ])
  465. for (let i = 1; i <= videos.length; i++) {
  466. expect(videos[i - 1].playlistElement.position).to.equal(i)
  467. }
  468. }
  469. }
  470. })
  471. it('Should update startTimestamp/endTimestamp of some elements', async function () {
  472. this.timeout(30000)
  473. await updateVideoPlaylistElement({
  474. url: servers[0].url,
  475. token: servers[0].accessToken,
  476. playlistId: playlistServer1Id,
  477. videoId: servers[0].videos[3].uuid,
  478. elementAttrs: {
  479. startTimestamp: 1
  480. }
  481. })
  482. await updateVideoPlaylistElement({
  483. url: servers[0].url,
  484. token: servers[0].accessToken,
  485. playlistId: playlistServer1Id,
  486. videoId: servers[0].videos[4].uuid,
  487. elementAttrs: {
  488. stopTimestamp: null
  489. }
  490. })
  491. await waitJobs(servers)
  492. for (const server of servers) {
  493. const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10)
  494. const videos: Video[] = res.body.data
  495. expect(videos[0].name).to.equal('video 3 server 1')
  496. expect(videos[0].playlistElement.position).to.equal(1)
  497. expect(videos[0].playlistElement.startTimestamp).to.equal(1)
  498. expect(videos[0].playlistElement.stopTimestamp).to.equal(35)
  499. expect(videos[5].name).to.equal('video 4 server 1')
  500. expect(videos[5].playlistElement.position).to.equal(6)
  501. expect(videos[5].playlistElement.startTimestamp).to.equal(45)
  502. expect(videos[5].playlistElement.stopTimestamp).to.be.null
  503. }
  504. })
  505. it('Should check videos existence in my playlist', async function () {
  506. const videoIds = [
  507. servers[0].videos[0].id,
  508. 42000,
  509. servers[0].videos[3].id,
  510. 43000,
  511. servers[0].videos[4].id
  512. ]
  513. const res = await doVideosExistInMyPlaylist(servers[ 0 ].url, servers[ 0 ].accessToken, videoIds)
  514. const obj = res.body as VideoExistInPlaylist
  515. {
  516. const elem = obj[servers[0].videos[0].id]
  517. expect(elem).to.have.lengthOf(1)
  518. expect(elem[ 0 ].playlistId).to.equal(playlistServer1Id)
  519. expect(elem[ 0 ].startTimestamp).to.equal(15)
  520. expect(elem[ 0 ].stopTimestamp).to.equal(28)
  521. }
  522. {
  523. const elem = obj[servers[0].videos[3].id]
  524. expect(elem).to.have.lengthOf(1)
  525. expect(elem[ 0 ].playlistId).to.equal(playlistServer1Id)
  526. expect(elem[ 0 ].startTimestamp).to.equal(1)
  527. expect(elem[ 0 ].stopTimestamp).to.equal(35)
  528. }
  529. {
  530. const elem = obj[servers[0].videos[4].id]
  531. expect(elem).to.have.lengthOf(1)
  532. expect(elem[ 0 ].playlistId).to.equal(playlistServer1Id)
  533. expect(elem[ 0 ].startTimestamp).to.equal(45)
  534. expect(elem[ 0 ].stopTimestamp).to.equal(null)
  535. }
  536. expect(obj[42000]).to.have.lengthOf(0)
  537. expect(obj[43000]).to.have.lengthOf(0)
  538. })
  539. it('Should automatically update updatedAt field of playlists', async function () {
  540. const server = servers[1]
  541. const videoId = servers[1].videos[5].id
  542. async function getPlaylistNames () {
  543. const res = await getAccountPlaylistsListWithToken(server.url, server.accessToken, 'root', 0, 5, undefined, '-updatedAt')
  544. return (res.body.data as VideoPlaylist[]).map(p => p.displayName)
  545. }
  546. const elementAttrs = { videoId }
  547. await addVideoInPlaylist({ url: server.url, token: server.accessToken, playlistId: playlistServer2Id1, elementAttrs })
  548. await addVideoInPlaylist({ url: server.url, token: server.accessToken, playlistId: playlistServer2Id2, elementAttrs })
  549. const names1 = await getPlaylistNames()
  550. expect(names1[0]).to.equal('playlist 3 updated')
  551. expect(names1[1]).to.equal('playlist 2')
  552. await removeVideoFromPlaylist({ url: server.url, token: server.accessToken, playlistId: playlistServer2Id1, videoId })
  553. const names2 = await getPlaylistNames()
  554. expect(names2[0]).to.equal('playlist 2')
  555. expect(names2[1]).to.equal('playlist 3 updated')
  556. await removeVideoFromPlaylist({ url: server.url, token: server.accessToken, playlistId: playlistServer2Id2, videoId })
  557. const names3 = await getPlaylistNames()
  558. expect(names3[0]).to.equal('playlist 3 updated')
  559. expect(names3[1]).to.equal('playlist 2')
  560. })
  561. it('Should delete some elements', async function () {
  562. this.timeout(30000)
  563. await removeVideoFromPlaylist({
  564. url: servers[0].url,
  565. token: servers[0].accessToken,
  566. playlistId: playlistServer1Id,
  567. videoId: servers[0].videos[3].uuid
  568. })
  569. await removeVideoFromPlaylist({
  570. url: servers[0].url,
  571. token: servers[0].accessToken,
  572. playlistId: playlistServer1Id,
  573. videoId: nsfwVideoServer1
  574. })
  575. await waitJobs(servers)
  576. for (const server of servers) {
  577. const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10)
  578. expect(res.body.total).to.equal(4)
  579. const videos: Video[] = res.body.data
  580. expect(videos).to.have.lengthOf(4)
  581. expect(videos[ 0 ].name).to.equal('video 0 server 1')
  582. expect(videos[ 0 ].playlistElement.position).to.equal(1)
  583. expect(videos[ 1 ].name).to.equal('video 2 server 3')
  584. expect(videos[ 1 ].playlistElement.position).to.equal(2)
  585. expect(videos[ 2 ].name).to.equal('video 1 server 3')
  586. expect(videos[ 2 ].playlistElement.position).to.equal(3)
  587. expect(videos[ 3 ].name).to.equal('video 4 server 1')
  588. expect(videos[ 3 ].playlistElement.position).to.equal(4)
  589. }
  590. })
  591. it('Should delete the playlist on server 1 and delete on server 2 and 3', async function () {
  592. this.timeout(30000)
  593. await deleteVideoPlaylist(servers[0].url, servers[0].accessToken, playlistServer1Id)
  594. await waitJobs(servers)
  595. for (const server of servers) {
  596. await getVideoPlaylist(server.url, playlistServer1UUID, 404)
  597. }
  598. })
  599. it('Should have deleted the thumbnail on server 1, 2 and 3', async function () {
  600. this.timeout(30000)
  601. for (const server of servers) {
  602. await checkPlaylistFilesWereRemoved(playlistServer1UUID, server.serverNumber)
  603. }
  604. })
  605. it('Should unfollow servers 1 and 2 and hide their playlists', async function () {
  606. this.timeout(30000)
  607. const finder = data => data.find(p => p.displayName === 'my super playlist')
  608. {
  609. const res = await getVideoPlaylistsList(servers[ 2 ].url, 0, 5)
  610. expect(res.body.total).to.equal(2)
  611. expect(finder(res.body.data)).to.not.be.undefined
  612. }
  613. await unfollow(servers[2].url, servers[2].accessToken, servers[0])
  614. {
  615. const res = await getVideoPlaylistsList(servers[ 2 ].url, 0, 5)
  616. expect(res.body.total).to.equal(1)
  617. expect(finder(res.body.data)).to.be.undefined
  618. }
  619. })
  620. it('Should delete a channel and put the associated playlist in private mode', async function () {
  621. this.timeout(30000)
  622. const res = await addVideoChannel(servers[0].url, servers[0].accessToken, { name: 'super_channel', displayName: 'super channel' })
  623. const videoChannelId = res.body.videoChannel.id
  624. const res2 = await createVideoPlaylist({
  625. url: servers[0].url,
  626. token: servers[0].accessToken,
  627. playlistAttrs: {
  628. displayName: 'channel playlist',
  629. privacy: VideoPlaylistPrivacy.PUBLIC,
  630. videoChannelId
  631. }
  632. })
  633. const videoPlaylistUUID = res2.body.videoPlaylist.uuid
  634. await waitJobs(servers)
  635. await deleteVideoChannel(servers[0].url, servers[0].accessToken, 'super_channel')
  636. await waitJobs(servers)
  637. const res3 = await getVideoPlaylistWithToken(servers[0].url, servers[0].accessToken, videoPlaylistUUID)
  638. expect(res3.body.displayName).to.equal('channel playlist')
  639. expect(res3.body.privacy.id).to.equal(VideoPlaylistPrivacy.PRIVATE)
  640. await getVideoPlaylist(servers[1].url, videoPlaylistUUID, 404)
  641. })
  642. it('Should delete an account and delete its playlists', async function () {
  643. this.timeout(30000)
  644. const user = { username: 'user_1', password: 'password' }
  645. const res = await createUser({
  646. url: servers[ 0 ].url,
  647. accessToken: servers[ 0 ].accessToken,
  648. username: user.username,
  649. password: user.password
  650. })
  651. const userId = res.body.user.id
  652. const userAccessToken = await userLogin(servers[0], user)
  653. const resChannel = await getMyUserInformation(servers[0].url, userAccessToken)
  654. const userChannel = (resChannel.body as User).videoChannels[0]
  655. await createVideoPlaylist({
  656. url: servers[0].url,
  657. token: userAccessToken,
  658. playlistAttrs: {
  659. displayName: 'playlist to be deleted',
  660. privacy: VideoPlaylistPrivacy.PUBLIC,
  661. videoChannelId: userChannel.id
  662. }
  663. })
  664. await waitJobs(servers)
  665. const finder = data => data.find(p => p.displayName === 'playlist to be deleted')
  666. {
  667. for (const server of [ servers[0], servers[1] ]) {
  668. const res = await getVideoPlaylistsList(server.url, 0, 15)
  669. expect(finder(res.body.data)).to.not.be.undefined
  670. }
  671. }
  672. await removeUser(servers[0].url, userId, servers[0].accessToken)
  673. await waitJobs(servers)
  674. {
  675. for (const server of [ servers[0], servers[1] ]) {
  676. const res = await getVideoPlaylistsList(server.url, 0, 15)
  677. expect(finder(res.body.data)).to.be.undefined
  678. }
  679. }
  680. })
  681. after(async function () {
  682. await cleanupTests(servers)
  683. })
  684. })